hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Why connection timeouts doesn't works?
Date Wed, 15 Aug 2007 15:14:57 GMT
On Wed, 2007-08-15 at 17:56 +0300, Vitaly Baranovsky wrote:
> Good day!
> 
> Connection timeouts of httpClient in my program doesn't works. I set
> timeout to 10 000 milliseconds, but my program waits for about 65
> seconds before answering.

...

> Here is the code of my class:
> 
> public class HttpGetter {
> 
> private static final int DEFAULT_SOCKET_TIMEOUT = 10000;
> private HttpClient httpClient;
> private GetMethod method;
> 
> public HttpGetter() {
> super();
> MultiThreadedHttpConnectionManager cm = new
> MultiThreadedHttpConnectionManager();
> cm.getParams().setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
> 

Hi Vitaly,

On top of what Pete Keyes just said, in your code you are setting a
socket timeout, not a connect timeout. No wonder you are not getting the
expected result.

Oleg


> httpClient = new HttpClient(cm);
> }
> 
> private String getFromURLAsString(String url) throws HttpException,
> IOException {
>   URI uri = new URI(url, false);
>   method = new GetMethod(uri.getEscapedURI());
>   method.getParams().setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
>   int result = httpClient.executeMethod(method);
>   return method.getResponseBodyAsString();;
> }
> }
> 
> 
> 
> Here is the code of my TestCase:
> 
> public class HttpGetterTest extends TestCase {
> 	public void testGetFromUrlAsString() throws HttpException, IOException{
> 		HttpGetter httpGetter = new HttpGetter();
> 		System.out.println(httpGetter.getFromURLAsString("http://google.com"));
> 	}
> }
> 
> 
> Why timeouts doesn't works?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


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


Mime
View raw message