public class GoogleStorageService extends RestStorageService
This class uses properties obtained through Jets3tProperties. For more information on
these properties please refer to
JetS3t Configuration
RestStorageService.HTTP_METHODcredentialsProvider, defaultServerSideEncryptionAlgorithm, defaultStorageClass, httpClient, regionEndpointCache, shuttingDownBUCKET_STATUS__ALREADY_CLAIMED, BUCKET_STATUS__DOES_NOT_EXIST, BUCKET_STATUS__MY_BUCKET, timeOffset| Constructor and Description |
|---|
GoogleStorageService(ProviderCredentials credentials)
Constructs the service and initialises the properties.
|
GoogleStorageService(ProviderCredentials credentials,
java.lang.String invokingApplicationDescription,
org.apache.http.client.CredentialsProvider credentialsProvider)
Constructs the service and initialises the properties.
|
GoogleStorageService(ProviderCredentials credentials,
java.lang.String invokingApplicationDescription,
org.apache.http.client.CredentialsProvider credentialsProvider,
Jets3tProperties jets3tProperties)
Constructs the service and initialises the properties.
|
| Modifier and Type | Method and Description |
|---|---|
void |
authorizeHttpRequest(org.apache.http.client.methods.HttpUriRequest httpMethod,
org.apache.http.protocol.HttpContext context,
java.lang.String ignoredForceRequestSignatureVersion)
Authorizes an HTTP/S request using the standard HMAC approach or OAuth 2,
whichever technique is appropriate.
|
GSBucket |
createBucket(java.lang.String bucketName)
Creates a bucket.
|
GSBucket |
createBucket(java.lang.String bucketName,
java.lang.String location,
AccessControlList acl) |
GSBucket |
createBucket(java.lang.String bucketName,
java.lang.String location,
AccessControlList acl,
java.lang.String projectId)
Creates a bucket in a specific location, without checking whether the bucket already
exists.
|
protected StorageBucket |
createBucketImpl(java.lang.String bucketName,
java.lang.String location,
AccessControlList acl,
java.lang.String projectId) |
void |
deleteWebsiteConfig(java.lang.String bucketName)
Delete a bucket's website configuration; removes the effect of any
previously-applied configuration.
|
protected void |
deleteWebsiteConfigImpl(java.lang.String bucketName) |
GSAccessControlList |
getBucketAcl(java.lang.String bucketName)
Retrieves the access control settings of a bucket.
|
java.lang.String |
getBucketLocation(java.lang.String bucketName) |
GSBucketLoggingStatus |
getBucketLoggingStatus(java.lang.String bucketName) |
protected boolean |
getDisableDnsBuckets() |
protected boolean |
getEnableServerSideEncryption() |
protected boolean |
getEnableStorageClasses() |
java.lang.String |
getEndpoint() |
protected int |
getHttpPort() |
protected boolean |
getHttpsOnly() |
protected int |
getHttpsPort() |
GSObject |
getObject(java.lang.String bucketName,
java.lang.String objectKey)
Returns an object representing the details and data of an item in a service,
without applying any preconditions.
|
GSObject |
getObject(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)
Returns an object representing the details and data of an item that meets any given preconditions.
|
GSObject |
getObjectDetails(java.lang.String bucketName,
java.lang.String objectKey)
Returns an object representing the details of an item in without the object's data, and
without applying any preconditions.
|
java.util.List<java.lang.String> |
getResourceParameterNames() |
java.lang.String |
getRestHeaderPrefix() |
java.lang.String |
getRestMetadataPrefix() |
protected java.lang.String |
getSignatureIdentifier() |
protected java.lang.String |
getVirtualPath() |
GSWebsiteConfig |
getWebsiteConfig(java.lang.String bucketName) |
protected XmlResponsesSaxParser |
getXmlResponseSaxParser() |
protected boolean |
isRecoverable403(org.apache.http.client.methods.HttpUriRequest httpRequest,
java.lang.Exception exception)
Determine whether a given 403 Forbidden HTTP error response is recoverable and should
be retried.
|
protected boolean |
isTargettingGoogleStorageService() |
GSBucket[] |
listAllBuckets()
Lists the buckets belonging to the service user.
|
GSBucket[] |
listAllBuckets(java.lang.String projectId)
List all buckets in a given project
|
protected StorageBucket[] |
listAllBucketsImpl(java.lang.String projectId) |
GSObject[] |
listObjects(java.lang.String bucketName)
Lists the objects in a bucket.
|
GSObject[] |
listObjects(java.lang.String bucketName,
java.lang.String prefix,
java.lang.String delimiter)
Lists the objects in a bucket matching a prefix and delimiter.
|
protected StorageBucket |
newBucket() |
protected StorageObject |
newObject() |
void |
putBucketAcl(GSBucket bucket)
Applies access control settings to a bucket.
|
void |
putBucketAcl(java.lang.String bucketName,
GSAccessControlList acl)
Applies access control settings to a bucket.
|
GSObject |
putObject(java.lang.String bucketName,
GSObject object) |
void |
setBucketLoggingStatus(java.lang.String bucketName,
GSBucketLoggingStatus status) |
protected org.apache.http.client.methods.HttpUriRequest |
setupConnection(RestStorageService.HTTP_METHOD method,
java.lang.String bucketName,
java.lang.String objectKey,
java.util.Map<java.lang.String,java.lang.String> requestParameters)
Creates an
HttpRequest object to handle a particular connection method. |
void |
setWebsiteConfig(java.lang.String bucketName,
GSWebsiteConfig config)
Apply a website configuration to a bucket.
|
addMetadataToHeaders, addRequestHeadersToConnection, addRequestParametersToUrlPath, checkBucketStatus, copyObjectImpl, createBucketImpl, createObjectImpl, deleteBucketImpl, deleteObjectImpl, deleteObjectWithSignedUrl, getAccountOwnerImpl, getBucketAclImpl, getBucketLocationImpl, getBucketLoggingStatusImpl, getCredentialsProvider, getHttpClient, getHttpConnectionManager, getObjectAclImpl, getObjectAclImpl, getObjectAclWithSignedUrl, getObjectDetailsImpl, getObjectDetailsWithSignedUrl, getObjectImpl, getObjectWithSignedUrl, getRegionEndpointCache, getWebsiteConfigImpl, initHttpConnection, initializeDefaults, initializeProxy, isBucketAccessible, isLiveMD5HashingRequired, isXmlContentType, listAllBucketsImpl, listObjectsChunkedImpl, listObjectsImpl, listObjectsInternal, performRequest, performRequest, performRestDelete, performRestGet, performRestGet, performRestHead, performRestPost, performRestPostWithXmlBuilder, performRestPut, performRestPutWithXmlBuilder, prepareRESTHeaderAcl, prepareServerSideEncryption, prepareStorageClass, putAclImpl, putBucketAclImpl, putObjectAclImpl, putObjectAclWithSignedUrl, putObjectImpl, putObjectWithRequestEntityImpl, putObjectWithSignedUrl, setBucketLoggingStatusImpl, setCredentialsProvider, setHttpClient, setRegionEndpointCache, setWebsiteConfigImpl, shutdownImpl, verifyExpectedAndActualETagValuesassertAuthenticatedConnection, assertValidBucket, assertValidObject, assertValidObject, copyObject, copyObject, createBucket, createBucketImpl, deleteBucket, deleteBucket, deleteObject, getAccountOwner, getBucket, getCurrentTimeWithOffset, getInternalErrorRetryMax, getInvokingApplicationDescription, getJetS3tProperties, getObjectAcl, getObjectDetails, getOrCreateBucket, getProviderCredentials, isAuthenticatedConnection, isHttpsOnly, isObjectInBucket, isShutdown, listAllBucketsImpl, listObjects, listObjectsChunked, listObjectsChunked, moveObject, putBucketAcl, putBucketAcl, putObject, putObjectAcl, putObjectAcl, renameMetadataKeys, renameObject, setProviderCredentials, shutdown, sleepOnInternalError, updateObjectMetadatapublic GoogleStorageService(ProviderCredentials credentials) throws ServiceException
credentials - the user credentials to use when communicating with Google Storage, may be null in which case the
communication is done as an anonymous user.ServiceException - Service errorpublic GoogleStorageService(ProviderCredentials credentials, java.lang.String invokingApplicationDescription, org.apache.http.client.CredentialsProvider credentialsProvider) throws ServiceException
credentials - the user credentials to use when communicating with Google Storage, 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.0credentialsProvider - an implementation of the HttpClient CredentialsProvider interface, to provide a means for
prompting for credentials when necessary.ServiceException - Service errorpublic GoogleStorageService(ProviderCredentials credentials, java.lang.String invokingApplicationDescription, org.apache.http.client.CredentialsProvider credentialsProvider, Jets3tProperties jets3tProperties) throws ServiceException
credentials - the user credentials to use when communicating with Google Storage, 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.0credentialsProvider - 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.ServiceException - Service errorprotected org.apache.http.client.methods.HttpUriRequest setupConnection(RestStorageService.HTTP_METHOD method, java.lang.String bucketName, java.lang.String objectKey, java.util.Map<java.lang.String,java.lang.String> requestParameters) throws ServiceException
RestStorageServiceHttpRequest object to handle a particular connection method.setupConnection in class RestStorageServicemethod - the HTTP method/connection-type to use, must be one of: PUT, HEAD, GET, DELETEbucketName - the bucket's nameobjectKey - the object's key name, may be null if the operation is on a bucket only.ServiceExceptionprotected boolean isTargettingGoogleStorageService()
isTargettingGoogleStorageService in class RestStorageServicepublic java.lang.String getEndpoint()
getEndpoint in class StorageServiceprotected java.lang.String getVirtualPath()
getVirtualPath in class StorageServiceprotected java.lang.String getSignatureIdentifier()
getSignatureIdentifier in class StorageServicepublic java.lang.String getRestHeaderPrefix()
getRestHeaderPrefix in class StorageServicepublic java.lang.String getRestMetadataPrefix()
getRestMetadataPrefix in class StorageServicepublic java.util.List<java.lang.String> getResourceParameterNames()
getResourceParameterNames in class StorageServiceprotected int getHttpPort()
getHttpPort in class StorageServiceprotected int getHttpsPort()
getHttpsPort in class StorageServiceprotected boolean getHttpsOnly()
getHttpsOnly in class StorageServiceprotected boolean getDisableDnsBuckets()
getDisableDnsBuckets in class StorageServiceprotected boolean getEnableStorageClasses()
getEnableStorageClasses in class StorageServiceprotected boolean getEnableServerSideEncryption()
getEnableServerSideEncryption in class StorageServiceprotected XmlResponsesSaxParser getXmlResponseSaxParser() throws ServiceException
getXmlResponseSaxParser in class StorageServiceServiceExceptionprotected StorageBucket newBucket()
newBucket in class StorageServiceStorageBucket implementation.protected StorageObject newObject()
newObject in class StorageServiceStorageObject implementation.public GSBucket[] listAllBuckets() throws ServiceException
StorageServiceThis method cannot be performed by anonymous services, and will fail with an exception if the service is not authenticated.
listAllBuckets in class StorageServiceServiceExceptionpublic GSBucket[] listAllBuckets(java.lang.String projectId) throws ServiceException
projectId - The ID of the project being listedGSBucketServiceException - Service errorpublic GSObject[] listObjects(java.lang.String bucketName) throws ServiceException
StorageService
The objects returned by this method contain only minimal information
such as the object's size, ETag, and LastModified timestamp. To retrieve
the objects' metadata you must perform follow-up getObject
or getObjectDetails operations.
This method can be performed by anonymous services. Anonymous services can only list the objects in a publicly-readable bucket.
listObjects in class StorageServicebucketName - the name of the bucket whose contents will be listed.ServiceExceptionpublic GSObject[] listObjects(java.lang.String bucketName, java.lang.String prefix, java.lang.String delimiter) throws ServiceException
StorageService
The objects returned by this method contain only minimal information
such as the object's size, ETag, and LastModified timestamp. To retrieve
the objects' metadata you must perform follow-up getObject
or getObjectDetails operations.
This method can be performed by anonymous services. Anonymous services can only list the objects in a publicly-readable bucket.
NOTE: If you supply a delimiter value that could cause virtual path
"subdirectories" to be included in the results from the service, use the
StorageService.listObjectsChunked(String, String, String, long, String, boolean)
method instead of this one to obtain both object and path values.
listObjects in class StorageServicebucketName - the name of the bucket whose contents will be listed.prefix - only objects with a key that starts with this prefix will be listeddelimiter - only list objects with key names up to this delimiter, may be null.
See note above.
Note: If a non-null delimiter is specified, the prefix must include enough text to
reach the first occurrence of the delimiter in the bucket's keys, or no results will be returned.ServiceExceptionpublic GSBucket createBucket(java.lang.String bucketName) throws ServiceException
StorageServiceStorageService.getOrCreateBucket(String) in situations where the bucket may already exist.
This method cannot be performed by anonymous services.createBucket in class StorageServicebucketName - the name of the bucket to create.ServiceExceptionpublic GSBucket createBucket(java.lang.String bucketName, java.lang.String location, AccessControlList acl, java.lang.String projectId) throws ServiceException
StorageService.getOrCreateBucket(String) in situations where the bucket may already exist.
This method cannot be performed by anonymous services.
bucketName - the name of the bucket to create.location - the location of the S3 data centre in which the bucket will be created, or null for the
default GSBucket.LOCATION_US location. Valid values
include GSBucket.LOCATION_US, GSBucket.LOCATION_EUROPE,
and the default US location that can be
expressed in two ways:
GSBucket.LOCATION_US or GSBucket.LOCATION_DEFAULT.acl - the access control settings to apply to the new bucket, or null for default ACL values.projectId - the project within which to create the bucketServiceException - Service errorpublic GSBucket createBucket(java.lang.String bucketName, java.lang.String location, AccessControlList acl) throws ServiceException
ServiceExceptionpublic GSBucketLoggingStatus getBucketLoggingStatus(java.lang.String bucketName) throws ServiceException
ServiceExceptionpublic void setBucketLoggingStatus(java.lang.String bucketName,
GSBucketLoggingStatus status)
throws ServiceException
ServiceExceptionpublic java.lang.String getBucketLocation(java.lang.String bucketName)
throws ServiceException
ServiceExceptionpublic GSAccessControlList getBucketAcl(java.lang.String bucketName) throws ServiceException
StorageServicegetBucketAcl in class StorageServicebucketName - the name of the bucket whose access control settings will be returned.ServiceExceptionpublic void putBucketAcl(java.lang.String bucketName,
GSAccessControlList acl)
throws ServiceException
bucketName - a name of the bucket with ACL settings to apply.acl - PermissionsServiceException - Service errorpublic void putBucketAcl(GSBucket bucket) throws ServiceException
bucket - a bucket with ACL settings to apply.ServiceException - Service errorpublic GSObject getObject(java.lang.String bucketName, java.lang.String objectKey) throws ServiceException
StorageServiceThis method can be performed by anonymous services. Anonymous services can get a publicly-readable object.
Important: It is the caller's responsibility to close the object's data input stream. The data stream should be consumed and closed as soon as is practical as network connections may be held open until the streams are closed. Excessive unclosed streams can lead to connection starvation.
getObject in class StorageServicebucketName - the name of the bucket containing the object.objectKey - the key identifying the object.ServiceExceptionpublic GSObject putObject(java.lang.String bucketName, GSObject object) throws ServiceException
ServiceExceptionpublic GSObject getObject(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) throws ServiceException
StorageServiceImportant: It is the caller's responsibility to close the object's data input stream. The data stream should be consumed and closed as soon as is practical as network connections may be held open until the streams are closed. Excessive unclosed streams can lead to connection starvation.
An exception is thrown if any of the preconditions fail. Preconditions are only applied if they are non-null.
This method can be performed by anonymous services. Anonymous services can get a publicly-readable object.
Implementation notes
Implementations should use StorageService.assertValidBucket(org.jets3t.service.model.StorageBucket, java.lang.String) assertion.
getObject in class StorageServicebucketName - the name of the bucket containing the object.objectKey - the key identifying the object.ifModifiedSince - a precondition specifying a date after which the object must have been modified, ignored if null.ifUnmodifiedSince - a precondition specifying a date after which the object must not have been modified, ignored if null.ifMatchTags - a precondition specifying an MD5 hash the object must match, ignored if null.ifNoneMatchTags - a precondition specifying an MD5 hash the object must not match, ignored if null.byteRangeStart - include only a portion of the object's data - starting at this point, ignored if null.byteRangeEnd - include only a portion of the object's data - ending at this point, ignored if null.ServiceExceptionpublic GSObject getObjectDetails(java.lang.String bucketName, java.lang.String objectKey) throws ServiceException
StorageServiceThis method can be performed by anonymous services. Anonymous services can get a publicly-readable object's details.
getObjectDetails in class StorageServicebucketName - the name of the bucket containing the object.objectKey - the key identifying the object.ServiceExceptionpublic void authorizeHttpRequest(org.apache.http.client.methods.HttpUriRequest httpMethod,
org.apache.http.protocol.HttpContext context,
java.lang.String ignoredForceRequestSignatureVersion)
throws ServiceException
authorizeHttpRequest in interface JetS3tRequestAuthorizerauthorizeHttpRequest in class RestStorageServicehttpMethod - the request objectcontext - ignoredForceRequestSignatureVersion - ignored parameter relevant only for AWS4-HMAC-SHA256 request signing.ServiceExceptionprotected boolean isRecoverable403(org.apache.http.client.methods.HttpUriRequest httpRequest,
java.lang.Exception exception)
RestStorageServiceGenerally, such errors should not be retried since a user's access permissions for an item are unlikely to change, but if a service is using expiring authorization tokens (e.g. OAuth) it may be worthwhile retrying after refreshing those tokens.
isRecoverable403 in class RestStorageServicehttpRequest - Requestexception - Server responseprotected StorageBucket[] listAllBucketsImpl(java.lang.String projectId) throws ServiceException
ServiceExceptionprotected StorageBucket createBucketImpl(java.lang.String bucketName, java.lang.String location, AccessControlList acl, java.lang.String projectId) throws ServiceException
ServiceExceptionpublic void setWebsiteConfig(java.lang.String bucketName,
GSWebsiteConfig config)
throws ServiceException
bucketName - bucket to which the website configuration will be applied.config - the website configuration details.ServiceExceptionpublic GSWebsiteConfig getWebsiteConfig(java.lang.String bucketName) throws ServiceException
bucketName - a bucket with a website configuration.ServiceExceptionpublic void deleteWebsiteConfig(java.lang.String bucketName)
throws ServiceException
bucketName - a bucket with a website configuration.ServiceExceptionprotected void deleteWebsiteConfigImpl(java.lang.String bucketName)
throws ServiceException
deleteWebsiteConfigImpl in class RestStorageServiceServiceException