Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 888
  • Last Modified:

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!
0
Systima
Asked:
Systima
  • 2
  • 2
1 Solution
 
objectsCommented:
is the url the same the 2nd time?
0
 
SystimaAuthor Commented:
No - it's a different url to connect to a different servlet.
0
 
objectsCommented:
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
 
SystimaAuthor Commented:
Thanks - there was a problem with the 2nd url.  I needed to trim it.  All sorted - cheers!!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now