Example usage for com.amazonaws.services.s3.model GetObjectMetadataRequest setVersionId

List of usage examples for com.amazonaws.services.s3.model GetObjectMetadataRequest setVersionId

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model GetObjectMetadataRequest setVersionId.

Prototype

public void setVersionId(String versionId) 

Source Link

Document

Sets the optional version ID of the object version whose metadata is being retrieved.

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public HeadObjectResponseType headObject(final HeadObjectType request) throws S3Exception {
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    GetObjectMetadataRequest getMetadataRequest = new GetObjectMetadataRequest(request.getBucket(),
            request.getKey());//from   w w w.j  av  a  2  s . c om
    getMetadataRequest.setVersionId(request.getVersionId());
    try {
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        ObjectMetadata metadata;
        metadata = s3Client.getObjectMetadata(getMetadataRequest);

        HeadObjectResponseType reply = request.getReply();
        populateResponseMetadata(reply, metadata);
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }

}

From source file:org.springframework.cloud.aws.core.io.s3.SimpleStorageResource.java

License:Apache License

private ObjectMetadata getObjectMetadata() {
    if (this.objectMetadata == null) {
        try {/* ww w . j  ava  2  s.co  m*/
            GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(this.bucketName,
                    this.objectName);
            if (this.versionId != null) {
                metadataRequest.setVersionId(this.versionId);
            }
            this.objectMetadata = this.amazonS3.getObjectMetadata(metadataRequest);
        } catch (AmazonS3Exception e) {
            // Catch 404 (object not found) and 301 (bucket not found, moved permanently)
            if (e.getStatusCode() == 404 || e.getStatusCode() == 301) {
                this.objectMetadata = null;
            } else {
                throw e;
            }
        }
    }
    return this.objectMetadata;
}