Example usage for com.amazonaws.services.s3.model CopyObjectResult getETag

List of usage examples for com.amazonaws.services.s3.model CopyObjectResult getETag

Introduction

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

Prototype

public String getETag() 

Source Link

Document

Gets the ETag value for the new object that was created in the associated CopyObjectRequest .

Usage

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

License:Open Source License

@Override
public CopyObjectResponseType copyObject(CopyObjectType request) throws S3Exception {
    CopyObjectResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    String sourceBucket = request.getSourceBucket();
    String sourceKey = request.getSourceObject();
    String sourceVersionId = request.getSourceVersionId();
    String destinationBucket = request.getDestinationBucket();
    String destinationKey = request.getDestinationObject();
    String copyIfMatch = request.getCopySourceIfMatch();
    String copyIfNoneMatch = request.getCopySourceIfNoneMatch();
    Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince();
    Date copyIfModifiedSince = request.getCopySourceIfModifiedSince();
    try {//from w ww.  ja va2 s .  c  o  m
        CopyObjectRequest copyRequest = new CopyObjectRequest(sourceBucket, sourceKey, sourceVersionId,
                destinationBucket, destinationKey);
        copyRequest.setModifiedSinceConstraint(copyIfModifiedSince);
        copyRequest.setUnmodifiedSinceConstraint(copyIfUnmodifiedSince);
        if (copyIfMatch != null) {
            List<String> copyIfMatchConstraint = new ArrayList<String>();
            copyIfMatchConstraint.add(copyIfMatch);
            copyRequest.setMatchingETagConstraints(copyIfMatchConstraint);
        }
        if (copyIfNoneMatch != null) {
            List<String> copyIfNoneMatchConstraint = new ArrayList<String>();
            copyIfNoneMatchConstraint.add(copyIfNoneMatch);
            copyRequest.setNonmatchingETagConstraints(copyIfNoneMatchConstraint);
        }
        //TODO: Need to set canned ACL if specified
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        CopyObjectResult result = s3Client.copyObject(copyRequest);
        reply.setEtag(result.getETag());
        reply.setLastModified(DateFormatter.dateToListingFormattedString(result.getLastModifiedDate()));
        String destinationVersionId = result.getVersionId();
        if (destinationVersionId != null) {
            reply.setCopySourceVersionId(sourceVersionId);
            reply.setVersionId(destinationVersionId);
        }
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
    return reply;

}

From source file:io.konig.camel.aws.s3.DeleteObjectProducer.java

License:Apache License

private void copyObject(AmazonS3 s3Client, Exchange exchange) {
    String bucketNameDestination;
    String destinationKey;// www  . j ava  2s .  c o  m
    String sourceKey;
    String bucketName;
    String versionId;

    bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
    if (ObjectHelper.isEmpty(bucketName)) {
        bucketName = getConfiguration().getBucketName();
    }
    sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
    destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
    bucketNameDestination = exchange.getIn().getHeader(S3Constants.BUCKET_DESTINATION_NAME, String.class);
    versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);

    if (ObjectHelper.isEmpty(bucketName)) {
        throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(bucketNameDestination)) {
        throw new IllegalArgumentException(
                "Bucket Name Destination must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(sourceKey)) {
        throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(destinationKey)) {
        throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
    }
    CopyObjectRequest copyObjectRequest;
    if (ObjectHelper.isEmpty(versionId)) {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
    } else {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination,
                destinationKey);
    }

    if (getConfiguration().isUseAwsKMS()) {
        SSEAwsKeyManagementParams keyManagementParams;
        if (ObjectHelper.isNotEmpty(getConfiguration().getAwsKMSKeyId())) {
            keyManagementParams = new SSEAwsKeyManagementParams(getConfiguration().getAwsKMSKeyId());
        } else {
            keyManagementParams = new SSEAwsKeyManagementParams();
        }
        copyObjectRequest.setSSEAwsKeyManagementParams(keyManagementParams);
    }

    CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);

    Message message = getMessageForResponse(exchange);
    message.setHeader(S3Constants.E_TAG, copyObjectResult.getETag());
    if (copyObjectResult.getVersionId() != null) {
        message.setHeader(S3Constants.VERSION_ID, copyObjectResult.getVersionId());
    }
}

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

@Override
public String copyContent(String sourceSpaceId, String sourceContentId, String destSpaceId,
        String destContentId) {/*from   w w w  .  jav  a  2  s.  c om*/
    log.debug("copyContent({}, {}, {}, {})", sourceSpaceId, sourceContentId, destSpaceId, destContentId);

    // Will throw if source bucket does not exist
    String sourceBucketName = getBucketName(sourceSpaceId);
    // Will throw if destination bucket does not exist
    String destBucketName = getBucketName(destSpaceId);

    throwIfContentNotExist(sourceBucketName, sourceContentId);

    CopyObjectRequest request = new CopyObjectRequest(sourceBucketName, sourceContentId, destBucketName,
            destContentId);
    request.setStorageClass(DEFAULT_STORAGE_CLASS);
    request.setCannedAccessControlList(CannedAccessControlList.Private);

    CopyObjectResult result = doCopyObject(request);
    return StorageProviderUtil.compareChecksum(this, sourceSpaceId, sourceContentId, result.getETag());
}