Ability to set connection timeout for HttpURLFeedFetcher

This commit is contained in:
Jani Halinen 2014-03-09 15:25:53 +02:00
parent f29d19b7c4
commit 4867ab7deb

View file

@ -67,6 +67,7 @@ import com.sun.syndication.io.XmlReader;
* @author Nick Lothian * @author Nick Lothian
*/ */
public class HttpURLFeedFetcher extends AbstractFeedFetcher { public class HttpURLFeedFetcher extends AbstractFeedFetcher {
private int connectTimeout = -1;
static final int POLL_EVENT = 1; static final int POLL_EVENT = 1;
static final int RETRIEVE_EVENT = 2; static final int RETRIEVE_EVENT = 2;
static final int UNCHANGED_EVENT = 3; static final int UNCHANGED_EVENT = 3;
@ -117,6 +118,9 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
throw new IllegalArgumentException(feedUrl.toExternalForm() + " is not a valid HTTP Url"); throw new IllegalArgumentException(feedUrl.toExternalForm() + " is not a valid HTTP Url");
} }
final HttpURLConnection httpConnection = (HttpURLConnection) connection; final HttpURLConnection httpConnection = (HttpURLConnection) connection;
if (connectTimeout >= 0) {
httpConnection.setConnectTimeout(connectTimeout);
}
// httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be changed on a claswide basis // httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be changed on a claswide basis
final FeedFetcherCache cache = getFeedInfoCache(); final FeedFetcherCache cache = getFeedInfoCache();
@ -312,4 +316,11 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
public synchronized void setFeedInfoCache(final FeedFetcherCache cache) { public synchronized void setFeedInfoCache(final FeedFetcherCache cache) {
feedInfoCache = cache; feedInfoCache = cache;
} }
/**
* @param timeout see java.net.URLConnection.setConnectTimeout(int timeout)
*/
public synchronized void setConnectTimeout(final int timeout) {
connectTimeout = timeout;
}
} }