Solved

MIDP HTTP Connection Problems

Posted on 2006-11-01
4
854 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 86
JDeveloper 12c for 32 bit 4 85
object oriented programming comparison 5 72
Tomcat: Unable to run tomcat service. 2 20
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

810 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