org.gcube.contentmanagement.baselayer.networkFileTransfer
Class CommonsHTTPClientPseudeContentManager

java.lang.Object
  extended by org.gcube.contentmanagement.baselayer.networkFileTransfer.CommonsHTTPClientPseudeContentManager
All Implemented Interfaces:
InstantiableManager, RawFileContentManager

public class CommonsHTTPClientPseudeContentManager
extends java.lang.Object
implements RawFileContentManager, InstantiableManager

This class provides the basic functionallity to retrieve files via HTTP(S). It does not provide a full-fledged content manager e.g. with the abitility to store or delete remote files. The implementation is backed by the widely used Apache Jakarta Commons HTTPClient, that does avoid most of the problems of HTTP implementation provided by Java directly, e.g. concurrent use in multiple threads with different authentications.


Field Summary
static java.lang.String HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_LENGTH
          Constant name of the response header defining the length of the content according to RFC 2616, Section 14.13 commons-httpclient will evaluate this name case insensitive
static java.lang.String HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_TYPE
          Constant name of the response header defining the MIME type of the content according to RFC 2616, Section 14.17 commons-httpclient will evaluate this name case insensitive
static java.lang.String HTTP_RESPONSE_HEADER_TRANSFER_ENCODING
          Constant name of the response header defining the the transfer encoding according to RFC 2616, Section 14.41 This field is important in the context of the content length, since RFC 2616, Section 4.4.3 defines that in case both are submitted, content length must be be ignored.
 
Fields inherited from interface org.gcube.contentmanagement.baselayer.InstantiableManager
MANAGER_INSTANTIATION_METHOD_NAME
 
Constructor Summary
CommonsHTTPClientPseudeContentManager(java.lang.String managedURL)
          Constructs a new manager for a particular URL
 
Method Summary
 boolean deleteBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Removes the binary content from storage (Unsupported Operation)
 boolean existsBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Checks whether there is content at this location
 BaseLayerStream getBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Opens the content for reading and passes the input stream to the caller
 java.lang.String getDataProvider()
           
static java.lang.String getDataProviderPrefix()
          Returns the prefix that is used by the manager for identying responsibility for a data source
static HTTPPseudoContentManager getManagerInstance(java.lang.String[] params, java.lang.String managerName)
           
 java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
           
 boolean handles(java.lang.String dataprovider)
          Checks whether the RawFileContentManager can handle this data.
 RawContentLocation makePermanentLocation(RawContentLocation currentLocation, BasicStorageHints hints)
          Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.
 RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID, BaseLayerStream binaryFileContent, BasicStorageHints hints)
          Saves the passed binary content in the managed resource.
 boolean supportsAppending()
          Tells whether this content manager supports appending content in addition to overwriting the content when storing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_LENGTH

public static final java.lang.String HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_LENGTH
Constant name of the response header defining the length of the content according to RFC 2616, Section 14.13 commons-httpclient will evaluate this name case insensitive

See Also:
Constant Field Values

HTTP_RESPONSE_HEADER_TRANSFER_ENCODING

public static final java.lang.String HTTP_RESPONSE_HEADER_TRANSFER_ENCODING
Constant name of the response header defining the the transfer encoding according to RFC 2616, Section 14.41 This field is important in the context of the content length, since RFC 2616, Section 4.4.3 defines that in case both are submitted, content length must be be ignored. commons-httpclient will evaluate this name case insensitive

See Also:
Constant Field Values

HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_TYPE

public static final java.lang.String HTTP_RESPONSE_HEADER_ELEMENT_CONTENT_TYPE
Constant name of the response header defining the MIME type of the content according to RFC 2616, Section 14.17 commons-httpclient will evaluate this name case insensitive

See Also:
Constant Field Values
Constructor Detail

CommonsHTTPClientPseudeContentManager

public CommonsHTTPClientPseudeContentManager(java.lang.String managedURL)
Constructs a new manager for a particular URL

Parameters:
managedURL - the URL that should be mamaged
Method Detail

getDataProviderPrefix

public static java.lang.String getDataProviderPrefix()
Returns the prefix that is used by the manager for identying responsibility for a data source

Returns:
the prefix

saveBinaryContent

public RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID,
                                            BaseLayerStream binaryFileContent,
                                            BasicStorageHints hints)
                                     throws BaseLayerException
Saves the passed binary content in the managed resource. If the resource did previously exist, it is updated and the old content is lost. If the resource did not exist, it will be newly created.

Specified by:
saveBinaryContent in interface RawFileContentManager
Parameters:
binaryFileContent - the content to store
uniqueStorageID - a unique ID to as a hint where to store the content
hints - the hints that should be used
Returns:
the RawContentLocation where the content is now accessible
Throws:
BaseLayerException - in case of failure of underlying storage system

getBinaryContent

public BaseLayerStream getBinaryContent(RawContentLocation location,
                                        BasicStorageHints hints)
                                 throws BaseLayerException
Opens the content for reading and passes the input stream to the caller

Specified by:
getBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
the content stored in the managed resource
Throws:
BaseLayerException - in case of failure of underlying storage system

deleteBinaryContent

public boolean deleteBinaryContent(RawContentLocation location,
                                   BasicStorageHints hints)
                            throws BaseLayerException
Removes the binary content from storage (Unsupported Operation)

Specified by:
deleteBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
true, if content has been deleted successfully; false if the content did not exist and therefore the operation had no effect.
Throws:
BaseLayerException - in case of failure of underlying storage system

existsBinaryContent

public boolean existsBinaryContent(RawContentLocation location,
                                   BasicStorageHints hints)
                            throws BaseLayerException
Checks whether there is content at this location

Specified by:
existsBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
Returns:
true, if there is content at this location; false otherwise
Throws:
BaseLayerException - in case of failure of underlying storage system

handles

public boolean handles(java.lang.String dataprovider)
Checks whether the RawFileContentManager can handle this data.

This means that it can handle the requests for content stored at this dataprovider. In the ideal case, this also checks if it has all required access rights. But this cannot be enforced as a strong requirement before the actual calls take place.

Specified by:
handles in interface RawFileContentManager
Parameters:
dataprovider -
Returns:
true, if it can do, false otherwise

getDataProvider

public java.lang.String getDataProvider()
Specified by:
getDataProvider in interface RawFileContentManager
Returns:
a string identifying this data source

supportsAppending

public boolean supportsAppending()
Tells whether this content manager supports appending content in addition to overwriting the content when storing

Specified by:
supportsAppending in interface RawFileContentManager
Returns:
true, if appending is supported
See Also:
BasicStorageHints#HINT_NAME_APPEND_CONTENT

makePermanentLocation

public RawContentLocation makePermanentLocation(RawContentLocation currentLocation,
                                                BasicStorageHints hints)
                                         throws ValueNotValidException
Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.

This is of particular interest for username / password combinations.

Specified by:
makePermanentLocation in interface RawFileContentManager
Parameters:
currentLocation - the location, where content can be accessed currently (may require information from the hints)
hints - hints, that may be needed to request the content
Returns:
a location which can be accessed without providing again the hints. This may not always be possible.
Throws:
ValueNotValidException - If some hints was not defined correctly or there is no possibility to include that in the permanent location.

getManagerInstance

public static HTTPPseudoContentManager getManagerInstance(java.lang.String[] params,
                                                          java.lang.String managerName)
                                                   throws BaseLayerException
Throws:
BaseLayerException

getUniqueStorageLocationIDFor

public java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
Specified by:
getUniqueStorageLocationIDFor in interface RawFileContentManager