Java URLConnection Timeout

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-07-02T06:35:37Z Indexed on 2011/11/23 9:50 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

I am trying to parse an XML file from an HTTP URL. I want to configure a timeout of 15 seconds if the XML fetch takes longer than that, I want to report a timeout. For some reason, the setConnectTimeout and setReadTimeout do not work. Here's the code:

          URL url = new URL("http://www.myurl.com/sample.xml");
          URLConnection urlConn = url.openConnection();
          urlConn.setConnectTimeout(15000);
          urlConn.setReadTimeout(15000);
          urlConn.setAllowUserInteraction(false);         
          urlConn.setDoOutput(true);

          InputStream inStream = urlConn.getInputStream();
          InputSource input = new InputSource(inStream);

And I am catching the SocketTimeoutException.

Thanks Chris

© Stack Overflow or respective owner

Related posts about java

Related posts about timeout