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("Aut horSearch" );
authorSearchUrl = authorSearchUrl + "?Author=" + workAuthor + "&ItemPage=" + 1;
hc = (HttpConnection)Connector. open(autho rSearchUrl );
hc.setRequestMethod(HttpCo nnection.G ET);
hc.setRequestProperty("Con nection", "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!
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("Aut
authorSearchUrl = authorSearchUrl + "?Author=" + workAuthor + "&ItemPage=" + 1;
hc = (HttpConnection)Connector.
hc.setRequestMethod(HttpCo
hc.setRequestProperty("Con
in = hc.openInputStream();
String result = null;
int contentLength = (int)hc.getLength();
...
}
catch(NullPointerException
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!
is the url the same the 2nd time?
ASKER
No - it's a different url to connect to a different servlet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks - there was a problem with the 2nd url. I needed to trim it. All sorted - cheers!!!