public class HttpURLFeedFetcher extends AbstractFeedFetcher
Class to retrieve syndication files via HTTP.
If passed a FeedFetcherCache in the constructor it will use
conditional gets to only retrieve modified content.
The class uses the Accept-Encoding: gzip header to retrieve gzipped feeds where supported by the server.
Simple usage:
// create the cache FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getFeedInfoCache(); // retrieve the feed the first time // any subsequent request will use conditional gets and only // retrieve the resource if it has changed SyndFeed feed = new HttpURLFeedFetcher(feedInfoCache).retrieveFeed(feedUrl);
DEFAULT_USER_AGENT| Constructor and Description |
|---|
HttpURLFeedFetcher()
Constructor to use HttpURLFeedFetcher without caching of feeds
|
HttpURLFeedFetcher(FeedFetcherCache feedInfoCache)
Constructor to enable HttpURLFeedFetcher to cache feeds
|
| Modifier and Type | Method and Description |
|---|---|
FeedFetcherCache |
getFeedInfoCache() |
protected void |
resetFeedInfo(URL orignalUrl,
SyndFeedInfo syndFeedInfo,
HttpURLConnection connection) |
protected void |
retrieveAndCacheFeed(URL feedUrl,
SyndFeedInfo syndFeedInfo,
HttpURLConnection connection) |
com.rometools.rome.feed.synd.SyndFeed |
retrieveFeed(String userAgent,
URL feedUrl)
Retrieve a feed over HTTP
|
com.rometools.rome.feed.synd.SyndFeed |
retrieveFeed(URL feedUrl)
Retrieve a feed over HTTP
|
void |
setConnectTimeout(int timeout) |
void |
setFeedInfoCache(FeedFetcherCache cache) |
protected void |
setRequestHeaders(URLConnection connection,
SyndFeedInfo syndFeedInfo)
Set appropriate HTTP headers, including conditional get and gzip encoding headers
|
addFetcherEventListener, combineFeeds, fireEvent, fireEvent, fireEvent, fireEvent, getUserAgent, handleErrorCodes, isPreserveWireFeed, isUsingDeltaEncoding, removeFetcherEventListener, setPreserveWireFeed, setUserAgent, setUsingDeltaEncoding, throw4XXError, throwAuthenticationErrorpublic HttpURLFeedFetcher()
public HttpURLFeedFetcher(FeedFetcherCache feedInfoCache)
feedCache - - an instance of the FeedFetcherCache interfacepublic com.rometools.rome.feed.synd.SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, com.rometools.rome.io.FeedException, FetcherException
FeedFetcherfeedUrl - A non-null URL of a RSS/Atom feed to retrieveSyndFeed objectIllegalArgumentException - if the URL is null;IOException - if a TCP error occurscom.rometools.rome.io.FeedException - if the feed is not validFetcherException - if a HTTP error occurredpublic com.rometools.rome.feed.synd.SyndFeed retrieveFeed(String userAgent, URL feedUrl) throws IllegalArgumentException, IOException, com.rometools.rome.io.FeedException, FetcherException
feedUrl - A non-null URL of a RSS/Atom feed to retrieveSyndFeed objectIllegalArgumentException - if the URL is null;IOException - if a TCP error occurscom.rometools.rome.io.FeedException - if the feed is not validFetcherException - if a HTTP error occurredprotected void retrieveAndCacheFeed(URL feedUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection) throws IllegalArgumentException, com.rometools.rome.io.FeedException, FetcherException, IOException
IllegalArgumentExceptioncom.rometools.rome.io.FeedExceptionFetcherExceptionIOExceptionprotected void resetFeedInfo(URL orignalUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection) throws IllegalArgumentException, IOException, com.rometools.rome.io.FeedException
IllegalArgumentExceptionIOExceptioncom.rometools.rome.io.FeedExceptionprotected void setRequestHeaders(URLConnection connection, SyndFeedInfo syndFeedInfo)
Set appropriate HTTP headers, including conditional get and gzip encoding headers
connection - A URLConnectionsyndFeedInfo - The SyndFeedInfo for the feed to be retrieved. May be nullpublic FeedFetcherCache getFeedInfoCache()
public void setFeedInfoCache(FeedFetcherCache cache)
cache - The cache to be used by this fetcher (pass null to stop using a cache)public void setConnectTimeout(int timeout)
timeout - see java.net.URLConnection.setConnectTimeout(int timeout)Copyright © 2015. All Rights Reserved.