You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Gustavo Hexsel <gh...@sagebrushcorp.com> on 2004/12/13 22:26:42 UTC

How to set timeout parameters for a method?

  Greetings,

  does anyone know how to set the timeout parameters (if possible, both
socket and connection) for a particular method?  I tried to make an accessor
to the HttpConnection, but as I suspected, it is not created until you try
to execute the method, and by then is too late, as both connection and first
read already happened.
  I tried to do something like this:

	method.getParams().setIntParameter("http.socket.timeout",
remainingTime); // in my logs, remaining time is about 300s
	method.getParams().setIntParameter("http.connection.timeout",
remainingTime);

  Even though "connection timeout" is not supposed to be a valid parameter
for the method.  The log indicated that the parameters were set, but the
values remained the same as the defaults set before, and I get a
"SocketTimeout: Read timed out" after about 10s (my default param setting).
  Similarly, even if the first "read()" doesn't time out, I've set the
connection timeouts to the remaining time (over 280s by then), but still
times out in the default values (10s).  This is the code I'm using:

	HttpConnectionParams connParams =
method.getResponseConnection().getParams(); // I just provided an accessor
here
	connParams.setConnectionTimeout(remainingTime);
	connParams.setSoTimeout(remainingTime);


  Any ideas?


  Thanks a lot,

    Gustavo


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


Re: How to set timeout parameters for a method?

Posted by Jilles van Gurp <ji...@gmail.com>.
Don't set the timeouts on the method but on the HttpClient instance. You 
can use the setConnectionTimeout and setTimeout methods.

Jilles van Gurp

Gustavo Hexsel wrote:

>  Greetings,
>
>  does anyone know how to set the timeout parameters (if possible, both
>socket and connection) for a particular method?  I tried to make an accessor
>to the HttpConnection, but as I suspected, it is not created until you try
>to execute the method, and by then is too late, as both connection and first
>read already happened.
>  I tried to do something like this:
>
>	method.getParams().setIntParameter("http.socket.timeout",
>remainingTime); // in my logs, remaining time is about 300s
>	method.getParams().setIntParameter("http.connection.timeout",
>remainingTime);
>
>  Even though "connection timeout" is not supposed to be a valid parameter
>for the method.  The log indicated that the parameters were set, but the
>values remained the same as the defaults set before, and I get a
>"SocketTimeout: Read timed out" after about 10s (my default param setting).
>  Similarly, even if the first "read()" doesn't time out, I've set the
>connection timeouts to the remaining time (over 280s by then), but still
>times out in the default values (10s).  This is the code I'm using:
>
>	HttpConnectionParams connParams =
>method.getResponseConnection().getParams(); // I just provided an accessor
>here
>	connParams.setConnectionTimeout(remainingTime);
>	connParams.setSoTimeout(remainingTime);
>
>
>  Any ideas?
>
>
>  Thanks a lot,
>
>    Gustavo
>
>
>---------------------------------------------------------------------
>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