|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.excalibur.source.impl.HTTPClientSource
public class HTTPClientSource
HTTP URL Source object, based on the Jakarta Commons HttpClient project.
Nested Class Summary | |
---|---|
private class |
HTTPClientSource.WrappedFileOutputStream
Internal class which extends FileOutputStream to
automatically upload the data written to it, upon a HTTPClientSource.WrappedFileOutputStream.close()
operation. |
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 |
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 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 HTTPClientSource.WrappedFileOutputStream 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 HTTPClientSource.WrappedFileOutputStream 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 . |
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 |
---|
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
Constructor Detail |
---|
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 instance
java.lang.Exception
- if an error occursMethod Detail |
---|
public 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.Parameterizable
params
- 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.Initializable
java.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
- SourceParameters
PostMethod
instanceprivate org.apache.commons.httpclient.methods.GetMethod createGetMethod(java.lang.String uri)
GetMethod
object.
uri
- URI
GetMethod
instanceprivate org.apache.commons.httpclient.methods.HeadMethod createHeadMethod(java.lang.String uri)
HeadMethod
object.
uri
- URI
HeadMethod
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 uploaded
PutMethod
instance
java.io.IOException
- if an error occursprivate org.apache.commons.httpclient.methods.DeleteMethod createDeleteMethod(java.lang.String uri)
DeleteMethod
object.
uri
- URI to delete
DeleteMethod
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 execute
java.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()
exists
in interface Source
true
if the resource pointed to by the
URI during construction exists, false
otherwise.public java.io.InputStream getInputStream() throws java.io.IOException, SourceNotFoundException
InputStream
to read the response
from the server.
getInputStream
in interface Source
InputStream
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.
getURI
in interface Source
String
object references.public java.lang.String getScheme()
getScheme
in interface Source
public SourceValidity getValidity()
SourceValidity
object.
getValidity
in interface Source
SourceValidity
object, or
null
if this is not possible.public void refresh()
Source
object.
refresh
in interface Source
private void updateMimeType(org.apache.commons.httpclient.HttpMethod method)
HttpMethod
.
method
- HttpMethod
executedpublic java.lang.String getMimeType()
getMimeType
in interface Source
private void updateContentLength(org.apache.commons.httpclient.HttpMethod method)
HttpMethod
.
method
- HttpMethod
executedpublic long getContentLength()
getContentLength
in interface Source
private void updateLastModified(org.apache.commons.httpclient.HttpMethod method)
HttpMethod
.
method
- HttpMethod
executedpublic long getLastModified()
getLastModified
in interface Source
0
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
HTTPClientSource.WrappedFileOutputStream
to write to. The HTTPClientSource.WrappedFileOutputStream
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 ModifiableSource
HTTPClientSource.WrappedFileOutputStream
instance
java.io.IOException
- if an error occurspublic void delete() throws SourceException
delete
in interface ModifiableSource
SourceException
- if an error occursprivate boolean deleteSuccessful(int response)
response
- response code from the HTTP PUT
public boolean canCancel(java.io.OutputStream stream)
getOutputStream()
) can
be cancelled
canCancel
in interface ModifiableSource
public void cancel(java.io.OutputStream stream) throws java.io.IOException
HTTPClientSource.WrappedFileOutputStream
returned by
getOutputStream()
.
After calling this method, the supplied HTTPClientSource.WrappedFileOutputStream
should no longer be used.
cancel
in interface ModifiableSource
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |