You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Alex <al...@optonline.net> on 2006/04/25 00:38:15 UTC

[commons-httpclient] setConnectionTimeout not working?

  client = new HttpClient();

 

SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();

mr.getParams().setConnectionTimeout(1000);

client = new HttpClient(mr);   

 

 

long startTime = System.currentTimeMillis();

int resultCode = client.executeMethod(getMethod);  

setConnTime(System.currentTimeMillis()-startTime);  

 

 

my connection timeout is set to 1000 (1 second),  output shows that
connection to some site took over 3-4 seconds and 

it never comes to "catch (ConnectTimeoutException e)"  

 

 

why is it not throwing ConnectTimeoutException?


Re: [commons-httpclient] setConnectionTimeout not working?

Posted by Christian Hufgard <ch...@gmx.de>.
Hi Alex,

> long startTime = System.currentTimeMillis();
> int resultCode = client.executeMethod(getMethod);
> setConnTime(System.currentTimeMillis()-startTime);

> my connection timeout is set to 1000 (1 second),  output shows that
> connection to some site took over 3-4 seconds and 

> why is it not throwing ConnectTimeoutException?


Well, I guess I made the same wrong assumption you did. Connection
timeout is _not_ an overall timeout for the whole connection. It is a
timeout für getting a connection to the server.
A timeout of 1 second means, that if the server does not accecpt a
connection within one second a ConnectTimeoutException will be thrown.
But as soon as the connection is established, this value is no longer
regarded.
You can now also set a SocketTimeout which specifies how much time
may be between two bytes coming in and manually setting a read
timeout.

As far as I know, the httpclient has no support for a read timeout.
In our environment we had some really slow servers. They sent maybe
one byte each second. SocketTimeout was not reached, it was about 30
seconds since the request itself might took some time to process.
So I used a BufferedInputStream, read the data within a loop and
checked for the reading time manually.



-- 
Best regards,
 Christian                            mailto:christian.hufgard@gmx.de


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-04-25 at 11:05 -0400, Alex wrote:
> Thanks Oleg, 
> with what JRE timeout wouldn't  work?

Alex,

The Java runtime did not provide a means to set a timeout for the socket
connect operation until version 1.4. HttpClient uses a fairly nasty
trick to simulate the connect timeout on older JREs, which is not always
reliable. Moreover that trick can be even considered harmful if
HttpClient is run inside an EJB container, because it involves a
controller thread. 

Bottom-line, any JRE version above or equal to 1.4.2 should be fine.

Oleg


> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Tuesday, April 25, 2006 10:57 AM
> To: Jakarta Commons Users List
> Subject: RE: [commons-httpclient] setConnectionTimeout not working?
> 
> On Tue, 2006-04-25 at 10:50 -0400, Alex wrote:
> > I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? 
> 
> Yes, it does. 
> 
> > What
> > JRE would I need to use for the timeout to work?
> 
> First of all, you need to understand that the connect timeout is the
> maximum period of time a socket can stay blocked until the connection
> with the remote host is fully established. This has nothing to do with
> the total request execution time, which you are measuring in your code
> 
> Hope this helps
> 
> Oleg 
> 
> 
> > 
> > -----Original Message-----
> > From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> > Sent: Tuesday, April 25, 2006 3:52 AM
> > To: Jakarta Commons Users List
> > Subject: Re: [commons-httpclient] setConnectionTimeout not working?
> > 
> > On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
> > >   client = new HttpClient();
> > > 
> > >  
> > > 
> > > SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> > > 
> > > mr.getParams().setConnectionTimeout(1000);
> > > 
> > > client = new HttpClient(mr);   
> > > 
> > >  
> > > 
> > > 
> > > 
> > > long startTime = System.currentTimeMillis();
> > > 
> > > int resultCode = client.executeMethod(getMethod);  
> > > 
> > > setConnTime(System.currentTimeMillis()-startTime);  
> > > 
> > >  
> > > 
> > > 
> > > 
> > > my connection timeout is set to 1000 (1 second),  output shows that
> > > connection to some site took over 3-4 seconds and 
> > > 
> > > it never comes to "catch (ConnectTimeoutException e)"  
> > > 
> > >  
> > > 
> > > 
> > > 
> > > why is it not throwing ConnectTimeoutException?
> > > 
> > 
> > What's the JRE version that you are using? 
> > 
> > Try connecting to the host using a plain java.net.Socket and see if it
> > times out on connect.
> > 
> > Oleg
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Alex <al...@optonline.net>.
Thanks Oleg, 
with what JRE timeout wouldn't  work?

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Tuesday, April 25, 2006 10:57 AM
To: Jakarta Commons Users List
Subject: RE: [commons-httpclient] setConnectionTimeout not working?

On Tue, 2006-04-25 at 10:50 -0400, Alex wrote:
> I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? 

Yes, it does. 

