Link to home
Start Free TrialLog in
Avatar of Systima
Systima

asked on

MIDP HTTP Connection Problems

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!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

is the url the same the 2nd time?
Avatar of Systima
Systima

ASKER

No - it's a different url to connect to a different servlet.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Systima

ASKER

Thanks - there was a problem with the 2nd url.  I needed to trim it.  All sorted - cheers!!!