Results 1 to 3 of 3
  1. #1
    StephenS is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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

  1. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  2. How to set request parameters to an URLConnection
    By somesh A in forum Networking
    Replies: 0
    Last Post: 04-10-2009, 08:08 AM
  3. Servlet to Servlet connection through URLConnection
    By bsrjavaforum in forum Networking
    Replies: 0
    Last Post: 04-01-2009, 04:12 PM
  4. Timing array loop performance
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:43 PM
  5. Opening URLConnection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-24-2007, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •