|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jets3t.service.S3Service
org.jets3t.service.impl.rest.httpclient.RestS3Service
public class RestS3Service
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
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 | |
---|---|
static String |
VERSION
|
static String |
XML_NAMESPACE
|
Fields inherited from class org.jets3t.service.S3Service |
---|
BUCKET_STATUS__ALREADY_CLAIMED, BUCKET_STATUS__DOES_NOT_EXIST, BUCKET_STATUS__MY_BUCKET, VERSION_NO__JETS3T_TOOLKIT |
Constructor Summary | |
---|---|
RestS3Service(AWSCredentials awsCredentials)
Constructs the service and initialises the properties. |
|
RestS3Service(AWSCredentials awsCredentials,
String invokingApplicationDescription,
org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
Constructs the service and initialises the properties. |
|
RestS3Service(AWSCredentials awsCredentials,
String invokingApplicationDescription,
org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider,
Jets3tProperties jets3tProperties)
Constructs the service and initialises the properties. |
|
RestS3Service(AWSCredentials awsCredentials,
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 | |
---|---|
void |
authorizeHttpRequest(org.apache.commons.httpclient.HttpMethod httpMethod)
Authorizes an HTTP request by signing it. |
int |
checkBucketStatus(String bucketName)
Find out the status of an S3 bucket with the given name. |
void |
deleteObjectWithSignedUrl(String signedDeleteUrl)
Deletes an object using a pre-signed DELETE URL generated for that object. |
org.apache.commons.httpclient.auth.CredentialsProvider |
getCredentialsProvider()
|
org.apache.commons.httpclient.HttpClient |
getHttpClient()
|
org.apache.commons.httpclient.HttpConnectionManager |
getHttpConnectionManager()
|
AccessControlList |
getObjectAclWithSignedUrl(String signedAclUrl)
Gets an object's ACL details using a pre-signed GET URL generated for that object. |
S3Object |
getObjectDetailsWithSignedUrl(String signedHeadUrl)
Gets an object's details using a pre-signed HEAD URL generated for that object. |
S3Object |
getObjectWithSignedUrl(String signedGetUrl)
Gets an object using a pre-signed GET URL generated for that object. |
boolean |
isBucketAccessible(String bucketName)
Indicates whether a bucket exists and is accessible to a service user. |
void |
putObjectAclWithSignedUrl(String signedAclUrl,
AccessControlList acl)
Sets an object's ACL details using a pre-signed PUT URL generated for that object. |
S3Object |
putObjectWithSignedUrl(String signedPutUrl,
S3Object object)
Puts an object using a pre-signed PUT URL generated for that object. |
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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String VERSION
public static final String XML_NAMESPACE
Constructor Detail |
---|
public RestS3Service(AWSCredentials awsCredentials) throws S3ServiceException
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.
S3ServiceException
public RestS3Service(AWSCredentials awsCredentials, String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider) throws S3ServiceException
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.
S3ServiceException
public RestS3Service(AWSCredentials awsCredentials, String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider, Jets3tProperties jets3tProperties) throws S3ServiceException
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.
S3ServiceException
public RestS3Service(AWSCredentials awsCredentials, String invokingApplicationDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider, Jets3tProperties jets3tProperties, org.apache.commons.httpclient.HostConfiguration hostConfig) throws S3ServiceException
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
S3ServiceException
Method Detail |
---|
public org.apache.commons.httpclient.HttpConnectionManager getHttpConnectionManager()
public void setHttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager httpConnectionManager)
httpConnectionManager
- the connection manager that will replace the default manager created by
the class constructor.public org.apache.commons.httpclient.HttpClient getHttpClient()
public void setHttpClient(org.apache.commons.httpclient.HttpClient httpClient)
httpClient
- the client that will replace the default client created by
the class constructor.public org.apache.commons.httpclient.auth.CredentialsProvider getCredentialsProvider()
public void setCredentialsProvider(org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
initHttpConnection(HostConfiguration)
method
is called.
credentialsProvider
- public void authorizeHttpRequest(org.apache.commons.httpclient.HttpMethod httpMethod) throws Exception
HttpMethod
object as an Authorization header.
authorizeHttpRequest
in interface AWSRequestAuthorizer
httpMethod
- the request object
S3ServiceException
Exception
public boolean isBucketAccessible(String bucketName) throws S3ServiceException
S3Service
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.
isBucketAccessible
in class S3Service
S3ServiceException
public int checkBucketStatus(String bucketName) throws S3ServiceException
S3Service
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.
checkBucketStatus
in class S3Service
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.
S3ServiceException
public S3Object putObjectWithSignedUrl(String signedPutUrl, S3Object object) throws S3ServiceException
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.
putObjectWithSignedUrl
in interface SignedUrlHandler
signedPutUrl
- a signed PUT URL.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
).
S3ServiceException
public void deleteObjectWithSignedUrl(String signedDeleteUrl) throws S3ServiceException
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.
deleteObjectWithSignedUrl
in interface SignedUrlHandler
signedDeleteUrl
- a signed DELETE URL.
S3ServiceException
public S3Object getObjectWithSignedUrl(String signedGetUrl) throws S3ServiceException
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.
getObjectWithSignedUrl
in interface SignedUrlHandler
signedGetUrl
- a signed GET URL.
S3ServiceException
public S3Object getObjectDetailsWithSignedUrl(String signedHeadUrl) throws S3ServiceException
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.
getObjectDetailsWithSignedUrl
in interface SignedUrlHandler
signedHeadUrl
- a signed HEAD URL.
S3ServiceException
public AccessControlList getObjectAclWithSignedUrl(String signedAclUrl) throws S3ServiceException
SignedUrlHandler
.
getObjectAclWithSignedUrl
in interface SignedUrlHandler
signedAclUrl
- a signed URL.
S3ServiceException
public void putObjectAclWithSignedUrl(String signedAclUrl, AccessControlList acl) throws S3ServiceException
SignedUrlHandler
.
putObjectAclWithSignedUrl
in interface SignedUrlHandler
signedAclUrl
- a signed URL.acl
- the ACL settings to apply to the object represented by the signed URL.
S3ServiceException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |