Solved

MIDP HTTP Connection Problems

Posted on 2006-11-01
4
868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

734 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