Results 1 to 3 of 3
- 03-31-2010, 05:12 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
URLConnection not timing out as expected
Hi all,
This is my first post in what looks to be a great forum on java development. I look forward to contributing and getting help!
I am working on a project where I must validate a large number of urls contained in a database (50,000+ urls). I have developed a java application to do the validating for me using Java 1.5 on AIX UNIX.
I am having problems with some of the urls where they are no longer valid. The httpConnection.connect() part of the code seems to hang. I have set connection.setConnectTimeout(2000) in an attempt to have the connection timeout after two seconds. However, the connection takes over 2 minutes to eventually time out. The java error that I'm receiving is:
java.net.SocketException: Unexpected end of file from server
at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:736)
at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:607)
at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:734)
at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:607)
at sun.net.http://www.protocol.http.HttpURLConn...ction.java:966)
at java.net.HttpURLConnection.getResponseCode(HttpURL Connection.java:379)
at ValidateURLs.main(ValidateURLs.java:94)
A shortened version of my code is as follows:
int connectionTimeout = 2000;
String processUrl = "http://hubbell.syndication.exaltsolutions.com/exalt/doc/Horizontal.PDF";
URL url = new URL(processUrl);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(connectionTimeout);
try {
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection)connection;
httpConnection.connect();
int returnCode = httpConnection.getResponseCode();
httpConnection.disconnect();
} // if (connection instanceof HttpURLConnection) {
} catch (Exception e) {
e.printStackTrace();
}
What can I do to get the timeout to work?
Thank you!
-StephenS
- 04-02-2010, 12:58 AM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Look at this thread :
Socket Programming - java.net.SocketException: Unexpected end of file from server
- 04-02-2010, 03:10 AM #3
I'm not certain, but... It sounds like you are establishing a connection, but that the response does not contain valid data, or no response is being sent. You may be attempting to create an HTTP connection to a URL that does not support HTTP. That could create a raw socket that would subsequently fail.
The Java Tutorial. Read it.
Similar Threads
-
Content type for MS files "content/unknown" with URLConnection
By serjant in forum NetworkingReplies: 2Last Post: 05-30-2009, 10:42 AM -
How to set request parameters to an URLConnection
By somesh A in forum NetworkingReplies: 0Last Post: 04-10-2009, 08:08 AM -
Servlet to Servlet connection through URLConnection
By bsrjavaforum in forum NetworkingReplies: 0Last Post: 04-01-2009, 04:12 PM -
Timing array loop performance
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM -
Opening URLConnection
By Java Tip in forum Java TipReplies: 0Last Post: 11-24-2007, 07:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks