Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Jakarta's Latest HttpClient

Thread view: 
Brent - 19 Jan 2006 06:27 GMT
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
John C. Bollinger - 20 Jan 2006 04:14 GMT
> 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
[quoted text clipped - 7 lines]
> 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);
[quoted text clipped - 10 lines]
>
> 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.

Signature

John Bollinger
jobollin@indiana.edu

Brent - 20 Jan 2006 05:36 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.