public class HTTPClientSource extends org.apache.avalon.framework.logger.AbstractLogEnabled implements ModifiableSource, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.parameters.Parameterizable
| Modifier and Type | Class and Description |
|---|---|
private class |
HTTPClientSource.WrappedFileOutputStream
Internal class which extends
FileOutputStream to
automatically upload the data written to it, upon a HTTPClientSource.WrappedFileOutputStream.close()
operation. |
| Modifier and Type | Field and Description |
|---|---|
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
|
private long |
m_cachedLastModificationDate
Cached last modification date.
|
private SourceValidity |
m_cachedValidity
Stored
SourceValidity object. |
private org.apache.commons.httpclient.HttpClient |
m_client
The
HttpClient object. |
private long |
m_contentLength
The content length of the resource on the server.
|
private boolean |
m_dataValid
Whether the data held within this instance is currently accurate.
|
private boolean |
m_exists
Whether the resource exists on the server.
|
private org.apache.commons.httpclient.HttpState |
m_httpState
Optional http state passed from SourceFactory
|
private long |
m_lastModified
The last modified date of the resource on the server.
|
private java.lang.String |
m_mimeType
The mime type of the resource on the server.
|
private java.util.Map |
m_parameters
Contextual parameters passed via the
SourceFactory. |
private java.lang.String |
m_proxyHost
Proxy host if set via configuration.
|
private int |
m_proxyPort
Proxy port if set via configuration.
|
private java.lang.String |
m_uri
The URI being accessed.
|
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 and Description |
|---|
HTTPClientSource(java.lang.String uri,
java.util.Map parameters,
org.apache.commons.httpclient.HttpState httpState)
Constructor, creates a new
HTTPClientSource instance. |
| Modifier and Type | Method and Description |
|---|---|
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(). |
private org.apache.commons.httpclient.methods.DeleteMethod |
createDeleteMethod(java.lang.String uri)
Factory method to create a
DeleteMethod object. |
private org.apache.commons.httpclient.methods.GetMethod |
createGetMethod(java.lang.String uri)
Factory method to create a
GetMethod object. |
private org.apache.commons.httpclient.methods.HeadMethod |
createHeadMethod(java.lang.String uri)
Factory method to create a
HeadMethod object. |
private org.apache.commons.httpclient.methods.PostMethod |
createPostMethod(java.lang.String uri,
SourceParameters params)
Factory method to create a new
PostMethod with the given
SourceParameters object. |
private org.apache.commons.httpclient.methods.PutMethod |
createPutMethod(java.lang.String uri,
java.io.File uploadFile)
Factory method to create a
PutMethod object. |
void |
delete()
Deletes the referenced resource.
|
private boolean |
deleteSuccessful(int response)
According to RFC2616 (HTTP 1.1) valid responses for a HTTP DELETE
are 200 (OK), 202 (Accepted) and 204 (No Content).
|
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.
|
private java.lang.String |
findMethodType()
Method to discover what kind of request is being made from the
parameters map passed in to this Source's constructor.
|
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.
|
private org.apache.commons.httpclient.HttpMethod |
getMethod()
Helper method to create the required
HttpMethod object
based on parameters passed to this HTTPClientSource object. |
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(org.apache.avalon.framework.parameters.Parameters params)
Parameterizes this
HTTPClientSource instance. |
private void |
recycle()
Recycles this
HTTPClientSource object so that it may be reused
to refresh it's content. |
void |
refresh()
Refreshes this
Source object. |
private void |
updateContentLength(org.apache.commons.httpclient.HttpMethod method)
Method to update the content length of a resource after
executing a particular
HttpMethod. |
private void |
updateData()
Method to make response data available if possible without
actually making an actual request (ie.
|
private void |
updateExists(org.apache.commons.httpclient.HttpMethod method)
Method to update whether a referenced resource exists, after
executing a particular
HttpMethod. |
private void |
updateLastModified(org.apache.commons.httpclient.HttpMethod method)
Method to update the last modified date of a resource after
executing a particular
HttpMethod. |
private void |
updateMimeType(org.apache.commons.httpclient.HttpMethod method)
Method to update the mime type of a resource after
executing a particular
HttpMethod. |
public static final java.lang.String POST
public static final java.lang.String GET
public static final java.lang.String PROXY_HOST
public static final java.lang.String PROXY_PORT
public static final java.lang.String CONTENT_TYPE
public static final java.lang.String CONTENT_LENGTH
public static final java.lang.String LAST_MODIFIED
private final java.lang.String m_uri
private final java.util.Map m_parameters
SourceFactory.private final org.apache.commons.httpclient.HttpState m_httpState
private org.apache.commons.httpclient.HttpClient m_client
HttpClient object.private int m_proxyPort
private java.lang.String m_proxyHost
private boolean m_dataValid
private boolean m_exists
private java.lang.String m_mimeType
private long m_contentLength
private long m_lastModified
private SourceValidity m_cachedValidity
SourceValidity object.private long m_cachedLastModificationDate
public HTTPClientSource(java.lang.String uri,
java.util.Map parameters,
org.apache.commons.httpclient.HttpState httpState)
throws java.lang.Exception
HTTPClientSource instance.uri - URIparameters - contextual parameters passed to this instancejava.lang.Exception - if an error occurspublic void parameterize(org.apache.avalon.framework.parameters.Parameters params)
throws org.apache.avalon.framework.parameters.ParameterException
HTTPClientSource instance.parameterize in interface org.apache.avalon.framework.parameters.Parameterizableparams - a Parameters instance.org.apache.avalon.framework.parameters.ParameterException - if an error occurspublic void initialize()
throws java.lang.Exception
HTTPClientSource instance.initialize in interface org.apache.avalon.framework.activity.Initializablejava.lang.Exception - if an error occursprivate java.lang.String findMethodType()
private org.apache.commons.httpclient.HttpMethod getMethod()
HttpMethod object
based on parameters passed to this HTTPClientSource object.HttpMethod object.private org.apache.commons.httpclient.methods.PostMethod createPostMethod(java.lang.String uri,
SourceParameters params)
PostMethod with the given
SourceParameters object.uri - URIparams - SourceParametersPostMethod instanceprivate org.apache.commons.httpclient.methods.GetMethod createGetMethod(java.lang.String uri)
GetMethod object.uri - URIGetMethod instanceprivate org.apache.commons.httpclient.methods.HeadMethod createHeadMethod(java.lang.String uri)
HeadMethod object.uri - URIHeadMethod instanceprivate org.apache.commons.httpclient.methods.PutMethod createPutMethod(java.lang.String uri,
java.io.File uploadFile)
throws java.io.IOException
PutMethod object.uri - URI to upload uploadFile touploadFile - File to be uploadedPutMethod instancejava.io.IOException - if an error occursprivate org.apache.commons.httpclient.methods.DeleteMethod createDeleteMethod(java.lang.String uri)
DeleteMethod object.uri - URI to deleteDeleteMethod instance.private void updateData()
protected int executeMethod(org.apache.commons.httpclient.HttpMethod method)
throws java.io.IOException
HttpMethod and updates internal
data storage.method - HttpMethod to executejava.io.IOException - if an error occursprivate void updateExists(org.apache.commons.httpclient.HttpMethod method)
HttpMethod.
REVISIT: exists() would be better called canRead() or similar, as a resource can exist but not be readable.
method - HttpMethod executed.public boolean exists()
public java.io.InputStream getInputStream()
throws java.io.IOException,
SourceNotFoundException
InputStream to read the response
from the server.getInputStream in interface SourceInputStream containing data sent from the server.java.io.IOException - if some I/O problem occurs.SourceNotFoundException - if the source doesn't exist.public java.lang.String getURI()
Source object references.public java.lang.String getScheme()
public SourceValidity getValidity()
SourceValidity object.getValidity in interface SourceSourceValidity object, or
null if this is not possible.public void refresh()
Source object.private void updateMimeType(org.apache.commons.httpclient.HttpMethod method)
HttpMethod.method - HttpMethod executedpublic java.lang.String getMimeType()
getMimeType in interface Sourceprivate void updateContentLength(org.apache.commons.httpclient.HttpMethod method)
HttpMethod.method - HttpMethod executedpublic long getContentLength()
getContentLength in interface Sourceprivate void updateLastModified(org.apache.commons.httpclient.HttpMethod method)
HttpMethod.method - HttpMethod executedpublic long getLastModified()
getLastModified in interface Source0 if unknown.private void recycle()
HTTPClientSource object so that it may be reused
to refresh it's content.public java.io.OutputStream getOutputStream()
throws java.io.IOException
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.getOutputStream in interface ModifiableSourceOutputStream instancejava.io.IOException - if an error occurspublic void delete()
throws SourceException
delete in interface ModifiableSourceSourceException - if an error occursprivate boolean deleteSuccessful(int response)
response - response code from the HTTP PUTpublic boolean canCancel(java.io.OutputStream stream)
getOutputStream()) can
be cancelledcanCancel in interface ModifiableSourcepublic void cancel(java.io.OutputStream stream)
throws java.io.IOException
OutputStream returned by
getOutputStream().
After calling this method, the supplied OutputStream
should no longer be used.cancel in interface ModifiableSourcejava.io.IOException