Jakarta's Latest HttpClient

B

Brent

I'm not "real" familiar with Java, but enough to get around. However,
I'm seemingly having a problem getting a URL connection to timeout
correctly using HttpClient. Example code follows:


// Create HTTP Client
int theTimeOut = Integer.parseInt(TimeOutTime); // TimeOutTime is a
String = "5" (testing purposes)
theTimeOut = (theTimeOut * 1000);
HttpClient client = new HttpClient();
client.getParams().setParameter("http.socket.timeout", new
Integer(theTimeOut));

// Create method to get URL
GetMethod get = new GetMethod("http://10.0.14.200:8201");
get.getParams().setParameter("http.socket.timeout", new
Integer(theTimeOut));

// Try to retrieve URL
client.executeMethod(get);

.......blah blah blah blah

Basically, the server http://10.0.14.200:8201 does not exist, so
instead of timing out in 5 seconds as it should, it takes, I don't
know, at least a minute.

Any ideas why it doesn't timeout as it should trying to connect?

What am I missing here.

JDK 1.4.2 is what I'm running.

-Brent
 
J

John C. Bollinger

Brent said:
I'm not "real" familiar with Java, but enough to get around. However,
I'm seemingly having a problem getting a URL connection to timeout
correctly using HttpClient. Example code follows:


// Create HTTP Client
int theTimeOut = Integer.parseInt(TimeOutTime); // TimeOutTime is a
String = "5" (testing purposes)
theTimeOut = (theTimeOut * 1000);
HttpClient client = new HttpClient();
client.getParams().setParameter("http.socket.timeout", new
Integer(theTimeOut));

You really ought to use HttpMethodParams.SO_TIMEOUT instead of a String
literal for the key. That could be the cause of your problem, though I
doubt it.
// Create method to get URL
GetMethod get = new GetMethod("http://10.0.14.200:8201");
get.getParams().setParameter("http.socket.timeout", new
Integer(theTimeOut));

Again, use the symbolic name for the key.
// Try to retrieve URL
client.executeMethod(get);

......blah blah blah blah

Basically, the server http://10.0.14.200:8201 does not exist, so
instead of timing out in 5 seconds as it should, it takes, I don't
know, at least a minute.

Any ideas why it doesn't timeout as it should trying to connect?

What am I missing here.

JDK 1.4.2 is what I'm running.

You may be missing that SO_TIMEOUT applies to reads, but not to connects
(at least, as far as I have ever been able to tell from various Java API
docs and Linux/POSIX system docs). You may also be missing that it is
system-dependent whether it is possible to change the socket timeout at
all. There is an outside chance that you have a retry handler
configured on the GetMethod (possibly by default), and that you are
therefore seeing multiple timeouts before the executeMethod() invocation
returns. There is a very slim chance that your system's resolver
library is doing something funny (and likely buggy) that causes the delay.

You could try configuring an HttpClientParams.CONNECTION_MANAGER_TIMEOUT
on the HttpClient instance instead. I don't know whether that will do
the job, but it seems on its face to be a better fit.

Note: HttpClient specifics are referred to recently-released HttpClient
3.0, which is not API-compatible with HttpClient 2.
 
B

Brent

Wow...really, it only applies to "reads" not "connects". That really
seems like a huge oversight. I have a custom Retry Handler so that it
does NOT retry after the first fail. Took me a while to figure that one
out as well ;-)

At any rate, I'll take your advice and try the
CONNECTION_MANAGER_TIMEOUT

Thank you for your reply!!

-Brent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top