org.apache.excalibur.source.impl
Class HTTPClientSource

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.source.impl.HTTPClientSource
All Implemented Interfaces:
Initializable, LogEnabled, ModifiableSource, Parameterizable, Source

public class HTTPClientSource
extends AbstractLogEnabled
implements ModifiableSource, Initializable, Parameterizable

HTTP URL Source object, based on the Jakarta Commons HttpClient project.

Version:
CVS $Id: HTTPClientSource.java,v 1.4 2004/02/28 11:47:24 cziegeler Exp $
Author:
Avalon Development Team

Field Summary
static java.lang.String CONTENT_LENGTH
          Constant used when obtaining the Content-Length from HTTP Headers
static java.lang.String CONTENT_TYPE
          Constant used when obtaining the Content-Type from HTTP Headers
static java.lang.String GET
          Constant used for identifying GET requests.
static java.lang.String LAST_MODIFIED
          Constant used when obtaining the Last-Modified date from HTTP Headers
static java.lang.String POST
          Constant used for identifying POST requests.
static java.lang.String PROXY_HOST
          Constant used for configuring the proxy hostname.
static java.lang.String PROXY_PORT
          Constant used for configuring the proxy port number.
 
Constructor Summary
HTTPClientSource(java.lang.String uri, java.util.Map parameters, org.apache.commons.httpclient.HttpState httpState)
          Constructor, creates a new HTTPClientSource instance.
 
Method Summary
 boolean canCancel(java.io.OutputStream stream)
          Method to determine whether writing to the supplied OutputStream (which must be that returned from getOutputStream()) can be cancelled
 void cancel(java.io.OutputStream stream)
          Cancels any data sent to the OutputStream returned by getOutputStream().
 void delete()
          Deletes the referenced resource.
protected  int executeMethod(org.apache.commons.httpclient.HttpMethod method)
          Executes a particular HttpMethod and updates internal data storage.
 boolean exists()
          Method to ascertain whether the given resource actually exists.
 long getContentLength()
          Obtain the content length of the referenced resource.
 java.io.InputStream getInputStream()
          Method to obtain an InputStream to read the response from the server.
 long getLastModified()
          Get the last modification date of this source.
 java.lang.String getMimeType()
          Obtain the mime-type for the referenced resource.
 java.io.OutputStream getOutputStream()
          Obtain an OutputStream to write to.
 java.lang.String getScheme()
          Return the URI scheme identifier, ie.
 java.lang.String getURI()
          Obtain the absolute URI this Source object references.
 SourceValidity getValidity()
          Obtain a SourceValidity object.
 void initialize()
          Initializes this HTTPClientSource instance.
 void parameterize(Parameters params)
          Parameterizes this HTTPClientSource instance.
 void refresh()
          Refreshes this Source object.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POST

public static final java.lang.String POST
Constant used for identifying POST requests.

See Also:
Constant Field Values

GET

public static final java.lang.String GET
Constant used for identifying GET requests.

See Also:
Constant Field Values

PROXY_HOST

public static final java.lang.String PROXY_HOST
Constant used for configuring the proxy hostname.

See Also:
Constant Field Values

PROXY_PORT

public static final java.lang.String PROXY_PORT
Constant used for configuring the proxy port number.

See Also:
Constant Field Values

CONTENT_TYPE

public static final java.lang.String CONTENT_TYPE
Constant used when obtaining the Content-Type from HTTP Headers

See Also:
Constant Field Values

CONTENT_LENGTH

public static final java.lang.String CONTENT_LENGTH
Constant used when obtaining the Content-Length from HTTP Headers

See Also:
Constant Field Values

LAST_MODIFIED

public static final java.lang.String LAST_MODIFIED
Constant used when obtaining the Last-Modified date from HTTP Headers

See Also:
Constant Field Values
Constructor Detail

HTTPClientSource

public HTTPClientSource(java.lang.String uri,
                        java.util.Map parameters,
                        org.apache.commons.httpclient.HttpState httpState)
                 throws java.lang.Exception
Constructor, creates a new HTTPClientSource instance.

Parameters:
uri - URI
parameters - contextual parameters passed to this instance
Throws:
java.lang.Exception - if an error occurs
Method Detail

parameterize

public void parameterize(Parameters params)
                  throws ParameterException
Parameterizes this HTTPClientSource instance.

Specified by:
parameterize in interface Parameterizable
Parameters:
params - a Parameters instance.
Throws:
ParameterException - if an error occurs

initialize

public void initialize()
                throws java.lang.Exception
Initializes this HTTPClientSource instance.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - if an error occurs

executeMethod

protected int executeMethod(org.apache.commons.httpclient.HttpMethod method)
                     throws java.io.IOException
Executes a particular HttpMethod and updates internal data storage.

Parameters:
method - HttpMethod to execute
Returns:
response code from server
Throws:
java.io.IOException - if an error occurs

exists

public boolean exists()
Method to ascertain whether the given resource actually exists.

Specified by:
exists in interface Source
Returns:
true if the resource pointed to by the URI during construction exists, false otherwise.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException,
                                          SourceNotFoundException
Method to obtain an InputStream to read the response from the server.

Specified by:
getInputStream in interface Source
Returns:
InputStream containing data sent from the server.
Throws:
java.io.IOException - if some I/O problem occurs.
SourceNotFoundException - if the source doesn't exist.

getURI

public java.lang.String getURI()
Obtain the absolute URI this Source object references.

Specified by:
getURI in interface Source
Returns:
the absolute URI this String object references.

getScheme

public java.lang.String getScheme()
Return the URI scheme identifier, ie. the part preceding the fist ':' in the URI (see RFC 2396).

Specified by:
getScheme in interface Source
Returns:
the URI scheme identifier

getValidity

public SourceValidity getValidity()
Obtain a SourceValidity object.

Specified by:
getValidity in interface Source
Returns:
a SourceValidity object, or null if this is not possible.

refresh

public void refresh()
Refreshes this Source object.

Specified by:
refresh in interface Source

getMimeType

public java.lang.String getMimeType()
Obtain the mime-type for the referenced resource.

Specified by:
getMimeType in interface Source
Returns:
mime-type for the referenced resource.

getContentLength

public long getContentLength()
Obtain the content length of the referenced resource.

Specified by:
getContentLength in interface Source
Returns:
content length of the referenced resource, or -1 if unknown/uncalculatable

getLastModified

public long getLastModified()
Get the last modification date of this source. This date is measured in milliseconds since the Epoch (00:00:00 GMT, January 1, 1970).

Specified by:
getLastModified in interface Source
Returns:
the last modification date or 0 if unknown.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Obtain an OutputStream to write to. The OutputStream returned actually references a temporary local file, which will be written to the server upon closing. The returned stream must be closed or cancelled by the calling code.

Specified by:
getOutputStream in interface ModifiableSource
Returns:
an OutputStream instance
Throws:
java.io.IOException - if an error occurs

delete

public void delete()
            throws SourceException
Deletes the referenced resource.

Specified by:
delete in interface ModifiableSource
Throws:
SourceException - if an error occurs

canCancel

public boolean canCancel(java.io.OutputStream stream)
Method to determine whether writing to the supplied OutputStream (which must be that returned from getOutputStream()) can be cancelled

Specified by:
canCancel in interface ModifiableSource
Returns:
true if writing to the stream can be cancelled, false otherwise

cancel

public void cancel(java.io.OutputStream stream)
            throws java.io.IOException
Cancels any data sent to the OutputStream returned by getOutputStream(). After calling this method, the supplied OutputStream should no longer be used.

Specified by:
cancel in interface ModifiableSource
Throws:
java.io.IOException


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.