com.sun.syndication.fetcher.impl
Class HttpURLFeedFetcher

java.lang.Object
  extended bycom.sun.syndication.fetcher.impl.AbstractFeedFetcher
      extended bycom.sun.syndication.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
private  FeedFetcherCache feedInfoCache
           
private  IProgressMonitor monitor
          The IProgressMonitor to report the progress of a newsfeed retrieval operation to.
(package private) static int POLL_EVENT
           
(package private) static int RETRIEVE_EVENT
           
(package private) static int UNCHANGED_EVENT
           
 
Fields inherited from class com.sun.syndication.fetcher.impl.AbstractFeedFetcher
 
Fields inherited from interface com.sun.syndication.fetcher.FeedFetcher
DEFAULT_USER_AGENT
 
Constructor Summary
HttpURLFeedFetcher()
          Constructor to use HttpURLFeedFetcher without caching of feeds
HttpURLFeedFetcher(FeedFetcherCache feedCache)
          Constructor to enable HttpURLFeedFetcher to cache feeds
HttpURLFeedFetcher(FeedFetcherCache feedCache, IProgressMonitor monitor)
           Constructor to enable HttpURLFeedFetcher to cache feeds and to report the progress of a newsfeed retrieval operation to the specified IProgressMonitor.
 
Method Summary
 FeedFetcherCache getFeedInfoCache()
           
 IProgressMonitor getProgressMonitor()
           Gets the IProgressMonitor used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation.
private  SyndFeed getSyndFeedFromStream(InputStream inputStream, URLConnection connection)
           
protected  void resetFeedInfo(URL orignalUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection)
           
protected  void retrieveAndCacheFeed(URL feedUrl, SyndFeedInfo syndFeedInfo, HttpURLConnection connection)
           
 SyndFeed retrieveFeed(URL feedUrl)
          Retrieve a feed over HTTP
 void setFeedInfoCache(FeedFetcherCache cache)
           
 void setProgressMonitor(IProgressMonitor monitor)
           Sets the IProgressMonitor to be used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation.
protected  void setRequestHeaders(URLConnection connection, SyndFeedInfo syndFeedInfo)
          Set appropriate HTTP headers, including conditional get and gzip encoding headers
 
Methods inherited from class com.sun.syndication.fetcher.impl.AbstractFeedFetcher
addFetcherEventListener, combineFeeds, fireEvent, fireEvent, fireEvent, fireEvent, getUserAgent, handleErrorCodes, isUsingDeltaEncoding, removeFetcherEventListener, setUserAgent, setUsingDeltaEncoding, throw4XXError, throwAuthenticationError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POLL_EVENT

static final int POLL_EVENT
See Also:
Constant Field Values

RETRIEVE_EVENT

static final int RETRIEVE_EVENT
See Also:
Constant Field Values

UNCHANGED_EVENT

static final int UNCHANGED_EVENT
See Also:
Constant Field Values

feedInfoCache

private FeedFetcherCache feedInfoCache

monitor

private IProgressMonitor monitor
The IProgressMonitor to report the progress of a newsfeed retrieval operation to. Added by Sebastian Machhausen (Sebastian.Machhausen@gmail.com)

Constructor Detail

HttpURLFeedFetcher

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


HttpURLFeedFetcher

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

Parameters:
feedCache - - an instance of the FeedFetcherCache interface

HttpURLFeedFetcher

public HttpURLFeedFetcher(FeedFetcherCache feedCache,
                          IProgressMonitor monitor)

Constructor to enable HttpURLFeedFetcher to cache feeds and to report the progress of a newsfeed retrieval operation to the specified IProgressMonitor.

Parameters:
feedCache - an instance of the FeedFetcherCache interface
monitor - the IProgressMonitor used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation
Method Detail

retrieveFeed

public SyndFeed retrieveFeed(URL feedUrl)
                      throws IllegalArgumentException,
                             IOException,
                             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
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,
                                    FeedException,
                                    FetcherException,
                                    IOException
Throws:
IllegalArgumentException
FeedException
FetcherException
IOException

resetFeedInfo

protected void resetFeedInfo(URL orignalUrl,
                             SyndFeedInfo syndFeedInfo,
                             HttpURLConnection connection)
                      throws IllegalArgumentException,
                             IOException,
                             FeedException
Throws:
IllegalArgumentException
IOException
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

getSyndFeedFromStream

private SyndFeed getSyndFeedFromStream(InputStream inputStream,
                                       URLConnection connection)
                                throws IOException,
                                       IllegalArgumentException,
                                       FeedException
Throws:
IOException
IllegalArgumentException
FeedException

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)

setProgressMonitor

public void setProgressMonitor(IProgressMonitor monitor)

Sets the IProgressMonitor to be used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation.

Parameters:
monitor - the IProgressMonitor to be used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation

getProgressMonitor

public IProgressMonitor getProgressMonitor()

Gets the IProgressMonitor used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation.

Returns:
the IProgressMonitor used by this HttpURLFeedFetcher to report the progress of a newsfeed retrieval operation