commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Heaberlin <heabd...@gmail.com>
Subject Re: Commons HttpClient: HttpClient#setConnectionTimeout
Date Tue, 01 Mar 2005 22:55:51 GMT
Not to bring this thread back up, but I am having a hard time getting
this to work (tried both 2.0.2 and 3.0-rc1)

<code>
//input = my non-null string
HttpClient myClient = new HttpClient();
PostMethod post = new PostMethod("http://localhost:12345");
post.setRequestBody(input);
post.setRequestContentLength(input.length());
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000L);
       httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000L);
httpClient.executeMethod(post);
String response = httpMethod.getResponseBodyAsString();
</code>

Run the netcat command, `nc -l -p 12345`  (that's a lower case -L) locally.
Now - run the above snippet.  You'll see in your netcat console
everything httpclient sends... but don't touch anything.  Wait 5000
milliseconds.   Wait 10,000 milliseconds.  Wait indefinitely...

On my machine (JRE 1.4.2_03) this never ever returns.  If I Control-C
(punt) the netcat command, my java app *immediately* receives:
java.net.ConnectException: Connection refused: connect

I am trying to troubleshoot a situation in an application which has
its own "timeout" configuration which is passed directly to
httpclient, but we are seeing in our logs evidence that this timeout
is apparently having no effect and certain http requests we make are
at the mercy of the responding web server.

Any thoughts?  Of course the above code sample only works with 3.0+.  
I was previously (2.0.2) using the equivalent methods (now deprecated)
directly on the HttpClient instance:
<code>
httpClient.setConnectionTimeout(5000L);
httpClient.setTimeout(5000L);
</code>

Any thoughts?  Your help is greatly appreciated,

-Scott


Scott Heaberlin

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


Mime
View raw message