You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Otis Gospodnetic <ot...@yahoo.com> on 2004/05/06 19:49:30 UTC

Requests hanging, not timing out

Hello,

I am using HttpClient from CVS HEAD from exactly 1 month ago (May 6,
2004).  Although I set the time-out to 5 seconds, I noticed that it
does not always work, and because of that my application often hangs
indefinitely.

Perhaps I'm not using the API correctly.
Here are the relevant portions of my code:
(HttpResponse is my class - a simple 'struct', nothing else)


HttpClientParams clientParams = new HttpClientParams();
clientParams.setParameter(HttpClientParams.USER_AGENT, "xxx");

_client = new HttpClient(clientParams);
_client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

GetMethod method = new GetMethod(urlString);
method.setFollowRedirects(false);

String responseBody = null;
try {
    _client.executeMethod(method);
    responseBody = method.getResponseBodyAsString();
} catch (HttpException he) {
    System.err.println("Http error connecting to '" + url + "'");
    method.releaseConnection();
    method.recycle();
    return new HttpResponse(-1, -1, null, null);
} catch (IOException ioe) {
    System.err.println("Unable to connect to '" + url + "'");
    method.releaseConnection();
    method.recycle();
    return new HttpResponse(-1, -1, null, null);
}

int statusCode = method.getStatusCode();
long sizeBytes = method.getResponseContentLength();
String charSet = method.getResponseCharSet();
String lang    = null;

// clean up the connection resources
method.releaseConnection();
method.recycle();

return new HttpResponse(statusCode, sizeBytes, null, charSet);



Am I forgetting to call something that will ensure that no request ever
hangs forever?

Thank you,
Otis


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org