[commons-httpclient] setConnectionTimeout not working?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[commons-httpclient] setConnectionTimeout not working?

Alex-123
  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?

Reply | Threaded
Open this post in threaded view
|

Re: [commons-httpclient] setConnectionTimeout not working?

olegk
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [commons-httpclient] setConnectionTimeout not working?

Christian Hufgard
In reply to this post by Alex-123
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:[hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

Alex-123
In reply to this post by olegk
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:[hidden email]]
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: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

olegk
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:[hidden email]]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

Alex-123
Thanks Oleg,
with what JRE timeout wouldn't  work?

-----Original Message-----
From: Oleg Kalnichevski [mailto:[hidden email]]
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:[hidden email]]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

Alex-123
In reply to this post by olegk
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:[hidden email]]
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:[hidden email]]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

olegk
In reply to this post by Alex-123
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:[hidden email]]
> 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:[hidden email]]
> > 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [commons-httpclient] setConnectionTimeout not working?

olegk
In reply to this post by Alex-123
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:[hidden email]]
> 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:[hidden email]]
> > 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Christian Hufgard
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:[hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]