org.apache.commons.feedparser.network
Class URLResourceRequest

java.lang.Object
  extended by org.apache.commons.feedparser.network.BaseResourceRequest
      extended by org.apache.commons.feedparser.network.URLResourceRequest
All Implemented Interfaces:
ResourceRequest

public class URLResourceRequest
extends BaseResourceRequest
implements ResourceRequest

ResourceRequest implementation that uses java.net.URL as the backend. Differences from other ResourceRequests. setRequestMethod() - Allows us to change the request type (HEAD, etc). getContentLength() - Returns the length/size of the content represented by this resource. Can be used by clients with setRequestMethod( "HEAD" ) to find the size of a remote resource without doing a full fetch.

Version:
$Id: URLResourceRequest.java 561366 2007-07-31 15:58:29Z rahul $
Author:
Kevin A. Burton

Field Summary
static String ACCEPT_ENCODING_HEADER
           
static boolean ENABLE_HTTP_DELTA_FEED_IM
          Enable RFC 3228 HTTP Delta for feeds.
static String GZIP_ENCODING
           
static String IF_NONE_MATCH_HEADER
           
static int MAX_CONTENT_LENGTH
           
static String REFERER
          Not used anymore.
static String USER_AGENT
           
static String USER_AGENT_HEADER
           
static String USER_AGENT_MOZILLA
           
 
Fields inherited from class org.apache.commons.feedparser.network.BaseResourceRequest
FOLLOW_REDIRECTS
 
Constructor Summary
URLResourceRequest()
           
 
Method Summary
 InputStream _getInputStream()
           
 int getContentLength()
          Return the conent length of this request or -1 if not known.
 String getHeaderField(String name)
          Get a given response header.
 InputStream getInputStream()
          Get an input stream for this content.
 String getResourceFromRedirect()
          This method used Reflection to pull out the redirected URL in java.net.URL.
 void init()
          Perform all initialization and connection to the remote server.
 void initConnection()
          Init the actual connection.
 void setRequestMethod(String method)
          Set the RequestMethod of this URLConnection.
 
Methods inherited from class org.apache.commons.feedparser.network.BaseResourceRequest
fireDataEvent, fireDataEvent, fireInit, fireOnClosed, getEtag, getFollowRedirects, getIfModifiedSince, getInputStreamAsByteArray, getInputStreamAsString, getLocalInputStream, getLocalInputStreamAsByteArray, getRequestHeaderField, getRequestHeaderFields, getResource, getResponseCode, setEtag, setEventListener, setFollowRedirects, setIfModifiedSince, setLocalCache, setRequestHeaderField, setResource, setResponseCode, toOutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.feedparser.network.ResourceRequest
getEtag, getFollowRedirects, getIfModifiedSince, getInputStreamAsByteArray, getInputStreamAsString, getLocalInputStream, getLocalInputStreamAsByteArray, getRequestHeaderField, getRequestHeaderFields, getResource, getResponseCode, setEtag, setEventListener, setFollowRedirects, setIfModifiedSince, setLocalCache, setRequestHeaderField, setResource, setResponseCode, toOutputStream
 

Field Detail

ACCEPT_ENCODING_HEADER

public static final String ACCEPT_ENCODING_HEADER
See Also:
Constant Field Values

IF_NONE_MATCH_HEADER

public static final String IF_NONE_MATCH_HEADER
See Also:
Constant Field Values

GZIP_ENCODING

public static final String GZIP_ENCODING
See Also:
Constant Field Values

USER_AGENT_HEADER

public static final String USER_AGENT_HEADER
See Also:
Constant Field Values

ENABLE_HTTP_DELTA_FEED_IM

public static boolean ENABLE_HTTP_DELTA_FEED_IM
Enable RFC 3228 HTTP Delta for feeds. http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html http://bobwyman.pubsub.com/main/2004/09/implementations.html


USER_AGENT

public static String USER_AGENT

USER_AGENT_MOZILLA

public static String USER_AGENT_MOZILLA

REFERER

public static final String REFERER
Not used anymore. Provided for historical reasons.

See Also:
Constant Field Values

MAX_CONTENT_LENGTH

public static final int MAX_CONTENT_LENGTH
See Also:
Constant Field Values
Constructor Detail

URLResourceRequest

public URLResourceRequest()
Method Detail

init

public void init()
          throws IOException
Description copied from interface: ResourceRequest
Perform all initialization and connection to the remote server. This should always be called BEFORE network getInputStream() if you want to perform other operations first. When using a HEAD request this must be used and not getInputStream()

Specified by:
init in interface ResourceRequest
Throws:
IOException

initConnection

public void initConnection()
                    throws NetworkException
Init the actual connection. Should be called AFTER init() but before getInputStream() so that we can set any runtime params requestMethod, etc. If getInputStream() is called without an initConnection() we do this automatically. initConnection() might not want to be called when doing a HEAD request.

Throws:
NetworkException

getResourceFromRedirect

public String getResourceFromRedirect()
This method used Reflection to pull out the redirected URL in java.net.URL. Internally sun.net.www.protocol.http.HttpURLConnection stores a reference to sun.net.www.http.HttpClient which then in turn does all the redirection and stores the redirect java.net.URL. We just use reflection to FETCH this URL and then call toString to get the correct value. Java needs the concept of readonly private variables.

Specified by:
getResourceFromRedirect in interface ResourceRequest
Overrides:
getResourceFromRedirect in class BaseResourceRequest

getInputStream

public InputStream getInputStream()
                           throws NetworkException
Description copied from interface: ResourceRequest
Get an input stream for this content.

Specified by:
getInputStream in interface ResourceRequest
Throws:
NetworkException

_getInputStream

public InputStream _getInputStream()
                            throws IOException
Throws:
IOException

setRequestMethod

public void setRequestMethod(String method)
                      throws NetworkException
Set the RequestMethod of this URLConnection.

Specified by:
setRequestMethod in interface ResourceRequest
Overrides:
setRequestMethod in class BaseResourceRequest
Throws:
NetworkException

getContentLength

public int getContentLength()
                     throws IOException
Description copied from interface: ResourceRequest
Return the conent length of this request or -1 if not known.

Specified by:
getContentLength in interface ResourceRequest
Overrides:
getContentLength in class BaseResourceRequest
Throws:
IOException

getHeaderField

public String getHeaderField(String name)
Description copied from interface: ResourceRequest
Get a given response header.

Specified by:
getHeaderField in interface ResourceRequest
Overrides:
getHeaderField in class BaseResourceRequest


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.