> What
> JRE would I need to use for the timeout to work?

First of all, you need to understand that the connect timeout is the
maximum period of time a socket can stay blocked until the connection
with the remote host is fully established. This has nothing to do with
the total request execution time, which you are measuring in your code

Hope this helps

Oleg 


> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Tuesday, April 25, 2006 3:52 AM
> To: Jakarta Commons Users List
> Subject: Re: [commons-httpclient] setConnectionTimeout not working?
> 
> On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
> >   client = new HttpClient();
> > 
> >  
> > 
> > SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> > 
> > mr.getParams().setConnectionTimeout(1000);
> > 
> > client = new HttpClient(mr);   
> > 
> >  
> > 
> > 
> > 
> > long startTime = System.currentTimeMillis();
> > 
> > int resultCode = client.executeMethod(getMethod);  
> > 
> > setConnTime(System.currentTimeMillis()-startTime);  
> > 
> >  
> > 
> > 
> > 
> > my connection timeout is set to 1000 (1 second),  output shows that
> > connection to some site took over 3-4 seconds and 
> > 
> > it never comes to "catch (ConnectTimeoutException e)"  
> > 
> >  
> > 
> > 
> > 
> > why is it not throwing ConnectTimeoutException?
> > 
> 
> What's the JRE version that you are using? 
> 
> Try connecting to the host using a plain java.net.Socket and see if it
> times out on connect.
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


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


Re[2]: [commons-httpclient] setConnectionTimeout not working?

Posted by Christian Hufgard <ch...@gmx.de>.
Hi Alex,

>> Is there a way I could measure connection time and not a full request time?

> Yes, there is. Just implement a custom socket factory

Like I wrote before, I use a BufferedInputStream, read the data within
a loop and check for the reading time manually.

Might be easier than writing or extending a socket factory.


-- 
Best regards,
 Christian                            mailto:christian.hufgard@gmx.de


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-04-25 at 11:10 -0400, Alex wrote:
> Thanks Oleg,
> with what JRE timeout wouldn't  work?
> Is there a way I could measure connection time and not a full request time?

Yes, there is. Just implement a custom socket factory

Oleg

> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Tuesday, April 25, 2006 10:57 AM
> To: Jakarta Commons Users List
> Subject: RE: [commons-httpclient] setConnectionTimeout not working?
> 
> On Tue, 2006-04-25 at 10:50 -0400, Alex wrote:
> > I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? 
> 
> Yes, it does. 
> 
> > What
> > JRE would I need to use for the timeout to work?
> 
> First of all, you need to understand that the connect timeout is the
> maximum period of time a socket can stay blocked until the connection
> with the remote host is fully established. This has nothing to do with
> the total request execution time, which you are measuring in your code
> 
> Hope this helps
> 
> Oleg 
> 
> 
> > 
> > -----Original Message-----
> > From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> > Sent: Tuesday, April 25, 2006 3:52 AM
> > To: Jakarta Commons Users List
> > Subject: Re: [commons-httpclient] setConnectionTimeout not working?
> > 
> > On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
> > >   client = new HttpClient();
> > > 
> > >  
> > > 
> > > SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> > > 
> > > mr.getParams().setConnectionTimeout(1000);
> > > 
> > > client = new HttpClient(mr);   
> > > 
> > >  
> > > 
> > > 
> > > 
> > > long startTime = System.currentTimeMillis();
> > > 
> > > int resultCode = client.executeMethod(getMethod);  
> > > 
> > > setConnTime(System.currentTimeMillis()-startTime);  
> > > 
> > >  
> > > 
> > > 
> > > 
> > > my connection timeout is set to 1000 (1 second),  output shows that
> > > connection to some site took over 3-4 seconds and 
> > > 
> > > it never comes to "catch (ConnectTimeoutException e)"  
> > > 
> > >  
> > > 
> > > 
> > > 
> > > why is it not throwing ConnectTimeoutException?
> > > 
> > 
> > What's the JRE version that you are using? 
> > 
> > Try connecting to the host using a plain java.net.Socket and see if it
> > times out on connect.
> > 
> > Oleg
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Alex <al...@optonline.net>.
Thanks Oleg,
with what JRE timeout wouldn't  work?
Is there a way I could measure connection time and not a full request time?

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Tuesday, April 25, 2006 10:57 AM
To: Jakarta Commons Users List
Subject: RE: [commons-httpclient] setConnectionTimeout not working?

On Tue, 2006-04-25 at 10:50 -0400, Alex wrote:
> I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? 

Yes, it does. 

> What
> JRE would I need to use for the timeout to work?

First of all, you need to understand that the connect timeout is the
maximum period of time a socket can stay blocked until the connection
with the remote host is fully established. This has nothing to do with
the total request execution time, which you are measuring in your code

Hope this helps

Oleg 


> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Tuesday, April 25, 2006 3:52 AM
> To: Jakarta Commons Users List
> Subject: Re: [commons-httpclient] setConnectionTimeout not working?
> 
> On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
> >   client = new HttpClient();
> > 
> >  
> > 
> > SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> > 
> > mr.getParams().setConnectionTimeout(1000);
> > 
> > client = new HttpClient(mr);   
> > 
> >  
> > 
> > 
> > 
> > long startTime = System.currentTimeMillis();
> > 
> > int resultCode = client.executeMethod(getMethod);  
> > 
> > setConnTime(System.currentTimeMillis()-startTime);  
> > 
> >  
> > 
> > 
> > 
> > my connection timeout is set to 1000 (1 second),  output shows that
> > connection to some site took over 3-4 seconds and 
> > 
> > it never comes to "catch (ConnectTimeoutException e)"  
> > 
> >  
> > 
> > 
> > 
> > why is it not throwing ConnectTimeoutException?
> > 
> 
> What's the JRE version that you are using? 
> 
> Try connecting to the host using a plain java.net.Socket and see if it
> times out on connect.
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-04-25 at 10:50 -0400, Alex wrote:
> I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? 

Yes, it does. 

> What
> JRE would I need to use for the timeout to work?

First of all, you need to understand that the connect timeout is the
maximum period of time a socket can stay blocked until the connection
with the remote host is fully established. This has nothing to do with
the total request execution time, which you are measuring in your code

Hope this helps

Oleg 


> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Tuesday, April 25, 2006 3:52 AM
> To: Jakarta Commons Users List
> Subject: Re: [commons-httpclient] setConnectionTimeout not working?
> 
> On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
> >   client = new HttpClient();
> > 
> >  
> > 
> > SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> > 
> > mr.getParams().setConnectionTimeout(1000);
> > 
> > client = new HttpClient(mr);   
> > 
> >  
> > 
> > 
> > 
> > long startTime = System.currentTimeMillis();
> > 
> > int resultCode = client.executeMethod(getMethod);  
> > 
> > setConnTime(System.currentTimeMillis()-startTime);  
> > 
> >  
> > 
> > 
> > 
> > my connection timeout is set to 1000 (1 second),  output shows that
> > connection to some site took over 3-4 seconds and 
> > 
> > it never comes to "catch (ConnectTimeoutException e)"  
> > 
> >  
> > 
> > 
> > 
> > why is it not throwing ConnectTimeoutException?
> > 
> 
> What's the JRE version that you are using? 
> 
> Try connecting to the host using a plain java.net.Socket and see if it
> times out on connect.
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


RE: [commons-httpclient] setConnectionTimeout not working?

Posted by Alex <al...@optonline.net>.
I am using latest Netbeans 5.0  JRE 1.5..   does it make a difference? What
JRE would I need to use for the timeout to work?

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Tuesday, April 25, 2006 3:52 AM
To: Jakarta Commons Users List
Subject: Re: [commons-httpclient] setConnectionTimeout not working?

On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
>   client = new HttpClient();
> 
>  
> 
> SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> 
> mr.getParams().setConnectionTimeout(1000);
> 
> client = new HttpClient(mr);   
> 
>  
> 
> 
> 
> long startTime = System.currentTimeMillis();
> 
> int resultCode = client.executeMethod(getMethod);  
> 
> setConnTime(System.currentTimeMillis()-startTime);  
> 
>  
> 
> 
> 
> my connection timeout is set to 1000 (1 second),  output shows that
> connection to some site took over 3-4 seconds and 
> 
> it never comes to "catch (ConnectTimeoutException e)"  
> 
>  
> 
> 
> 
> why is it not throwing ConnectTimeoutException?
> 

What's the JRE version that you are using? 

Try connecting to the host using a plain java.net.Socket and see if it
times out on connect.

Oleg


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


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


Re: [commons-httpclient] setConnectionTimeout not working?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2006-04-24 at 18:38 -0400, Alex wrote:
>   client = new HttpClient();
> 
>  
> 
> SimpleHttpConnectionManager mr = new SimpleHttpConnectionManager();
> 
> mr.getParams().setConnectionTimeout(1000);
> 
> client = new HttpClient(mr);   
> 
>  
> 
> 
> 
> long startTime = System.currentTimeMillis();
> 
> int resultCode = client.executeMethod(getMethod);  
> 
> setConnTime(System.currentTimeMillis()-startTime);  
> 
>  
> 
> 
> 
> my connection timeout is set to 1000 (1 second),  output shows that
> connection to some site took over 3-4 seconds and 
> 
> it never comes to "catch (ConnectTimeoutException e)"  
> 
>  
> 
> 
> 
> why is it not throwing ConnectTimeoutException?
> 

What's the JRE version that you are using? 

Try connecting to the host using a plain java.net.Socket and see if it
times out on connect.

Oleg


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