views:

523

answers:

1

Hi, Im using Httconnection for connecting to webserver , somtimes request fails causing

EOFException when calling httpconnection.getResponseCode().

im setting the following headers while making the connection HttpConnection httpconnection = (HttpConnection) Connector.open(url .concat(";interface=wifi")); httpconnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0"); httpconnection.setRequestProperty("Content-Language", "en-US");

any clue regarding this? Im closing all the connections after processing the request properly.Is this exception is due to exceeding max connections .

A: 

It's an internal server error, which return status code 500 in response.

This may be caused by incorrect request, but as well server code or overload may be the reason.
If you have access to server, check event logs.

See also
500 EOF when chunk header expected
Why might LWP::UserAgent be failing with '500 EOF'?
500 EOF instead of reponse status line in perl script
Apache 1.3 error - Unexpected EOF reading HTTP status - connectionreset
Error 500!

UPDATE On the other hand, if it's not response message, but a real exception, then it may be simply a bug, just like in old java
And workaround may be putting getResponseCode() inside of try/catch and call second time on exception:

 int responseCode = -1;
 try {
  responseCode = con.getResponseCode();
 } catch (IOException ex1) {
  //check if it's eof, if yes retrieve code again
  if (-1 != ex1.getMessage().indexOf("EOF")) {
   try {
    responseCode = con.getResponseCode();
   } catch (IOException ex2) {
    System.out.println(ex2.getMessage());
    // handle exception
   }
  } else {
   System.out.println(ex1.getMessage());
   // handle exception
  }
 }

Talking by connections number limit, read
What Is - Maximum number of simultaneous connections
How To - Close connections

Max Gontar