Class CmsGenericS3Client
- All Implemented Interfaces:
AutoCloseable,I_CmsS3Client
Should work with most products such as SeaweedFS, MinIO, Garage, Ceph.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opencms.db.storage.s3.I_CmsS3Client
I_CmsS3Client.I_CmsS3ObjectKeyVisitor, I_CmsS3Client.I_CmsS3ObjectMetadataVisitor, I_CmsS3Client.I_CmsS3ObjectVisitor -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault single API call attempt timeout in milliseconds.static final intDefault complete API call timeout in milliseconds.static final intDefault timeout for acquiring a pooled connection in milliseconds.static final intDefault connection timeout in milliseconds.static final intDefault maximum number of pooled connections.static final intDefault maximum number of retries.static final StringDefault AWS region.static final intDefault socket timeout in milliseconds.static final intMaximum number of keys accepted by the S3 DeleteObjects API. -
Constructor Summary
ConstructorsConstructorDescriptionCmsGenericS3Client(String endpoint, String bucketName, String accessKey, String secretKey, boolean pathStyle) Creates a new local S3 client.CmsGenericS3Client(String endpoint, String bucketName, String accessKey, String secretKey, boolean pathStyle, int connectionTimeout, int socketTimeout, int apiCallAttemptTimeout, int apiCallTimeout, int maxRetries) Creates a new local S3 client.CmsGenericS3Client(CmsS3ClientConfiguration configuration) Creates a new local S3 client. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the client and releases associated resources.voiddeleteObject(String key) Deletes an object from the specified bucket.deleteObjects(List<String> keys) Deletes multiple objects.booleanChecks if an object exists in the specified bucket.byte[]Retrieves an object's content from the specified bucket.longgetObjectLength(String key) Returns the length of an object's content.longReturns the length of an object's content if the object exists.getObjectMetadata(String key) Returns an object's metadata.voidUploads an object to the specified bucket.voidreadObjectFrom(String key, I_CmsFileContentStreamHandler handler) Passes an object's content from the specified bucket to the given input stream handler.booleanrenewObject(String key, String expectedRevision, Instant renewalTime) Renews an object by conditionally copying it onto itself.static CmsS3ClientConfigurationresolveCredentials(CmsS3ClientConfiguration configuration) Resolves credentials in the S3 client configuration with the OpenCms credentials resolver.static CmsS3ClientConfigurationresolveCredentials(CmsS3ClientConfiguration configuration, I_CmsCredentialsResolver credentialsResolver) Resolves credentials in the S3 client configuration.voidValidates that the configured bucket is accessible.voidVisits all object keys in the configured bucket.voidvisitObjects(String prefix, I_CmsS3Client.I_CmsS3ObjectMetadataVisitor visitor) Visits object metadata for objects matching an optional prefix.voidVisits all objects in the configured bucket.voidwriteObjectRangeTo(String key, long start, long length, OutputStream out) Writes an object byte range from the specified bucket to the given output stream.writeObjectRangeToWithMetadata(String key, long start, long length, OutputStream out) Writes an object byte range and returns the metadata received with the object response.voidwriteObjectTo(String key, OutputStream out) Writes an object's content from the specified bucket to the given output stream.writeObjectToWithMetadata(String key, OutputStream out) Writes an object's content and returns the metadata received with the object response.
-
Field Details
-
MAX_DELETE_OBJECTS
Maximum number of keys accepted by the S3 DeleteObjects API.- See Also:
-
DEFAULT_API_CALL_TIMEOUT
Default complete API call timeout in milliseconds.- See Also:
-
DEFAULT_API_CALL_ATTEMPT_TIMEOUT
Default single API call attempt timeout in milliseconds.- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
Default connection timeout in milliseconds.- See Also:
-
DEFAULT_CONNECTION_ACQUISITION_TIMEOUT
Default timeout for acquiring a pooled connection in milliseconds.- See Also:
-
DEFAULT_MAX_CONNECTIONS
Default maximum number of pooled connections.- See Also:
-
DEFAULT_MAX_RETRIES
Default maximum number of retries.- See Also:
-
DEFAULT_REGION
Default AWS region. -
DEFAULT_SOCKET_TIMEOUT
Default socket timeout in milliseconds.- See Also:
-
-
Constructor Details
-
CmsGenericS3Client
Creates a new local S3 client.- Parameters:
configuration- the S3 client configuration
-
CmsGenericS3Client
public CmsGenericS3Client(String endpoint, String bucketName, String accessKey, String secretKey, boolean pathStyle) Creates a new local S3 client.- Parameters:
endpoint- the URL of the S3 server (e.g., "http://localhost:8080")bucketName- the bucket nameaccessKey- the access keysecretKey- the secret keypathStyle- whether path-style access should be used
-
CmsGenericS3Client
public CmsGenericS3Client(String endpoint, String bucketName, String accessKey, String secretKey, boolean pathStyle, int connectionTimeout, int socketTimeout, int apiCallAttemptTimeout, int apiCallTimeout, int maxRetries) Creates a new local S3 client.- Parameters:
endpoint- the URL of the S3 server (e.g., "http://localhost:8080")bucketName- the bucket nameaccessKey- the access keysecretKey- the secret keypathStyle- whether path-style access should be usedconnectionTimeout- the connection timeout in millisecondssocketTimeout- the socket timeout in millisecondsapiCallAttemptTimeout- the timeout for a single API call attempt in millisecondsapiCallTimeout- the timeout for the complete API call in millisecondsmaxRetries- the maximum number of retries
-
-
Method Details
-
resolveCredentials
Resolves credentials in the S3 client configuration with the OpenCms credentials resolver.- Parameters:
configuration- the original S3 client configuration- Returns:
- the S3 client configuration with resolved credentials
-
resolveCredentials
public static CmsS3ClientConfiguration resolveCredentials(CmsS3ClientConfiguration configuration, I_CmsCredentialsResolver credentialsResolver) Resolves credentials in the S3 client configuration.- Parameters:
configuration- the original S3 client configurationcredentialsResolver- the credentials resolver- Returns:
- the S3 client configuration with resolved credentials
-
close
Description copied from interface:I_CmsS3ClientCloses the client and releases associated resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceI_CmsS3Client- Throws:
Exception- if closing the client fails
-
deleteObject
Description copied from interface:I_CmsS3ClientDeletes an object from the specified bucket.- Specified by:
deleteObjectin interfaceI_CmsS3Client- Parameters:
key- the identifier for the object to delete- Throws:
Exception- if the deletion fails
-
deleteObjects
Description copied from interface:I_CmsS3ClientDeletes multiple objects.The optimized S3 implementation supports at most 1000 keys per call. This default implementation preserves compatibility for other clients.
- Specified by:
deleteObjectsin interfaceI_CmsS3Client- Parameters:
keys- the object keys- Returns:
- the per-object delete result
- Throws:
Exception- if the complete request fails- See Also:
-
exists
Description copied from interface:I_CmsS3ClientChecks if an object exists in the specified bucket.- Specified by:
existsin interfaceI_CmsS3Client- Parameters:
key- the identifier for the object- Returns:
- true if the object exists, false otherwise
- Throws:
Exception- if the existence check fails
-
getObject
Description copied from interface:I_CmsS3ClientRetrieves an object's content from the specified bucket.- Specified by:
getObjectin interfaceI_CmsS3Client- Parameters:
key- the identifier for the object- Returns:
- the binary data of the object
- Throws:
Exception- if the object cannot be retrieved or does not exist
-
getObjectLength
Description copied from interface:I_CmsS3ClientReturns the length of an object's content.- Specified by:
getObjectLengthin interfaceI_CmsS3Client- Parameters:
key- the identifier for the object- Returns:
- the object content length
- Throws:
Exception- if the object can not be accessed
-
getObjectLengthIfExists
Description copied from interface:I_CmsS3ClientReturns the length of an object's content if the object exists.- Specified by:
getObjectLengthIfExistsin interfaceI_CmsS3Client- Parameters:
key- the identifier for the object- Returns:
- the object content length, or
-1if the object does not exist - Throws:
Exception- if the object can not be accessed
-
getObjectMetadata
Description copied from interface:I_CmsS3ClientReturns an object's metadata.- Specified by:
getObjectMetadatain interfaceI_CmsS3Client- Parameters:
key- the identifier for the object- Returns:
- the object metadata
- Throws:
Exception- if the object can not be accessed- See Also:
-
putObject
Description copied from interface:I_CmsS3ClientUploads an object to the specified bucket.- Specified by:
putObjectin interfaceI_CmsS3Client- Parameters:
key- the unique identifier (path) for the objectcontent- the binary data to upload- Throws:
Exception- if the upload fails
-
readObjectFrom
Description copied from interface:I_CmsS3ClientPasses an object's content from the specified bucket to the given input stream handler.- Specified by:
readObjectFromin interfaceI_CmsS3Client- Parameters:
key- the identifier for the objecthandler- the stream handler- Throws:
Exception- if the object cannot be retrieved or handled- See Also:
-
renewObject
public boolean renewObject(String key, String expectedRevision, Instant renewalTime) throws Exception Description copied from interface:I_CmsS3ClientRenews an object by conditionally copying it onto itself.The copy must only be applied when the source still has the expected revision. A missing object or revision mismatch is not an error and is reported by returning
false. The S3 last-modified time is always assigned by the storage server.- Specified by:
renewObjectin interfaceI_CmsS3Client- Parameters:
key- the object keyexpectedRevision- the expected source revisionrenewalTime- the requested renewal time- Returns:
trueif the object was renewed, orfalseif it no longer matched- Throws:
Exception- if the copy fails- See Also:
-
validateBucketAccess
Description copied from interface:I_CmsS3ClientValidates that the configured bucket is accessible.- Specified by:
validateBucketAccessin interfaceI_CmsS3Client- Throws:
Exception- if the bucket can not be accessed
-
visitObjectKeys
Description copied from interface:I_CmsS3ClientVisits all object keys in the configured bucket.- Specified by:
visitObjectKeysin interfaceI_CmsS3Client- Parameters:
visitor- the object key visitor- Throws:
Exception- if listing fails
-
visitObjects
Description copied from interface:I_CmsS3ClientVisits all objects in the configured bucket.- Specified by:
visitObjectsin interfaceI_CmsS3Client- Parameters:
visitor- the object visitor- Throws:
Exception- if listing fails
-
visitObjects
public void visitObjects(String prefix, I_CmsS3Client.I_CmsS3ObjectMetadataVisitor visitor) throws Exception Description copied from interface:I_CmsS3ClientVisits object metadata for objects matching an optional prefix.This compatibility implementation filters client-side and can not provide timestamps or revisions. Optimized clients should override it.
- Specified by:
visitObjectsin interfaceI_CmsS3Client- Parameters:
prefix- the object key prefix, ornullvisitor- the metadata visitor- Throws:
Exception- if listing fails- See Also:
-
writeObjectRangeTo
public void writeObjectRangeTo(String key, long start, long length, OutputStream out) throws Exception Description copied from interface:I_CmsS3ClientWrites an object byte range from the specified bucket to the given output stream.- Specified by:
writeObjectRangeToin interfaceI_CmsS3Client- Parameters:
key- the identifier for the objectstart- the first byte to writelength- the number of bytes to writeout- the output stream to write to- Throws:
Exception- if the object cannot be retrieved or written- See Also:
-
writeObjectRangeToWithMetadata
public CmsS3ObjectMetadata writeObjectRangeToWithMetadata(String key, long start, long length, OutputStream out) throws Exception Description copied from interface:I_CmsS3ClientWrites an object byte range and returns the metadata received with the object response.Optimized clients should override this method so that no additional metadata request is needed. The default implementation preserves compatibility by reading the range first and loading the metadata afterwards.
- Specified by:
writeObjectRangeToWithMetadatain interfaceI_CmsS3Client- Parameters:
key- the identifier for the objectstart- the first byte to writelength- the number of bytes to writeout- the output stream to write to- Returns:
- the object metadata
- Throws:
Exception- if the object cannot be retrieved or written- See Also:
-
writeObjectTo
Description copied from interface:I_CmsS3ClientWrites an object's content from the specified bucket to the given output stream.- Specified by:
writeObjectToin interfaceI_CmsS3Client- Parameters:
key- the identifier for the objectout- the output stream to write to- Throws:
Exception- if the object cannot be retrieved or written
-
writeObjectToWithMetadata
Description copied from interface:I_CmsS3ClientWrites an object's content and returns the metadata received with the object response.Optimized clients should override this method so that no additional metadata request is needed. The default implementation preserves compatibility by reading the object first and loading the metadata afterwards.
- Specified by:
writeObjectToWithMetadatain interfaceI_CmsS3Client- Parameters:
key- the identifier for the objectout- the output stream to write to- Returns:
- the object metadata
- Throws:
Exception- if the object cannot be retrieved or written- See Also:
-