com.sun.syndication.fetcher.impl
Class HttpURLFeedFetcher

java.lang.Object
  |
  +--com.sun.syndication.fetcher.impl.AbstractFeedFetcher
        |
        +--com.sun.syndication.fetcher.impl.HttpURLFeedFetcher
All Implemented Interfaces:
FeedFetcherI

public class HttpURLFeedFetcher
extends AbstractFeedFetcher

Class to retrieve syndication files via HTTP.

If passed a FeedFetcherCacheI 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
	FeedFetcherCacheI 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
	SyndFeedI 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

Field Summary
 
Fields inherited from interface com.sun.syndication.fetcher.FeedFetcherI
DEFAULT_USER_AGENT
 
Constructor Summary
HttpURLFeedFetcher()
          Constructor to use HttpURLFeedFetcher without caching of feeds
HttpURLFeedFetcher(com.sun.syndication.fetcher.impl.FeedFetcherCacheI feedCache)
          Constructor to enable HttpURLFeedFetcher to cache feeds
 
Method Summary
 com.sun.syndication.fetcher.impl.FeedFetcherCacheI getFeedInfoCache()
           
protected  void handleErrorCodes(int responseCode)
          Handles HTTP error codes.
protected  void resetFeedInfo(java.net.URL orignalUrl, com.sun.syndication.fetcher.impl.SyndFeedInfo syndFeedInfo, java.net.URLConnection connection)
           
protected  void retrieveAndCacheFeed(java.net.URL feedUrl, com.sun.syndication.fetcher.impl.SyndFeedInfo syndFeedInfo, java.net.URLConnection connection)
           
 com.sun.syndication.feed.synd.SyndFeedI retrieveFeed(java.net.URL feedUrl)
          Retrieve a feed over HTTP
 void setFeedInfoCache(com.sun.syndication.fetcher.impl.FeedFetcherCacheI cache)
           
protected  void setRequestHeaders(java.net.URLConnection connection, com.sun.syndication.fetcher.impl.SyndFeedInfo syndFeedInfo)
          Set appropriate HTTP headers, including conditional get and gzip encoding headers
 
Methods inherited from class com.sun.syndication.fetcher.impl.AbstractFeedFetcher
addFetcherEventListener, fireEvent, getUserAgent, removeFetcherPolledListener, setUserAgent
 
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(com.sun.syndication.fetcher.impl.FeedFetcherCacheI feedCache)
Constructor to enable HttpURLFeedFetcher to cache feeds

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

retrieveFeed

public com.sun.syndication.feed.synd.SyndFeedI retrieveFeed(java.net.URL feedUrl)
                                                     throws java.lang.IllegalArgumentException,
                                                            java.io.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 SyndFeedI object
Throws:
java.lang.IllegalArgumentException - if the URL is null;
java.io.IOException - if a TCP error occurs
com.sun.syndication.io.FeedException - if the feed is not valid
FetcherException - if a HTTP error occurred

handleErrorCodes

protected void handleErrorCodes(int responseCode)
                         throws FetcherException

Handles HTTP error codes.

Parameters:
responseCode - the HTTP response code
Throws:
FetcherException - if response code is in the range 400 to 599 inclusive

retrieveAndCacheFeed

protected void retrieveAndCacheFeed(java.net.URL feedUrl,
                                    com.sun.syndication.fetcher.impl.SyndFeedInfo syndFeedInfo,
                                    java.net.URLConnection connection)
                             throws java.lang.IllegalArgumentException,
                                    com.sun.syndication.io.FeedException,
                                    FetcherException,
                                    java.io.IOException
java.lang.IllegalArgumentException
com.sun.syndication.io.FeedException
FetcherException
java.io.IOException

resetFeedInfo

protected void resetFeedInfo(java.net.URL orignalUrl,
                             com.sun.syndication.fetcher.impl.SyndFeedInfo syndFeedInfo,
                             java.net.URLConnection connection)
                      throws java.lang.IllegalArgumentException,
                             java.io.IOException,
                             com.sun.syndication.io.FeedException
java.lang.IllegalArgumentException
java.io.IOException
com.sun.syndication.io.FeedException

setRequestHeaders

protected void setRequestHeaders(java.net.URLConnection connection,
                                 com.sun.syndication.fetcher.impl.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 com.sun.syndication.fetcher.impl.FeedFetcherCacheI getFeedInfoCache()
Returns:
The FeedFetcherCacheI used by this fetcher (Could be null)

setFeedInfoCache

public void setFeedInfoCache(com.sun.syndication.fetcher.impl.FeedFetcherCacheI cache)
Parameters:
cache - The cache to be used by this fetcher (pass null to stop using a cache)


Copyright © 2004 Sun Microsystems. All Rights Reserved.