I'm having some problems with the nokia 7210 phone, and have come up with a partial workaround in the form of

connection.setRequestProperty( "Connection", "close" );

and I was wondering if anyone else has experienced this:


On nokia 7210 v4.18, 07-12-02, NHL-4

When the following code snippet is run and there is a signal problem the method connection.openInputStream(); will block for two minutes (1 minute or less would be more appropriate) before throwing an exception and allowing the thread (not the main thread we run this in a background thread) to continue.


private static String get(String url) throws IOException {
HttpConnection connection = null;
InputStream is = null;
String result = null;
try {
connection = (HttpConnection)(Connector.open(url, Connector.READ, true));
connection.setRequestProperty( "Connection", "close" );
is = connection.openInputStream();

int contentlength = (int)connection.getLength();
byte buffer[] = new byte[(int)Math.max(256, contentlength)];
int len = 0;
byte ch;
while ((contentlength < 0 || len < contentlength) && (ch = (byte)is.read()) != -1) {
buffer[len] = ch;
len++;
}
result = (0 < len)? new String(buffer, 0, len) : null;

} catch (IllegalArgumentException e) {
// The URL is malformed. Throw an IOException to the caller
throw new IOException("Malformed URL: " + e);
} finally {
if (is != null) is.close();
if (connection != null) connection.close();
return result;
}
}


This is fine except that sometimes the phone will never recover from this error and further calls to connection.openInputStream(); will always result in an exception being thrown after approx 2 minutes, even if network coverage is restored. The phone must be reset to fix this.

Furthermore, if the line

connection.setRequestProperty( "Connection", "close" );

is omitted, the call will never return and never throw an exception.

Ryan