Angie,
I ran the following test:
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
GetMethod httpget = new GetMethod("http://www.au.yahoo.com/");
try {
client.executeMethod(httpget);
System.out.println(httpget.getStatusLine());
System.out.println(httpget.getResponseBodyAsString());
} finally {
httpget.releaseConnection();
}
And this is what I got. As far as I am concerned everything works as
advertised.
...
[DEBUG] DefaultHttpParams - -Set parameter http.connection.timeout = 100
[DEBUG] HttpConnection - -Open connection to www.au.yahoo.com:80
[DEBUG] HttpConnection - -Releasing connection back to connection
manager.
Exception in thread "main"
org.apache.commons.httpclient.ConnectTimeoutException: The host did not
accept the connection within timeout of 100 ms
at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:145)
at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:124)
at org.apache.commons.httpclient.HttpConnection.open
(HttpConnection.java:705)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry
(HttpMethodDirector.java:359)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod
(HttpMethodDirector.java:168)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:393)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:324)
at Test.main(Test.java:32)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:128)
... 7 more
On Wed, 2004-12-01 at 12:56 -0800, Angie Lin wrote:
> Hmm, so I switched to a bogus IP address on our internal network.
>
> I am getting: java.net.ConnectException: Connection Timed out
>
> but it's still taking about 3 minutes instead of 10 seconds. I haven't
> done the trace logging yet...
>
>
>
> On Dec 1, 2004, at 12:26 PM, Oleg Kalnichevski wrote:
>
> > Angie,
> >
> > "java.net.UnknownHostException: some.nonexistent.com" basically has
> > nothing to do with the connect timeout. The application spends all this
> > time trying to resolve the DNS name and not trying to connect to the
> > server.
> >
> > Hope this helps
> >
> > Oleg
> >
> >
> > On Wed, 2004-12-01 at 12:03 -0800, Angie Lin wrote:
> >> I'm specifying a completely non-existent url to test the connection
> >> timeout. That should work, right (i.e. non-existent url)?
> >>
> >> Anyways, it doesn't appear to work even though I'm setting the
> >> connection timeout on client, connection manager, AND the method.
> >>
> >> Angie
> >>
> >>
> >> On Dec 1, 2004, at 11:57 AM, Oleg Kalnichevski wrote:
> >>
> >>> Angie,
> >>>
> >>> You are not confusing socket (read) timeout with connect (establish
> >>> connection) timeout, are you? To my knowledge timeouts work as
> >>> advertised.
> >>>
> >>> Oleg
> >>>
> >>> On Wed, 2004-12-01 at 11:23 -0800, Angie Lin wrote:
> >>>> Do the timeouts work?
> >>>>
> >>>> I've tried:
> >>>>
> >>>> int CONN_TIMEOUT=10000;
> >>>> HttpClient client=new HttpClient();
> >>>> // set timeout on client
> >>>> client.setConnectionTimeout(CONN_TIMEOUT);
> >>>> client.getParams().setParameter("http.connection.timeout",
> >>>> new Integer(CONN_TIMEOUT));
> >>>>
> >>>> // set timeout on connection manager
> >>>>
> >>>> client.getHttpConnectionManager().getParams().setParameter("http.con
> >>>> ne
> >>>> ct
> >>>> ion.timeout",
> >>>> new
> >>>> Integer(CONN_TIMEOUT));
> >>>>
> >>>> // set timeout on method
> >>>> GetMethod get=new
> >>>> GetMethod("http://some.nonexistent.com/somepage.html");
> >>>> get.getParams().setParameter("http.connection.timeout", new
> >>>> Integer(CONN_TIMEOUT));
> >>>> get.setHttp11(true);
> >>>>
> >>>> client.executeMethod(get);
> >>>>
> >>>>
> >>>> But it still takes roughly 3 minutes instead of the 10 seconds I
> >>>> expected. Is there a different way for specifying the timeout?
> >>>>
> >>>> --
> >>>> Angie Lin
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> --------------------------------------------------------------------
> >>>> -
> >>>> To unsubscribe, e-mail:
> >>>> [EMAIL PROTECTED]
> >>>> For additional commands, e-mail:
> >>>> [EMAIL PROTECTED]
> >>>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >>> [EMAIL PROTECTED]
> >>> For additional commands, e-mail:
> >>> [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail:
> >> [EMAIL PROTECTED]
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> >
> >
> >
> >
>
>
> !DSPAM:41ae301d240612045121280!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]