org.jets3t.service.impl.rest.httpclient
Class RestS3Service

java.lang.Object
  extended by org.jets3t.service.S3Service
      extended by org.jets3t.service.impl.rest.httpclient.RestS3Service
All Implemented Interfaces:
java.io.Serializable, AWSRequestAuthorizer, SignedUrlHandler

public class RestS3Service
extends S3Service
implements SignedUrlHandler, AWSRequestAuthorizer

REST/HTTP implementation of an S3Service based on the HttpClient library.

This class uses properties obtained through Jets3tProperties. For more information on these properties please refer to JetS3t Configuration

Author:
James Murty
See Also:
Serialized Form

Nested Class Summary
 class RestS3Service.HttpMethodAndByteCount
          Simple container object to store an HttpMethod object representing a request connection, and a count of the byte size of the S3 object associated with the request.
 
Field Summary
protected  org.apache.commons.httpclient.HttpConnectionManager connectionManager
           
protected  org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider
           
protected  org.apache.commons.httpclient.HttpClient httpClient
           
static java.lang.String VERSION
           
static java.lang.String XML_NAMESPACE
           
 
Fields inherited from class org.jets3t.service.S3Service
BUCKET_STATUS__ALREADY_CLAIMED, BUCKET_STATUS__DOES_NOT_EXIST, BUCKET_STATUS__MY_BUCKET, jets3tProperties, timeOffset, VERSION_NO__JETS3T_TOOLKIT
 
Constructor Summary
RestS3Service(AWSCredentials awsCredentials)
          Constructs the service and initialises the properties.
