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 Questioner Guy <qu...@gmail.com> on 2005/09/15 11:37:36 UTC

Connection level timeout settings

I am trying to set the connection timeout at the individual connection 
level. The following code snippet sets the timeout at the HttpClient level
  HttpClient client = new HttpClient( new 
MultiThreadedHttpConnectionManager() );
client.getHttpConnectionManager().getParams().setParameter("
http.connection.timeout", new Integer( 30 * 1000));
 I want to be able to reset the connection timeout to certain web-sites 
after getting a timeout exception from the call to HttpClient's 
executeMethod() call. I coudn't figure out a way to get access to the 
connection allocated to the call. 
 I am new to HttpClient and I apologize if this a trivial question, but I 
would appreciate the answer.
 Thanks.

Re: Connection level timeout settings

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, Sep 16, 2005 at 12:12:46AM +0530, Questioner Guy wrote:
> Once again thanks for such quick responses. 
>  Thanks Oleg for pointing out to how the socket.timeout of the 
> HostConfiguration overrides the value set at the Client level. In fact the 
> value set at the Method level overrides the other two.
>  This is exactly what I wanted for the connection timeout. Any idea why the 
> same feature is not available for connection.timeout?
> 
> I am re-evaluating my design to see if I can avoid the need to reset the 
> connection timeout. I may be able to interrupt the connection and achieve 
> the same results. 
>  I would still like to know the reason for treating
> connection.timeoutsdifferently.

No good reason. This is a limitation of the existing architecture. One
of many reasons why HttpClient 4.0 will have to be a complete rewrite

Oleg


>  Thanks.
>    On 9/15/05, Roland Weber <RO...@de.ibm.com> wrote: 
> > 
> > Hello Guy,
> > 
> > when you get the timeout exception, you should release the current
> > connection. When you retry the request, a new connection will be
> > used. There is no point in setting anything at the old connection,
> > which could be used subsequently by a completely different method.
> > 
> > You should implement your own connection manager. Then you can
> > use some context sensitivity, for example a ThreadLocal variable,
> > to set the timeout by the time the connection gets allocated.
> > 
> > hope that helps,
> > Roland
> > 
> > 
> > 
> > 
> > Questioner Guy <qu...@gmail.com>
> > 15.09.2005 16:42
> > Please respond to
> > "HttpClient User Discussion"
> > 
> > 
> > To
> > HttpClient User Discussion <ht...@jakarta.apache.org>
> > cc
> > 
> > Subject
> > Re: Connection level timeout settings
> > 
> > 
> > 
> > 
> > 
> > 
> > Thanks for the reply Roland, Oleg!!
> > I'll try all three approaches Host Configuration/ Connection Manager
> > and/or
> > custom protocol factory approaches and let you know if I am able to fix
> > the
> > problem.
> > The problem is that when I get the first timeout exception, I need to be
> > able to identify the current request being handled reliably to the
> > Connection Manager/Protocol Factory so that they can reset the timeout on
> > the right socket. Do you know a way to identify the request/socket
> > combination reliably? I may have more than one request to the same host
> > being handled at the same time, and worse, may be even to the same
> > resource.
> > Can I rely on the thread id?
> > Thanks again.
> > On 9/15/05, Oleg Kalnichevski <ol...@apache.org> wrote:
> > >
> > > Presently only socket timeout value can be set on a per method / host /
> > > client basis. Connection timeout can be set on a per connection manager
> > > / client basis. The only way to work that problem around is to implement
> > > a custom connection manager or a custom protocol socket factory
> > >
> > > Oleg
> > >
> > >
> > > On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> > > > Hi Guy,
> > > >
> > > > you can't set the timeout on the connection because you don't know
> > > > which connection is going to be used until you execute the method.
> > > > You can set the timeout for the connection manager, which will affect
> > > > all connections. I think there is also a way to set the timeout based
> > > > on the HostConfiguration, which is probably what you want to do.
> > > >
> > > > hope that helps,
> > > > Roland
> > > >
> > > >
> > > >
> > > >
> > > > Questioner Guy <qu...@gmail.com>
> > > > 15.09.2005 11:37
> > > > Please respond to
> > > > "HttpClient User Discussion"
> > > >
> > > >
> > > > To
> > > > httpclient-user@jakarta.apache.org
> > > > cc
> > > >
> > > > Subject
> > > > Connection level timeout settings
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I am trying to set the connection timeout at the individual connection
> > > > level. The following code snippet sets the timeout at the HttpClient
> > > level
> > > > HttpClient client = new HttpClient( new
> > > > MultiThreadedHttpConnectionManager() );
> > > > client.getHttpConnectionManager().getParams().setParameter("
> > > > http.connection.timeout", new Integer( 30 * 1000));
> > > > I want to be able to reset the connection timeout to certain web-sites
> > > > after getting a timeout exception from the call to HttpClient's
> > > > executeMethod() call. I coudn't figure out a way to get access to the
> > > > connection allocated to the call.
> > > > I am new to HttpClient and I apologize if this a trivial question, but
> > I
> > > > would appreciate the answer.
> > > > Thanks.
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > 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


Re: Connection level timeout settings

Posted by Questioner Guy <qu...@gmail.com>.
Once again thanks for such quick responses. 
 Thanks Oleg for pointing out to how the socket.timeout of the 
HostConfiguration overrides the value set at the Client level. In fact the 
value set at the Method level overrides the other two.
 This is exactly what I wanted for the connection timeout. Any idea why the 
same feature is not available for connection.timeout?

I am re-evaluating my design to see if I can avoid the need to reset the 
connection timeout. I may be able to interrupt the connection and achieve 
the same results. 
 I would still like to know the reason for treating
connection.timeoutsdifferently.
 Thanks.
   On 9/15/05, Roland Weber <RO...@de.ibm.com> wrote: 
> 
> Hello Guy,
> 
> when you get the timeout exception, you should release the current
> connection. When you retry the request, a new connection will be
> used. There is no point in setting anything at the old connection,
> which could be used subsequently by a completely different method.
> 
> You should implement your own connection manager. Then you can
> use some context sensitivity, for example a ThreadLocal variable,
> to set the timeout by the time the connection gets allocated.
> 
> hope that helps,
> Roland
> 
> 
> 
> 
> Questioner Guy <qu...@gmail.com>
> 15.09.2005 16:42
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> HttpClient User Discussion <ht...@jakarta.apache.org>
> cc
> 
> Subject
> Re: Connection level timeout settings
> 
> 
> 
> 
> 
> 
> Thanks for the reply Roland, Oleg!!
> I'll try all three approaches Host Configuration/ Connection Manager
> and/or
> custom protocol factory approaches and let you know if I am able to fix
> the
> problem.
> The problem is that when I get the first timeout exception, I need to be
> able to identify the current request being handled reliably to the
> Connection Manager/Protocol Factory so that they can reset the timeout on
> the right socket. Do you know a way to identify the request/socket
> combination reliably? I may have more than one request to the same host
> being handled at the same time, and worse, may be even to the same
> resource.
> Can I rely on the thread id?
> Thanks again.
> On 9/15/05, Oleg Kalnichevski <ol...@apache.org> wrote:
> >
> > Presently only socket timeout value can be set on a per method / host /
> > client basis. Connection timeout can be set on a per connection manager
> > / client basis. The only way to work that problem around is to implement
> > a custom connection manager or a custom protocol socket factory
> >
> > Oleg
> >
> >
> > On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> > > Hi Guy,
> > >
> > > you can't set the timeout on the connection because you don't know
> > > which connection is going to be used until you execute the method.
> > > You can set the timeout for the connection manager, which will affect
> > > all connections. I think there is also a way to set the timeout based
> > > on the HostConfiguration, which is probably what you want to do.
> > >
> > > hope that helps,
> > > Roland
> > >
> > >
> > >
> > >
> > > Questioner Guy <qu...@gmail.com>
> > > 15.09.2005 11:37
> > > Please respond to
> > > "HttpClient User Discussion"
> > >
> > >
> > > To
> > > httpclient-user@jakarta.apache.org
> > > cc
> > >
> > > Subject
> > > Connection level timeout settings
> > >
> > >
> > >
> > >
> > >
> > >
> > > I am trying to set the connection timeout at the individual connection
> > > level. The following code snippet sets the timeout at the HttpClient
> > level
> > > HttpClient client = new HttpClient( new
> > > MultiThreadedHttpConnectionManager() );
> > > client.getHttpConnectionManager().getParams().setParameter("
> > > http.connection.timeout", new Integer( 30 * 1000));
> > > I want to be able to reset the connection timeout to certain web-sites
> > > after getting a timeout exception from the call to HttpClient's
> > > executeMethod() call. I coudn't figure out a way to get access to the
> > > connection allocated to the call.
> > > I am new to HttpClient and I apologize if this a trivial question, but
> I
> > > would appreciate the answer.
> > > Thanks.
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
>

Re: Connection level timeout settings

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, Sep 15, 2005 at 08:12:56PM +0530, Questioner Guy wrote:
> Thanks for the reply Roland, Oleg!!
>  I'll try all three approaches Host Configuration/ Connection Manager and/or 
> custom protocol factory approaches and let you know if I am able to fix the 
> problem.
>  The problem is that when I get the first timeout exception, I need to be 
> able to identify the current request being handled reliably to the 
> Connection Manager/Protocol Factory so that they can reset the timeout on 
> the right socket. 

Wait a minute. Are you talking about a connection timeout or a socket
read timeout? 


Do you know a way to identify the request/socket 
> combination reliably? 

HttpClient does not provide a direct access to the underlying sockets (for
all sorts of reasons). Probably what you are interested in is the
relationship between an HttpMethod and its HostConfiguration. The
connection manager will create a new connection or obtain an existing one
from the pool based on the given HostConfiguration. Each individual host
configuration can have a different socket timeout value, which will
override that set on the HttpClient level

Hope this helps

Oleg


I may have more than one request to the same host 
> being handled at the same time, and worse, may be even to the same resource. 
> Can I rely on the thread id?
>  Thanks again.
>  On 9/15/05, Oleg Kalnichevski <ol...@apache.org> wrote: 
> > 
> > Presently only socket timeout value can be set on a per method / host /
> > client basis. Connection timeout can be set on a per connection manager
> > / client basis. The only way to work that problem around is to implement
> > a custom connection manager or a custom protocol socket factory
> > 
> > Oleg
> > 
> > 
> > On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> > > Hi Guy,
> > >
> > > you can't set the timeout on the connection because you don't know
> > > which connection is going to be used until you execute the method.
> > > You can set the timeout for the connection manager, which will affect
> > > all connections. I think there is also a way to set the timeout based
> > > on the HostConfiguration, which is probably what you want to do.
> > >
> > > hope that helps,
> > > Roland
> > >
> > >
> > >
> > >
> > > Questioner Guy <qu...@gmail.com>
> > > 15.09.2005 11:37
> > > Please respond to
> > > "HttpClient User Discussion"
> > >
> > >
> > > To
> > > httpclient-user@jakarta.apache.org
> > > cc
> > >
> > > Subject
> > > Connection level timeout settings
> > >
> > >
> > >
> > >
> > >
> > >
> > > I am trying to set the connection timeout at the individual connection
> > > level. The following code snippet sets the timeout at the HttpClient 
> > level
> > > HttpClient client = new HttpClient( new
> > > MultiThreadedHttpConnectionManager() );
> > > client.getHttpConnectionManager().getParams().setParameter("
> > > http.connection.timeout", new Integer( 30 * 1000));
> > > I want to be able to reset the connection timeout to certain web-sites
> > > after getting a timeout exception from the call to HttpClient's
> > > executeMethod() call. I coudn't figure out a way to get access to the
> > > connection allocated to the call.
> > > I am new to HttpClient and I apologize if this a trivial question, but I
> > > would appreciate the answer.
> > > Thanks.
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> > 
> >

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


Re: Connection level timeout settings

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Guy,

when you get the timeout exception, you should release the current 
connection. When you retry the request, a new connection will be
used. There is no point in setting anything at the old connection,
which could be used subsequently by a completely different method.

You should implement your own connection manager. Then you can
use some context sensitivity, for example a ThreadLocal variable,
to set the timeout by the time the connection gets allocated.

hope that helps,
  Roland




Questioner Guy <qu...@gmail.com> 
15.09.2005 16:42
Please respond to
"HttpClient User Discussion"


To
HttpClient User Discussion <ht...@jakarta.apache.org>
cc

Subject
Re: Connection level timeout settings






Thanks for the reply Roland, Oleg!!
 I'll try all three approaches Host Configuration/ Connection Manager 
and/or 
custom protocol factory approaches and let you know if I am able to fix 
the 
problem.
 The problem is that when I get the first timeout exception, I need to be 
able to identify the current request being handled reliably to the 
Connection Manager/Protocol Factory so that they can reset the timeout on 
the right socket. Do you know a way to identify the request/socket 
combination reliably? I may have more than one request to the same host 
being handled at the same time, and worse, may be even to the same 
resource. 
Can I rely on the thread id?
 Thanks again.
 On 9/15/05, Oleg Kalnichevski <ol...@apache.org> wrote: 
> 
> Presently only socket timeout value can be set on a per method / host /
> client basis. Connection timeout can be set on a per connection manager
> / client basis. The only way to work that problem around is to implement
> a custom connection manager or a custom protocol socket factory
> 
> Oleg
> 
> 
> On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> > Hi Guy,
> >
> > you can't set the timeout on the connection because you don't know
> > which connection is going to be used until you execute the method.
> > You can set the timeout for the connection manager, which will affect
> > all connections. I think there is also a way to set the timeout based
> > on the HostConfiguration, which is probably what you want to do.
> >
> > hope that helps,
> > Roland
> >
> >
> >
> >
> > Questioner Guy <qu...@gmail.com>
> > 15.09.2005 11:37
> > Please respond to
> > "HttpClient User Discussion"
> >
> >
> > To
> > httpclient-user@jakarta.apache.org
> > cc
> >
> > Subject
> > Connection level timeout settings
> >
> >
> >
> >
> >
> >
> > I am trying to set the connection timeout at the individual connection
> > level. The following code snippet sets the timeout at the HttpClient 
> level
> > HttpClient client = new HttpClient( new
> > MultiThreadedHttpConnectionManager() );
> > client.getHttpConnectionManager().getParams().setParameter("
> > http.connection.timeout", new Integer( 30 * 1000));
> > I want to be able to reset the connection timeout to certain web-sites
> > after getting a timeout exception from the call to HttpClient's
> > executeMethod() call. I coudn't figure out a way to get access to the
> > connection allocated to the call.
> > I am new to HttpClient and I apologize if this a trivial question, but 
I
> > would appreciate the answer.
> > Thanks.
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 
>



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


Re: Connection level timeout settings

Posted by Questioner Guy <qu...@gmail.com>.
Thanks for the reply Roland, Oleg!!
 I'll try all three approaches Host Configuration/ Connection Manager and/or 
custom protocol factory approaches and let you know if I am able to fix the 
problem.
 The problem is that when I get the first timeout exception, I need to be 
able to identify the current request being handled reliably to the 
Connection Manager/Protocol Factory so that they can reset the timeout on 
the right socket. Do you know a way to identify the request/socket 
combination reliably? I may have more than one request to the same host 
being handled at the same time, and worse, may be even to the same resource. 
Can I rely on the thread id?
 Thanks again.
 On 9/15/05, Oleg Kalnichevski <ol...@apache.org> wrote: 
> 
> Presently only socket timeout value can be set on a per method / host /
> client basis. Connection timeout can be set on a per connection manager
> / client basis. The only way to work that problem around is to implement
> a custom connection manager or a custom protocol socket factory
> 
> Oleg
> 
> 
> On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> > Hi Guy,
> >
> > you can't set the timeout on the connection because you don't know
> > which connection is going to be used until you execute the method.
> > You can set the timeout for the connection manager, which will affect
> > all connections. I think there is also a way to set the timeout based
> > on the HostConfiguration, which is probably what you want to do.
> >
> > hope that helps,
> > Roland
> >
> >
> >
> >
> > Questioner Guy <qu...@gmail.com>
> > 15.09.2005 11:37
> > Please respond to
> > "HttpClient User Discussion"
> >
> >
> > To
> > httpclient-user@jakarta.apache.org
> > cc
> >
> > Subject
> > Connection level timeout settings
> >
> >
> >
> >
> >
> >
> > I am trying to set the connection timeout at the individual connection
> > level. The following code snippet sets the timeout at the HttpClient 
> level
> > HttpClient client = new HttpClient( new
> > MultiThreadedHttpConnectionManager() );
> > client.getHttpConnectionManager().getParams().setParameter("
> > http.connection.timeout", new Integer( 30 * 1000));
> > I want to be able to reset the connection timeout to certain web-sites
> > after getting a timeout exception from the call to HttpClient's
> > executeMethod() call. I coudn't figure out a way to get access to the
> > connection allocated to the call.
> > I am new to HttpClient and I apologize if this a trivial question, but I
> > would appreciate the answer.
> > Thanks.
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 
>

Re: Connection level timeout settings

Posted by Oleg Kalnichevski <ol...@apache.org>.
Presently only socket timeout value can be set on a per method / host /
client basis. Connection timeout can be set on a per connection manager
/ client basis. The only way to work that problem around is to implement
a custom connection manager or a custom protocol socket factory

Oleg


On Thu, Sep 15, 2005 at 12:22:46PM +0200, Roland Weber wrote:
> Hi Guy,
> 
> you can't set the timeout on the connection because you don't know
> which connection is going to be used until you execute the method.
> You can set the timeout for the connection manager, which will affect
> all connections. I think there is also a way to set the timeout based
> on the HostConfiguration, which is probably what you want to do.
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Questioner Guy <qu...@gmail.com> 
> 15.09.2005 11:37
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> httpclient-user@jakarta.apache.org
> cc
> 
> Subject
> Connection level timeout settings
> 
> 
> 
> 
> 
> 
> I am trying to set the connection timeout at the individual connection 
> level. The following code snippet sets the timeout at the HttpClient level
>   HttpClient client = new HttpClient( new 
> MultiThreadedHttpConnectionManager() );
> client.getHttpConnectionManager().getParams().setParameter("
> http.connection.timeout", new Integer( 30 * 1000));
>  I want to be able to reset the connection timeout to certain web-sites 
> after getting a timeout exception from the call to HttpClient's 
> executeMethod() call. I coudn't figure out a way to get access to the 
> connection allocated to the call. 
>  I am new to HttpClient and I apologize if this a trivial question, but I 
> would appreciate the answer.
>  Thanks.
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Connection level timeout settings

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Guy,

you can't set the timeout on the connection because you don't know
which connection is going to be used until you execute the method.
You can set the timeout for the connection manager, which will affect
all connections. I think there is also a way to set the timeout based
on the HostConfiguration, which is probably what you want to do.

hope that helps,
  Roland




Questioner Guy <qu...@gmail.com> 
15.09.2005 11:37
Please respond to
"HttpClient User Discussion"


To
httpclient-user@jakarta.apache.org
cc

Subject
Connection level timeout settings






I am trying to set the connection timeout at the individual connection 
level. The following code snippet sets the timeout at the HttpClient level
  HttpClient client = new HttpClient( new 
MultiThreadedHttpConnectionManager() );
client.getHttpConnectionManager().getParams().setParameter("
http.connection.timeout", new Integer( 30 * 1000));
 I want to be able to reset the connection timeout to certain web-sites 
after getting a timeout exception from the call to HttpClient's 
executeMethod() call. I coudn't figure out a way to get access to the 
connection allocated to the call. 
 I am new to HttpClient and I apologize if this a trivial question, but I 
would appreciate the answer.
 Thanks.



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