How to change Java ROME parser default socket timeout?
Asked Answered
H

1

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?

Hejaz answered 5/4, 2013 at 10:34 Comment(0)
H
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

Holmberg answered 5/4, 2013 at 10:47 Comment(4)
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..Hejaz
XmlReader can be constructed with both URL and URLConnection. check jarvana.com/jarvana/view/rome/rome/0.9/rome-0.9-javadoc.jar!/…Holmberg
Thank you very much. Solved. URLConnection urlConnection = new URL(rssSource).openConnection(); urlConnection.setConnectTimeout(4000); reader = new XmlReader(urlConnection); feed = new SyndFeedInput().build(reader);Hejaz
You may also want to give attention to URLConnection.setReadTimeout(int timeoutMs)Parts

© 2022 - 2024 — McMap. All rights reserved.