5

I am parsing a fair amount of RSS feeds in cascade using Java ROME as my XML parser. Sometimes one of the RSS feeds might be unreachable because of network issues, which results in a Socket timeout when trying to create the XMLReader object ( new XMLReader(url)).

The problem is that the default timeout lasts about 2 decades and when it happens it's slowing down the whole process.

Is there a way to change the default socket timeout in Java ROME?

Francesco
  • 315
  • 1
  • 3
  • 9

1 Answers1

7

When you create XMLReader object ( new XMLReader(url)), you already have a URLConnection object which is passed as the argument for XMLReader. Call, setConnectTimeout(long) of URLConnection and set your timeout value. I dont think Rome provides any connection timeout options

rajesh
  • 3,247
  • 5
  • 31
  • 56
  • Thank you. The object passed as argument to the XMLReader constructor is actually a java.net.URL object, which doesn't provide any setConnectTimeout method. Actually, I could wrap the java.net.URL object into a URLConnection object and pass that to the XMLReader constructor, but then I'm asked to implement a connect() method for the URLConnection object and I have no idea of hat to put in it.. – Francesco Apr 05 '13 at 11:04
  • 1
    `XmlReader` can be constructed with both URL and URLConnection. check http://www.jarvana.com/jarvana/view/rome/rome/0.9/rome-0.9-javadoc.jar!/com/sun/syndication/io/XmlReader.html – rajesh Apr 05 '13 at 11:07
  • 5
    Thank you very much. Solved. `URLConnection urlConnection = new URL(rssSource).openConnection();` `urlConnection.setConnectTimeout(4000);` `reader = new XmlReader(urlConnection);` `feed = new SyndFeedInput().build(reader);` – Francesco Apr 05 '13 at 11:12
  • You may also want to give attention to `URLConnection.setReadTimeout(int timeoutMs)` – Michael Rush Apr 30 '14 at 16:22