Solved

MIDP HTTP Connection Problems

Posted on 2006-11-01
4
833 Views
Last Modified: 2008-01-09
Hi,

I'm trying to build a MIDP application which will connect to Servlets running on an Apache Server.  I have built the architecture successfully such that I can connect to a servlet, receive a response and display it in the Midlet.  However, when I try to connect to a second servlet I get a java.io.IOException: response empty.

I have tested the servlet separately and it works fine.  I am also ensuring that the previous HTTP Connection and Input Stream are closed.  My code is as follows:

public void displayBooks() throws IOException {
    HttpConnection hc = null;
    InputStream in = null;
    try {
        ...
        String authorSearchUrl = midlet.getAppProperty("AuthorSearch");
        authorSearchUrl = authorSearchUrl + "?Author=" + workAuthor + "&ItemPage=" + 1;
                   
        hc = (HttpConnection)Connector.open(authorSearchUrl);
        hc.setRequestMethod(HttpConnection.GET);
        hc.setRequestProperty("Connection", "close");
        in = hc.openInputStream();
                  
        String result = null;
        int contentLength = (int)hc.getLength();
        ...
    }
    catch(NullPointerException npe){
        append(npe.toString());
    }
    catch(Exception e) {
        append(e.toString());
    }      
    finally {
        if (in != null) {
            in.close();
        }
        if (hc != null) {
            hc.close();
        }
    }

Any ideas would be most appreciated!
0
Comment
Question by:Systima
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17853081
is the url the same the 2nd time?
0
 

Author Comment

by:Systima
ID: 17853189
No - it's a different url to connect to a different servlet.
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 17853254
does the same url work if u try it the 2nd time?
may be a problem with the url

if there are space in workAuthor you'll need to encode them
0
 

Author Comment

by:Systima
ID: 17873681
Thanks - there was a problem with the 2nd url.  I needed to trim it.  All sorted - cheers!!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now