org.rometools.fetcher.impl
Class HttpURLFeedFetcher

java.lang.Object
  extended by org.rometools.fetcher.impl.AbstractFeedFetcher
      extended by org.rometools.fetcher.impl.HttpURLFeedFetcher
All Implemented Interfaces:
FeedFetcher

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);

Author:
Nick Lothian
See Also:
http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers, http://diveintomark.org/archives/2003/07/21/atom_aggregator_behavior_http_level, http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html

Field Summary
 
Fields inherited from interface org.rometools.fetcher.FeedFetcher
DEFAULT_USER_AGENT
 
Constructor Summary
HttpURLFeedFetcher()
          Constructor to use HttpURLFeedFetcher without caching of feeds
HttpURLFeedFetcher(FeedFetcherCache feedInfoCache)
          Constructor to enable HttpURLFeedFetcher to cache feeds
 
Method Summary
 FeedFetcherCache getFeedInfoCache()
           
protected  void resetFeedInfo(URL orignalUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection)
           
protected  void retrieveAndCacheFeed(URL feedUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection)
           
 com.sun.syndication.feed.synd.SyndFeed retrieveFeed(String userAgent, URL feedUrl)
          Retrieve a feed over HTTP
 com.sun.syndication.feed.synd.SyndFeed retrieveFeed(URL feedUrl)
          Retrieve a feed over HTTP
 void setFeedInfoCache(FeedFetcherCache cache)
           
protected  void setRequestHeaders(URLConnection connection, SyndFeedInfo syndFeedInfo)
          Set appropriate HTTP headers, including conditional get and gzip encoding headers
 
Methods inherited from class org.rometools.fetcher.impl.AbstractFeedFetcher
addFetcherEventListener, combineFeeds, fireEvent, fireEvent, fireEvent, fireEvent, getUserAgent, handleErrorCodes, isPreserveWireFeed, isUsingDeltaEncoding, removeFetcherEventListener, setPreserveWireFeed, setUserAgent, setUsingDeltaEncoding, throw4XXError, throwAuthenticationError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpURLFeedFetcher

public HttpURLFeedFetcher()
Constructor to use HttpURLFeedFetcher without caching of feeds


HttpURLFeedFetcher

public HttpURLFeedFetcher(FeedFetcherCache feedInfoCache)
Constructor to enable HttpURLFeedFetcher to cache feeds

Parameters:
feedCache - - an instance of the FeedFetcherCache interface
Method Detail

retrieveFeed

public com.sun.syndication.feed.synd.SyndFeed retrieveFeed(URL feedUrl)
                                                    throws IllegalArgumentException,
                                                           IOException,
                                                           com.sun.syndication.io.FeedException,
                                                           FetcherException
Description copied from interface: FeedFetcher
Retrieve a feed over HTTP

Parameters:
feedUrl - A non-null URL of a RSS/Atom feed to retrieve
Returns:
A SyndFeed object
Throws:
IllegalArgumentException - if the URL is null;
IOException - if a TCP error occurs
com.sun.syndication.io.FeedException - if the feed is not valid
FetcherException - if a HTTP error occurred

retrieveFeed

public com.sun.syndication.feed.synd.SyndFeed retrieveFeed(String userAgent,
                                                           URL feedUrl)
                                                    throws IllegalArgumentException,
                                                           IOException,
                                                           com.sun.syndication.io.FeedException,
                                                           FetcherException
Retrieve a feed over HTTP

Parameters:
feedUrl - A non-null URL of a RSS/Atom feed to retrieve
Returns:
A SyndFeed object
Throws:
IllegalArgumentException - if the URL is null;
IOException - if a TCP error occurs
com.sun.syndication.io.FeedException - if the feed is not valid
FetcherException - if a HTTP error occurred

retrieveAndCacheFeed

protected void retrieveAndCacheFeed(URL feedUrl,
                                    SyndFeedInfo syndFeedInfo,
                                    HttpURLConnection connection)
                             throws IllegalArgumentException,
                                    com.sun.syndication.io.FeedException,
                                    FetcherException,
                                    IOException
Throws:
IllegalArgumentException
com.sun.syndication.io.FeedException
FetcherException
IOException

resetFeedInfo

protected void resetFeedInfo(URL orignalUrl,
                             SyndFeedInfo syndFeedInfo,
                             HttpURLConnection connection)
                      throws IllegalArgumentException,
                             IOException,
                             com.sun.syndication.io.FeedException
Throws:
IllegalArgumentException
IOException
com.sun.syndication.io.FeedException

setRequestHeaders

protected void setRequestHeaders(URLConnection connection,
                                 SyndFeedInfo syndFeedInfo)

Set appropriate HTTP headers, including conditional get and gzip encoding headers

Parameters:
connection - A URLConnection
syndFeedInfo - The SyndFeedInfo for the feed to be retrieved. May be null

getFeedInfoCache

public FeedFetcherCache getFeedInfoCache()
Returns:
The FeedFetcherCache used by this fetcher (Could be null)

setFeedInfoCache

public void setFeedInfoCache(FeedFetcherCache cache)
Parameters:
cache - The cache to be used by this fetcher (pass null to stop using a cache)


Copyright © 2004-2013 ROME Project. All Rights Reserved.