RestS3Service(AWSCredentials awsCredentials, java.lang.String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
          Constructs the service and initialises the properties.
RestS3Service(AWSCredentials awsCredentials, java.lang.String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider, Jets3tProperties jets3tProperties)
          Constructs the service and initialises the properties.
RestS3Service(AWSCredentials awsCredentials, java.lang.String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider, Jets3tProperties jets3tProperties, org.apache.commons.httpclient.HostConfiguration hostConfig)
          Constructs the service and initialises the properties.
 
Method Summary
protected  void addMetadataToHeaders(org.apache.commons.httpclient.HttpMethodBase httpMethod, java.util.Map metadata)
          Adds all valid metadata name and value pairs as HTTP headers to the given HTTP method.
protected  void addRequestHeadersToConnection(org.apache.commons.httpclient.HttpMethodBase httpMethod, java.util.Map requestHeaders)
          Adds the provided request headers to the connection.
protected  java.lang.String addRequestParametersToUrlPath(java.lang.String urlPath, java.util.Map requestParameters)
          Adds all the provided request parameters to a URL in GET request format.
 void authorizeHttpRequest(org.apache.commons.httpclient.HttpMethod httpMethod)
          Authorizes an HTTP request by signing it.
 int checkBucketStatus(java.lang.String bucketName)
          Find out the status of an S3 bucket with the given name.
protected  java.util.Map copyObjectImpl(java.lang.String sourceBucketName, java.lang.String sourceObjectKey, java.lang.String destinationBucketName, java.lang.String destinationObjectKey, AccessControlList acl, java.util.Map destinationMetadata, java.util.Calendar ifModifiedSince, java.util.Calendar ifUnmodifiedSince, java.lang.String[] ifMatchTags, java.lang.String[] ifNoneMatchTags, java.lang.String versionId)
          Copy an object within your S3 account.
protected  S3Bucket createBucketImpl(java.lang.String bucketName, java.lang.String location, AccessControlList acl)
          Creates a bucket.
protected  java.util.Map createObjectImpl(java.lang.String bucketName, java.lang.String objectKey, java.lang.String contentType, org.apache.commons.httpclient.methods.RequestEntity requestEntity, java.util.Map metadata, AccessControlList acl)
           
protected  void deleteBucketImpl(java.lang.String bucketName)
           
protected  void deleteObjectImpl(java.lang.String bucketName, java.lang.String objectKey, java.lang.String versionId, java.lang.String multiFactorSerialNumber, java.lang.String multiFactorAuthCode)
           
 void deleteObjectWithSignedUrl(java.lang.String signedDeleteUrl)
          Deletes an object using a pre-signed DELETE URL generated for that object.
protected  S3Owner getAccountOwnerImpl()
           
protected  AccessControlList getBucketAclImpl(java.lang.String bucketName)
           
protected  java.lang.String getBucketLocationImpl(java.lang.String bucketName)
           
protected  S3BucketLoggingStatus getBucketLoggingStatusImpl(java.lang.String bucketName)
           
protected  S3BucketVersioningStatus getBucketVersioningStatusImpl(java.lang.String bucketName)
           
 org.apache.commons.httpclient.auth.CredentialsProvider getCredentialsProvider()
           
 org.apache.commons.httpclient.HttpClient getHttpClient()
           
 org.apache.commons.httpclient.HttpConnectionManager getHttpConnectionManager()
           
protected  AccessControlList getObjectAclImpl(java.lang.String bucketName, java.lang.String objectKey)
           
protected  AccessControlList getObjectAclImpl(java.lang.String bucketName, java.lang.String objectKey, java.lang.String versionId)
           
 AccessControlList getObjectAclWithSignedUrl(java.lang.String signedAclUrl)
          Gets an object's ACL details using a pre-signed GET URL generated for that object.
protected  S3Object getObjectDetailsImpl(java.lang.String bucketName, java.lang.String objectKey, java.util.Calendar ifModifiedSince, java.util.Calendar ifUnmodifiedSince, java.lang.String[] ifMatchTags, java.lang.String[] ifNoneMatchTags, java.lang.String versionId)
           
 S3Object getObjectDetailsWithSignedUrl(java.lang.String signedHeadUrl)
          Gets an object's details using a pre-signed HEAD URL generated for that object.
protected  S3Object getObjectImpl(java.lang.String bucketName, java.lang.String objectKey, java.util.Calendar ifModifiedSince, java.util.Calendar ifUnmodifiedSince, java.lang.String[] ifMatchTags, java.lang.String[] ifNoneMatchTags, java.lang.Long byteRangeStart, java.lang.Long byteRangeEnd, java.lang.String versionId)
           
 S3Object getObjectWithSignedUrl(java.lang.String signedGetUrl)
          Gets an object using a pre-signed GET URL generated for that object.
protected  HttpClientAndConnectionManager initHttpConnection(org.apache.commons.httpclient.HostConfiguration hostConfig)
          Initialise HttpClient and HttpConnectionManager objects with the configuration settings appropriate for communicating with S3.
 boolean isBucketAccessible(java.lang.String bucketName)
          Indicates whether a bucket exists and is accessible to a service user.
protected  boolean isRequesterPaysBucketImpl(java.lang.String bucketName)
           
protected  boolean isXmlContentType(java.lang.String contentType)
           
protected  S3Bucket[] listAllBucketsImpl()
           
protected  S3ObjectsChunk listObjectsChunkedImpl(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, long maxListingLength, java.lang.String priorLastKey, boolean completeListing)
          Lists objects in a bucket up to the maximum listing length specified.
protected  S3Object[] listObjectsImpl(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, long maxListingLength)
          Lists objects in a bucket.
protected  S3ObjectsChunk listObjectsInternal(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, long maxListingLength, boolean automaticallyMergeChunks, java.lang.String priorLastKey, java.lang.String priorLastVersion)
           
protected  VersionOrDeleteMarkersChunk listVersionedObjectsChunkedImpl(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, long maxListingLength, java.lang.String priorLastKey, java.lang.String priorLastVersion, boolean completeListing)
          Lists version or delete markers in a versioned bucket, up to the maximum listing length specified.
protected  BaseVersionOrDeleteMarker[] listVersionedObjectsImpl(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, java.lang.String keyMarker, java.lang.String versionMarker, long maxListingLength)
           
protected  VersionOrDeleteMarkersChunk listVersionedObjectsInternal(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter, long maxListingLength, boolean automaticallyMergeChunks, java.lang.String nextKeyMarker, java.lang.String nextVersionIdMarker)
           
protected  void performRequest(org.apache.commons.httpclient.HttpMethodBase httpMethod, int[] expectedResponseCodes)
          Performs an HTTP/S request by invoking the provided HttpMethod object.
protected  org.apache.commons.httpclient.HttpMethodBase performRestDelete(java.lang.String bucketName, java.lang.String objectKey, java.util.Map requestParameters, java.lang.String multiFactorSerialNumber, java.lang.String multiFactorAuthCode)
          Performs an HTTP DELETE request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.
protected  org.apache.commons.httpclient.HttpMethodBase performRestGet(java.lang.String bucketName, java.lang.String objectKey, java.util.Map requestParameters, java.util.Map requestHeaders)
          Performs an HTTP GET request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.
protected  org.apache.commons.httpclient.HttpMethodBase performRestHead(java.lang.String bucketName, java.lang.String objectKey, java.util.Map requestParameters, java.util.Map requestHeaders)
          Performs an HTTP HEAD request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.
protected  RestS3Service.HttpMethodAndByteCount performRestPut(java.lang.String bucketName, java.lang.String objectKey, java.util.Map metadata, java.util.Map requestParameters, org.apache.commons.httpclient.methods.RequestEntity requestEntity, boolean autoRelease)
          Performs an HTTP PUT request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.
protected  RestS3Service.HttpMethodAndByteCount performRestPutWithXmlBuilder(java.lang.String bucketName, java.lang.String objectKey, java.util.Map metadata, java.util.Map requestParameters, com.jamesmurty.utils.XMLBuilder builder)
           
protected  void putAclImpl(java.lang.String bucketName, java.lang.String objectKey, AccessControlList acl, java.lang.String versionId)
           
protected  void putBucketAclImpl(java.lang.String bucketName, AccessControlList acl)
           
protected  void putObjectAclImpl(java.lang.String bucketName, java.lang.String objectKey, AccessControlList acl, java.lang.String versionId)
           
 void putObjectAclWithSignedUrl(java.lang.String signedAclUrl, AccessControlList acl)
          Sets an object's ACL details using a pre-signed PUT URL generated for that object.
protected  S3Object putObjectImpl(java.lang.String bucketName, S3Object object)
          Beware of high memory requirements when creating large S3 objects when the Content-Length is not set in the object.
 S3Object putObjectWithSignedUrl(java.lang.String signedPutUrl, S3Object object)
          Puts an object using a pre-signed PUT URL generated for that object.
protected  void setBucketLoggingStatusImpl(java.lang.String bucketName, S3BucketLoggingStatus status)
           
 void setCredentialsProvider(org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
          Sets the credentials provider this service will use to authenticate itself.
 void setHttpClient(org.apache.commons.httpclient.HttpClient httpClient)
          Replaces the service's default HTTP client.
 void setHttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager httpConnectionManager)
          Replaces the service's default HTTP connection manager.
protected  void setRequesterPaysBucketImpl(java.lang.String bucketName, boolean requesterPays)
           
protected  org.apache.commons.httpclient.HttpMethodBase setupConnection(java.lang.String method, java.lang.String bucketName, java.lang.String objectKey, java.util.Map requestParameters)
          Creates an HttpMethod object to handle a particular connection method.
protected  void shutdownImpl()
          Shut down all connections managed by the underlying HttpConnectionManager.
protected  void updateBucketVersioningStatusImpl(java.lang.String bucketName, boolean enabled, boolean multiFactorAuthDeleteEnabled, java.lang.String multiFactorSerialNumber, java.lang.String multiFactorAuthCode)
           
protected  void verifyExpectedAndActualETagValues(java.lang.String expectedETag, S3Object uploadedObject)
          Compares the expected and actual ETag value for an uploaded object, and throws an S3ServiceException if these values do not match.
 
Methods inherited from class org.jets3t.service.S3Service
assertAuthenticatedConnection, assertValidBucket, assertValidObject, assertValidObject, buildPostForm, buildPostForm, buildPostForm, copyObject, copyObject, copyVersionedObject, copyVersionedObject, createBucket, createBucket, createBucket, createSignedDeleteUrl, createSignedDeleteUrl, createSignedGetUrl, createSignedGetUrl, createSignedHeadUrl, createSignedHeadUrl, createSignedPutUrl, createSignedPutUrl, createSignedUrl, createSignedUrl, createSignedUrl, createTorrentUrl, deleteBucket, deleteBucket, deleteObject, deleteObject, deleteVersionedObject, deleteVersionedObjectWithMFA, disableMFAForVersionedBucket, enableBucketVersioning, enableBucketVersioningWithMFA, generatePostPolicyCondition_AllowAnyValue, generatePostPolicyCondition_Equality, generatePostPolicyCondition_Equality, generatePostPolicyCondition_Equality, generatePostPolicyCondition_Range, generatePostPolicyCondition, generateS3HostnameForBucket, getAccountOwner, getAWSCredentials, getBucket, getBucketAcl, getBucketAcl, getBucketLocation, getBucketLoggingStatus, getBucketVersioningStatus, getCurrentTimeWithOffset, getDevPayProductToken, getDevPayUserToken, getInternalErrorRetryMax, getInvokingApplicationDescription, getJetS3tProperties, getObject, getObject, getObject, getObject, getObjectAcl, getObjectAcl, getObjectDetails, getObjectDetails, getObjectDetails, getObjectDetails, getObjectVersions, getOrCreateBucket, getOrCreateBucket, getVersionedObject, getVersionedObject, getVersionedObject, getVersionedObjectAcl, getVersionedObjectAcl, getVersionedObjectDetails, getVersionedObjectDetails, getVersionedObjectDetails, isAuthenticatedConnection, isBucketNameValidDNSName, isHttpsOnly, isObjectInBucket, isRequesterPaysBucket, isRequesterPaysEnabled, isShutdown, listAllBuckets, listObjects, listObjects, listObjects, listObjects, listObjectsChunked, listObjectsChunked, listVersionedObjects, listVersionedObjectsChunked, moveObject, putBucketAcl, putBucketAcl, putObject, putObject, putObjectAcl, putObjectAcl, putVersionedObjectAcl, putVersionedObjectAcl, renameObject, setBucketLoggingStatus, setDevPayProductToken, setDevPayUserToken, setRequesterPaysBucket, setRequesterPaysEnabled, shutdown, sleepOnInternalError, suspendBucketVersioning, suspendBucketVersioningWithMFA, updateObjectMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

XML_NAMESPACE

public static final java.lang.String XML_NAMESPACE
See Also:
Constant Field Values

httpClient

protected org.apache.commons.httpclient.HttpClient httpClient

connectionManager

protected org.apache.commons.httpclient.HttpConnectionManager connectionManager

credentialsProvider

protected org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider
Constructor Detail

RestS3Service

public RestS3Service(AWSCredentials awsCredentials)
              throws S3ServiceException
Constructs the service and initialises the properties.

Parameters:
awsCredentials - the S3 user credentials to use when communicating with S3, may be null in which case the communication is done as an anonymous user.
Throws:
S3ServiceException

RestS3Service

public RestS3Service(AWSCredentials awsCredentials,
                     java.lang.String invokingApplicationDescription,
                     org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
              throws S3ServiceException
Constructs the service and initialises the properties.

Parameters:
awsCredentials - the S3 user credentials to use when communicating with S3, may be null in which case the communication is done as an anonymous user.
invokingApplicationDescription - a short description of the application using the service, suitable for inclusion in a user agent string for REST/HTTP requests. Ideally this would include the application's version number, for example: Cockpit/0.7.3 or My App Name/1.0
credentialsProvider - an implementation of the HttpClient CredentialsProvider interface, to provide a means for prompting for credentials when necessary.
Throws:
S3ServiceException

RestS3Service

public RestS3Service(AWSCredentials awsCredentials,
                     java.lang.String invokingApplicationDescription,
                     org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider,
                     Jets3tProperties jets3tProperties)
              throws S3ServiceException
Constructs the service and initialises the properties.

Parameters:
awsCredentials - the S3 user credentials to use when communicating with S3, may be null in which case the communication is done as an anonymous user.
invokingApplicationDescription - a short description of the application using the service, suitable for inclusion in a user agent string for REST/HTTP requests. Ideally this would include the application's version number, for example: Cockpit/0.7.3 or My App Name/1.0
credentialsProvider - an implementation of the HttpClient CredentialsProvider interface, to provide a means for prompting for credentials when necessary.
jets3tProperties - JetS3t properties that will be applied within this service.
Throws:
S3ServiceException

RestS3Service

public RestS3Service(AWSCredentials awsCredentials,
                     java.lang.String invokingApplicationDescription,
                     org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider,
                     Jets3tProperties jets3tProperties,
                     org.apache.commons.httpclient.HostConfiguration hostConfig)
              throws S3ServiceException
Constructs the service and initialises the properties.

Parameters:
awsCredentials - the S3 user credentials to use when communicating with S3, may be null in which case the communication is done as an anonymous user.
invokingApplicationDescription - a short description of the application using the service, suitable for inclusion in a user agent string for REST/HTTP requests. Ideally this would include the application's version number, for example: Cockpit/0.7.3 or My App Name/1.0
credentialsProvider - an implementation of the HttpClient CredentialsProvider interface, to provide a means for prompting for credentials when necessary.
jets3tProperties - JetS3t properties that will be applied within this service.
hostConfig - Custom HTTP host configuration; e.g to register a custom Protocol Socket Factory
Throws:
S3ServiceException
Method Detail

shutdownImpl

protected void shutdownImpl()
                     throws S3ServiceException
Shut down all connections managed by the underlying HttpConnectionManager.

Specified by:
shutdownImpl in class S3Service
Throws:
S3ServiceException

initHttpConnection

protected HttpClientAndConnectionManager initHttpConnection(org.apache.commons.httpclient.HostConfiguration hostConfig)
Initialise HttpClient and HttpConnectionManager objects with the configuration settings appropriate for communicating with S3. By default, this method simply delegates the configuration task to RestUtils.initHttpConnection(AWSRequestAuthorizer, HostConfiguration, Jets3tProperties, String, CredentialsProvider).

To alter the low-level behaviour of the HttpClient library, override this method in a subclass and apply your own settings before returning the objects.

Parameters:
hostConfig - Custom HTTP host configuration; e.g to register a custom Protocol Socket Factory
Returns:
configured HttpClient library client and connection manager objects.

getHttpConnectionManager

public org.apache.commons.httpclient.HttpConnectionManager getHttpConnectionManager()
Returns:
the manager of HTTP connections for this service.

setHttpConnectionManager

public void setHttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager httpConnectionManager)
Replaces the service's default HTTP connection manager. This method should only be used by advanced users.

Parameters:
httpConnectionManager - the connection manager that will replace the default manager created by the class constructor.

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient()
Returns:
the HTTP client for this service.

setHttpClient

public void setHttpClient(org.apache.commons.httpclient.HttpClient httpClient)
Replaces the service's default HTTP client. This method should only be used by advanced users.

Parameters:
httpClient - the client that will replace the default client created by the class constructor.

getCredentialsProvider

public org.apache.commons.httpclient.auth.CredentialsProvider getCredentialsProvider()
Returns:
the credentials provider this service will use to authenticate itself, or null if no provider is set.

setCredentialsProvider

public void setCredentialsProvider(org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
Sets the credentials provider this service will use to authenticate itself. Changing the credentials provider with this method will have no effect until the initHttpConnection(HostConfiguration) method is called.

Parameters:
credentialsProvider -

isXmlContentType

protected boolean isXmlContentType(java.lang.String contentType)
Parameters:
contentType -
Returns:
true if the given Content-Type string represents an XML document.

performRequest

protected void performRequest(org.apache.commons.httpclient.HttpMethodBase httpMethod,
                              int[] expectedResponseCodes)
                       throws S3ServiceException
Performs an HTTP/S request by invoking the provided HttpMethod object. If the HTTP response code doesn't match the expected value, an exception is thrown.

Parameters:
httpMethod - the object containing a request target and all other information necessary to perform the request
expectedResponseCodes - the HTTP response code(s) that indicates a successful request. If the response code received does not match this value an error must have occurred, so an exception is thrown.
Throws:
S3ServiceException - all exceptions are wrapped in an S3ServiceException. Depending on the kind of error that occurred, this exception may contain additional error information available from an XML error response document.

authorizeHttpRequest

public void authorizeHttpRequest(org.apache.commons.httpclient.HttpMethod httpMethod)
                          throws java.lang.Exception
Authorizes an HTTP request by signing it. The signature is based on the target URL, and the signed authorization string is added to the HttpMethod object as an Authorization header.

Specified by:
authorizeHttpRequest in interface AWSRequestAuthorizer
Parameters:
httpMethod - the request object
Throws:
S3ServiceException
java.lang.Exception

addRequestParametersToUrlPath

protected java.lang.String addRequestParametersToUrlPath(java.lang.String urlPath,
                                                         java.util.Map requestParameters)
                                                  throws S3ServiceException
Adds all the provided request parameters to a URL in GET request format.

Parameters:
urlPath - the target URL
requestParameters - the parameters to add to the URL as GET request params.
Returns:
the target URL including the parameters.
Throws:
S3ServiceException

addRequestHeadersToConnection

protected void addRequestHeadersToConnection(org.apache.commons.httpclient.HttpMethodBase httpMethod,
                                             java.util.Map requestHeaders)
Adds the provided request headers to the connection.

Parameters:
httpMethod - the connection object
requestHeaders - the request headers to add as name/value pairs.

addMetadataToHeaders

protected void addMetadataToHeaders(org.apache.commons.httpclient.HttpMethodBase httpMethod,
                                    java.util.Map metadata)
                             throws S3ServiceException
Adds all valid metadata name and value pairs as HTTP headers to the given HTTP method. Null metadata names are ignored, as are metadata values that are not of type string.

The metadata values are verified to ensure that keys contain only ASCII characters, and that items are not accidentally duplicated due to use of different capitalization. If either of these verification tests fails, an S3ServiceException is thrown.

Parameters:
httpMethod -
metadata -
Throws:
S3ServiceException

verifyExpectedAndActualETagValues

protected void verifyExpectedAndActualETagValues(java.lang.String expectedETag,
                                                 S3Object uploadedObject)
                                          throws S3ServiceException
Compares the expected and actual ETag value for an uploaded object, and throws an S3ServiceException if these values do not match.

Parameters:
expectedETag -
uploadedObject -
Throws:
S3ServiceException

performRestHead

protected org.apache.commons.httpclient.HttpMethodBase performRestHead(java.lang.String bucketName,
                                                                       java.lang.String objectKey,
                                                                       java.util.Map requestParameters,
                                                                       java.util.Map requestHeaders)
                                                                throws S3ServiceException
Performs an HTTP HEAD request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.

Parameters:
bucketName - the bucket's name
objectKey - the object's key name, may be null if the operation is on a bucket only.
requestParameters - parameters to add to the request URL as GET params
requestHeaders - headers to add to the request
Returns:
the HTTP method object used to perform the request
Throws:
S3ServiceException

performRestGet

protected org.apache.commons.httpclient.HttpMethodBase performRestGet(java.lang.String bucketName,
                                                                      java.lang.String objectKey,
                                                                      java.util.Map requestParameters,
                                                                      java.util.Map requestHeaders)
                                                               throws S3ServiceException
Performs an HTTP GET request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.

Parameters:
bucketName - the bucket's name
objectKey - the object's key name, may be null if the operation is on a bucket only.
requestParameters - parameters to add to the request URL as GET params
requestHeaders - headers to add to the request
Returns:
The HTTP method object used to perform the request.
Throws:
S3ServiceException

performRestPut

protected RestS3Service.HttpMethodAndByteCount performRestPut(java.lang.String bucketName,
                                                              java.lang.String objectKey,
                                                              java.util.Map metadata,
                                                              java.util.Map requestParameters,
                                                              org.apache.commons.httpclient.methods.RequestEntity requestEntity,
                                                              boolean autoRelease)
                                                       throws S3ServiceException
Performs an HTTP PUT request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.

Parameters:
bucketName - the name of the bucket the object will be stored in.
objectKey - the key (name) of the object to be stored.
metadata - map of name/value pairs to add as metadata to any S3 objects created.
requestParameters - parameters to add to the request URL as GET params
requestEntity - an HttpClient object that encapsulates the object and data contents that will be uploaded. This object supports the resending of object data, when possible.
autoRelease - if true, the HTTP Method object will be released after the request has completed and the connection will be closed. If false, the object will not be released and the caller must take responsibility for doing this.
Returns:
a package including the HTTP method object used to perform the request, and the content length (in bytes) of the object that was PUT to S3.
Throws:
S3ServiceException

performRestDelete

protected org.apache.commons.httpclient.HttpMethodBase performRestDelete(java.lang.String bucketName,
                                                                         java.lang.String objectKey,
                                                                         java.util.Map requestParameters,
                                                                         java.lang.String multiFactorSerialNumber,
                                                                         java.lang.String multiFactorAuthCode)
                                                                  throws S3ServiceException
Performs an HTTP DELETE request using the performRequest(org.apache.commons.httpclient.HttpMethodBase, int[]) method.

Parameters:
bucketName - the bucket's name
objectKey - the object's key name, may be null if the operation is on a bucket only.
Returns:
The HTTP method object used to perform the request.
Throws:
S3ServiceException

performRestPutWithXmlBuilder

protected RestS3Service.HttpMethodAndByteCount performRestPutWithXmlBuilder(java.lang.String bucketName,
                                                                            java.lang.String objectKey,
                                                                            java.util.Map metadata,
                                                                            java.util.Map requestParameters,
                                                                            com.jamesmurty.utils.XMLBuilder builder)
                                                                     throws S3ServiceException
Throws:
S3ServiceException

setupConnection

protected org.apache.commons.httpclient.HttpMethodBase setupConnection(java.lang.String method,
                                                                       java.lang.String bucketName,
                                                                       java.lang.String objectKey,
                                                                       java.util.Map requestParameters)
                                                                throws S3ServiceException
Creates an HttpMethod object to handle a particular connection method.

Parameters:
method - the HTTP method/connection-type to use, must be one of: PUT, HEAD, GET, DELETE
bucketName - the bucket's name
objectKey - the object's key name, may be null if the operation is on a bucket only.
Returns:
the HTTP method object used to perform the request
Throws:
S3ServiceException

isBucketAccessible

public boolean isBucketAccessible(java.lang.String bucketName)
                           throws S3ServiceException
Description copied from class: S3Service
Indicates whether a bucket exists and is accessible to a service user. Caution: After changes to the way S3 operates, this check started to cause issues in situations where you need to immediately create a bucket when it does not exist. To conditionally create a bucket, use the S3Service.getOrCreateBucket(String) method instead.

This method can be performed by anonymous services.

Implementation notes

This method can be implemented by attempting to list the objects in a bucket. If the listing is successful return true, if the listing failed for any reason return false.

Specified by:
isBucketAccessible in class S3Service
Returns:
true if the bucket exists and is accessible to the service user, false otherwise.
Throws:
S3ServiceException

checkBucketStatus

public int checkBucketStatus(java.lang.String bucketName)
                      throws S3ServiceException
Description copied from class: S3Service
Find out the status of an S3 bucket with the given name. This method is only implemented in the RestS3Service client.

Warning! S3 can act strangely when you use this method in some circumstances. If you check the status of a bucket and find that it does not exist, then create the bucket, S3 will continue to tell you the bucket does not exists for up to 30 seconds. This problem has something to do with connection caching (I think).

This S3 quirk makes it a bad idea to use this method to check for a bucket's existence before creating that bucket. Use the S3Service.getOrCreateBucket(String) method for this purpose instead.

Specified by:
checkBucketStatus in class S3Service
Returns:
S3Service.BUCKET_STATUS__MY_BUCKET if you already own the bucket, S3Service.BUCKET_STATUS__DOES_NOT_EXIST if the bucket does not yet exist in S3, or S3Service.BUCKET_STATUS__ALREADY_CLAIMED if someone else has already created a bucket with the given name.
Throws:
S3ServiceException

listAllBucketsImpl

protected S3Bucket[] listAllBucketsImpl()
                                 throws S3ServiceException
Specified by:
listAllBucketsImpl in class S3Service
Returns:
the buckets in an S3 account.
Throws:
S3ServiceException

getAccountOwnerImpl

protected S3Owner getAccountOwnerImpl()
                               throws S3ServiceException
Specified by:
getAccountOwnerImpl in class S3Service
Returns:
the owner of an S3 account.
Throws:
S3ServiceException

listObjectsImpl

protected S3Object[] listObjectsImpl(java.lang.String bucketName,
                                     java.lang.String prefix,
                                     java.lang.String delimiter,
                                     long maxListingLength)
                              throws S3ServiceException
Description copied from class: S3Service
Lists objects in a bucket. Implementation notes

The implementation of this method is expected to return all the objects in a bucket, not a subset. This may require repeating the S3 list operation if the first one doesn't include all the available objects, such as when the number of objects is greater than maxListingLength.

Specified by:
listObjectsImpl in class S3Service
Returns:
the objects in a bucket.
Throws:
S3ServiceException

listVersionedObjectsImpl

protected BaseVersionOrDeleteMarker[] listVersionedObjectsImpl(java.lang.String bucketName,
                                                               java.lang.String prefix,
                                                               java.lang.String delimiter,
                                                               java.lang.String keyMarker,
                                                               java.lang.String versionMarker,
                                                               long maxListingLength)
                                                        throws S3ServiceException
Specified by:
listVersionedObjectsImpl in class S3Service
Throws:
S3ServiceException

listObjectsChunkedImpl

protected S3ObjectsChunk listObjectsChunkedImpl(java.lang.String bucketName,
                                                java.lang.String prefix,
                                                java.lang.String delimiter,
                                                long maxListingLength,
                                                java.lang.String priorLastKey,
                                                boolean completeListing)
                                         throws S3ServiceException
Description copied from class: S3Service
Lists objects in a bucket up to the maximum listing length specified.

Implementation notes The implementation of this method returns only as many objects as requested in the chunk size. It is the responsibility of the caller to build a complete object listing from multiple chunks, should this be necessary.

Specified by:
listObjectsChunkedImpl in class S3Service
Throws:
S3ServiceException

listVersionedObjectsChunkedImpl

protected VersionOrDeleteMarkersChunk listVersionedObjectsChunkedImpl(java.lang.String bucketName,
                                                                      java.lang.String prefix,
                                                                      java.lang.String delimiter,
                                                                      long maxListingLength,
                                                                      java.lang.String priorLastKey,
                                                                      java.lang.String priorLastVersion,
                                                                      boolean completeListing)
                                                               throws S3ServiceException
Description copied from class: S3Service
Lists version or delete markers in a versioned bucket, up to the maximum listing length specified.

Implementation notes The implementation of this method returns only as many items as requested in the chunk size. It is the responsibility of the caller to build a complete object listing from multiple chunks, should this be necessary.

Specified by:
listVersionedObjectsChunkedImpl in class S3Service
Throws:
S3ServiceException

listObjectsInternal

protected S3ObjectsChunk listObjectsInternal(java.lang.String bucketName,
                                             java.lang.String prefix,
                                             java.lang.String delimiter,
                                             long maxListingLength,
                                             boolean automaticallyMergeChunks,
                                             java.lang.String priorLastKey,
                                             java.lang.String priorLastVersion)
                                      throws S3ServiceException
Throws:
S3ServiceException

listVersionedObjectsInternal

protected VersionOrDeleteMarkersChunk listVersionedObjectsInternal(java.lang.String bucketName,
                                                                   java.lang.String prefix,
                                                                   java.lang.String delimiter,
                                                                   long maxListingLength,
                                                                   boolean automaticallyMergeChunks,
                                                                   java.lang.String nextKeyMarker,
                                                                   java.lang.String nextVersionIdMarker)
                                                            throws S3ServiceException
Throws:
S3ServiceException

deleteObjectImpl

protected void deleteObjectImpl(java.lang.String bucketName,
                                java.lang.String objectKey,
                                java.lang.String versionId,
                                java.lang.String multiFactorSerialNumber,
                                java.lang.String multiFactorAuthCode)
                         throws S3ServiceException
Specified by:
deleteObjectImpl in class S3Service
Throws:
S3ServiceException

getObjectAclImpl

protected AccessControlList getObjectAclImpl(java.lang.String bucketName,
                                             java.lang.String objectKey)
                                      throws S3ServiceException
Throws:
S3ServiceException

getObjectAclImpl

protected AccessControlList getObjectAclImpl(java.lang.String bucketName,
                                             java.lang.String objectKey,
                                             java.lang.String versionId)
                                      throws S3ServiceException
Specified by:
getObjectAclImpl in class S3Service
Throws:
S3ServiceException

getBucketAclImpl

protected AccessControlList getBucketAclImpl(java.lang.String bucketName)
                                      throws S3ServiceException
Specified by:
getBucketAclImpl in class S3Service
Throws:
S3ServiceException

putObjectAclImpl

protected void putObjectAclImpl(java.lang.String bucketName,
                                java.lang.String objectKey,
                                AccessControlList acl,
                                java.lang.String versionId)
                         throws S3ServiceException
Specified by:
putObjectAclImpl in class S3Service
Throws:
S3ServiceException

putBucketAclImpl

protected void putBucketAclImpl(java.lang.String bucketName,
                                AccessControlList acl)
                         throws S3ServiceException
Specified by:
putBucketAclImpl in class S3Service
Throws:
S3ServiceException

putAclImpl

protected void putAclImpl(java.lang.String bucketName,
                          java.lang.String objectKey,
                          AccessControlList acl,
                          java.lang.String versionId)
                   throws S3ServiceException
Throws:
S3ServiceException

createBucketImpl

protected S3Bucket createBucketImpl(java.lang.String bucketName,
                                    java.lang.String location,
                                    AccessControlList acl)
                             throws S3ServiceException
Description copied from class: S3Service
Creates a bucket. Implementation notes

The implementing method must populate the bucket object's metadata with the results of the operation before returning the object. It must also apply any AccessControlList settings included with the bucket.

Specified by:
createBucketImpl in class S3Service
Parameters:
bucketName - the name of the bucket to create.
location - the geographical location where the bucket will be stored (see S3Bucket.getLocation(). A null string value will cause the bucket to be stored in the default S3 location: US.
acl - an access control object representing the initial acl values for the bucket. May be null, in which case the default permissions are applied.
Returns:
the created bucket object, populated with all metadata made available by the creation operation.
Throws:
S3ServiceException

deleteBucketImpl

protected void deleteBucketImpl(java.lang.String bucketName)
                         throws S3ServiceException
Specified by:
deleteBucketImpl in class S3Service
Throws:
S3ServiceException

updateBucketVersioningStatusImpl

protected void updateBucketVersioningStatusImpl(java.lang.String bucketName,
                                                boolean enabled,
                                                boolean multiFactorAuthDeleteEnabled,
                                                java.lang.String multiFactorSerialNumber,
                                                java.lang.String multiFactorAuthCode)
                                         throws S3ServiceException
Specified by:
updateBucketVersioningStatusImpl in class S3Service
Throws:
S3ServiceException

getBucketVersioningStatusImpl

protected S3BucketVersioningStatus getBucketVersioningStatusImpl(java.lang.String bucketName)
                                                          throws S3ServiceException
Specified by:
getBucketVersioningStatusImpl in class S3Service
Throws:
S3ServiceException

putObjectImpl

protected S3Object putObjectImpl(java.lang.String bucketName,
                                 S3Object object)
                          throws S3ServiceException
Beware of high memory requirements when creating large S3 objects when the Content-Length is not set in the object.

Specified by:
putObjectImpl in class S3Service
Throws:
S3ServiceException

createObjectImpl

protected java.util.Map createObjectImpl(java.lang.String bucketName,
                                         java.lang.String objectKey,
                                         java.lang.String contentType,
                                         org.apache.commons.httpclient.methods.RequestEntity requestEntity,
                                         java.util.Map metadata,
                                         AccessControlList acl)
                                  throws S3ServiceException
Throws:
S3ServiceException

copyObjectImpl

protected java.util.Map copyObjectImpl(java.lang.String sourceBucketName,
                                       java.lang.String sourceObjectKey,
                                       java.lang.String destinationBucketName,
                                       java.lang.String destinationObjectKey,
                                       AccessControlList acl,
                                       java.util.Map destinationMetadata,
                                       java.util.Calendar ifModifiedSince,
                                       java.util.Calendar ifUnmodifiedSince,
                                       java.lang.String[] ifMatchTags,
                                       java.lang.String[] ifNoneMatchTags,
                                       java.lang.String versionId)
                                throws S3ServiceException
Description copied from class: S3Service
Copy an object within your S3 account. Copies within a single bucket or between buckets, and optionally updates the object's metadata at the same time. An object can be copied over itself, allowing you to update the metadata without making any other changes.

Specified by:
copyObjectImpl in class S3Service
Parameters:
sourceBucketName - the name of the bucket that contains the original object.
sourceObjectKey - the key name of the original object.
destinationBucketName - the name of the destination bucket to which the object will be copied.
destinationObjectKey - the key name for the copied object.
acl - the access control settings that will be applied to the copied object. If this parameter is null, the default (private) ACL setting will be applied to the copied object.
destinationMetadata - metadata items to apply to the copied object. If this parameter is null, the metadata will be copied unchanged from the original object. If this parameter is not null, the copied object will have only the supplied metadata.
Returns:
a map of the header and result information returned by S3 after the object copy. The map includes the object's MD5 hash value (ETag), its size (Content-Length), and update timestamp (Last-Modified).
Throws:
S3ServiceException

getObjectDetailsImpl

protected S3Object getObjectDetailsImpl(java.lang.String bucketName,
                                        java.lang.String objectKey,
                                        java.util.Calendar ifModifiedSince,
                                        java.util.Calendar ifUnmodifiedSince,
                                        java.lang.String[] ifMatchTags,
                                        java.lang.String[] ifNoneMatchTags,
                                        java.lang.String versionId)
                                 throws S3ServiceException
Specified by:
getObjectDetailsImpl in class S3Service
Throws:
S3ServiceException

getObjectImpl

protected S3Object getObjectImpl(java.lang.String bucketName,
                                 java.lang.String objectKey,
                                 java.util.Calendar ifModifiedSince,
                                 java.util.Calendar ifUnmodifiedSince,
                                 java.lang.String[] ifMatchTags,
                                 java.lang.String[] ifNoneMatchTags,
                                 java.lang.Long byteRangeStart,
                                 java.lang.Long byteRangeEnd,
                                 java.lang.String versionId)
                          throws S3ServiceException
Specified by:
getObjectImpl in class S3Service
Throws:
S3ServiceException

getBucketLocationImpl

protected java.lang.String getBucketLocationImpl(java.lang.String bucketName)
                                          throws S3ServiceException
Specified by:
getBucketLocationImpl in class S3Service
Throws:
S3ServiceException

getBucketLoggingStatusImpl

protected S3BucketLoggingStatus getBucketLoggingStatusImpl(java.lang.String bucketName)
                                                    throws S3ServiceException
Specified by:
getBucketLoggingStatusImpl in class S3Service
Throws:
S3ServiceException

setBucketLoggingStatusImpl

protected void setBucketLoggingStatusImpl(java.lang.String bucketName,
                                          S3BucketLoggingStatus status)
                                   throws S3ServiceException
Specified by:
setBucketLoggingStatusImpl in class S3Service
Throws:
S3ServiceException

isRequesterPaysBucketImpl

protected boolean isRequesterPaysBucketImpl(java.lang.String bucketName)
                                     throws S3ServiceException
Specified by:
isRequesterPaysBucketImpl in class S3Service
Throws:
S3ServiceException

setRequesterPaysBucketImpl

protected void setRequesterPaysBucketImpl(java.lang.String bucketName,
                                          boolean requesterPays)
                                   throws S3ServiceException
Specified by:
setRequesterPaysBucketImpl in class S3Service
Throws:
S3ServiceException

putObjectWithSignedUrl

public S3Object putObjectWithSignedUrl(java.lang.String signedPutUrl,
                                       S3Object object)
                                throws S3ServiceException
Puts an object using a pre-signed PUT URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

This operation does not required any S3 functionality as it merely uploads the object by performing a standard HTTP PUT using the signed URL.

Specified by:
putObjectWithSignedUrl in interface SignedUrlHandler
Parameters:
signedPutUrl - a signed PUT URL generated with S3Service.createSignedPutUrl(String, String, Map, AWSCredentials, Date).
object - the object to upload, which must correspond to the object for which the URL was signed. The object must have the correct content length set, and to apply a non-standard ACL policy only the REST canned ACLs can be used (eg AccessControlList.REST_CANNED_PUBLIC_READ_WRITE).
Returns:
the S3Object put to S3. The S3Object returned will represent the object created in S3.
Throws:
S3ServiceException

deleteObjectWithSignedUrl

public void deleteObjectWithSignedUrl(java.lang.String signedDeleteUrl)
                               throws S3ServiceException
Deletes an object using a pre-signed DELETE URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

This operation does not required any S3 functionality as it merely deletes the object by performing a standard HTTP DELETE using the signed URL.

Specified by:
deleteObjectWithSignedUrl in interface SignedUrlHandler
Parameters:
signedDeleteUrl - a signed DELETE URL generated with S3Service.createSignedDeleteUrl(java.lang.String, java.lang.String, org.jets3t.service.security.AWSCredentials, java.util.Date, boolean).
Throws:
S3ServiceException

getObjectWithSignedUrl

public S3Object getObjectWithSignedUrl(java.lang.String signedGetUrl)
                                throws S3ServiceException
Gets an object using a pre-signed GET URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

This operation does not required any S3 functionality as it merely uploads the object by performing a standard HTTP GET using the signed URL.

Specified by:
getObjectWithSignedUrl in interface SignedUrlHandler
Parameters:
signedGetUrl - a signed GET URL generated with S3Service.createSignedGetUrl(String, String, AWSCredentials, Date).
Returns:
the S3Object in S3 including all metadata and the object's data input stream.
Throws:
S3ServiceException

getObjectDetailsWithSignedUrl

public S3Object getObjectDetailsWithSignedUrl(java.lang.String signedHeadUrl)
                                       throws S3ServiceException
Gets an object's details using a pre-signed HEAD URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

This operation does not required any S3 functionality as it merely uploads the object by performing a standard HTTP HEAD using the signed URL.

Specified by:
getObjectDetailsWithSignedUrl in interface SignedUrlHandler
Parameters:
signedHeadUrl - a signed HEAD URL generated with S3Service.createSignedHeadUrl(String, String, AWSCredentials, Date).
Returns:
the S3Object in S3 including all metadata, but without the object's data input stream.
Throws:
S3ServiceException

getObjectAclWithSignedUrl

public AccessControlList getObjectAclWithSignedUrl(java.lang.String signedAclUrl)
                                            throws S3ServiceException
Gets an object's ACL details using a pre-signed GET URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

Specified by:
getObjectAclWithSignedUrl in interface SignedUrlHandler
Parameters:
signedAclUrl - a signed URL generated with S3Service.createSignedUrl(String, String, String, String, Map, AWSCredentials, long, boolean).
Returns:
the AccessControlList settings of the object in S3.
Throws:
S3ServiceException

putObjectAclWithSignedUrl

public void putObjectAclWithSignedUrl(java.lang.String signedAclUrl,
                                      AccessControlList acl)
                               throws S3ServiceException
Sets an object's ACL details using a pre-signed PUT URL generated for that object. This method is an implementation of the interface SignedUrlHandler.

Specified by:
putObjectAclWithSignedUrl in interface SignedUrlHandler
Parameters:
signedAclUrl - a signed URL generated with S3Service.createSignedUrl(String, String, String, String, Map, AWSCredentials, long, boolean).
acl - the ACL settings to apply to the object represented by the signed URL.
Throws:
S3ServiceException