} else
throw new IllegalArgumentException("Unsupported method in REST request");
}
private void executeCopyObject(HttpServletRequest request, HttpServletResponse response, String copy) throws IOException, XMLStreamException {
S3CopyObjectRequest engineRequest = new S3CopyObjectRequest();
String versionId = null;
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
String key = (String)request.getAttribute(S3Constants.OBJECT_ATTR_KEY);
String sourceBucketName = null;
String sourceKey = null;
// [A] Parse the x-amz-copy-source header into usable pieces
// Check to find a ?versionId= value if any
int index = copy.indexOf('?');
if (-1 != index) {
versionId = copy.substring(index + 1);
if (versionId.startsWith("versionId="))
engineRequest.setVersion(versionId.substring(10));
copy = copy.substring(0, index);
}
// The value of copy should look like: "bucket-name/object-name"
index = copy.indexOf('/');
// In case it looks like "/bucket-name/object-name" discard a leading '/' if it exists
if (0 == index) {
copy = copy.substring(1);
index = copy.indexOf('/');
}
if (-1 == index)
throw new IllegalArgumentException("Invalid x-amz-copy-source header value [" + copy + "]");
sourceBucketName = copy.substring(0, index);
sourceKey = copy.substring(index + 1);
// [B] Set the object used in the SOAP request so it can do the bulk of the work for us
engineRequest.setSourceBucketName(sourceBucketName);
engineRequest.setSourceKey(sourceKey);
engineRequest.setDestinationBucketName(bucketName);
engineRequest.setDestinationKey(key);
engineRequest.setDataDirective(request.getHeader("x-amz-metadata-directive"));
engineRequest.setMetaEntries(extractMetaData(request));
engineRequest.setCannedAccess(request.getHeader("x-amz-acl"));
engineRequest.setConditions(conditionalRequest(request, true));
// [C] Do the actual work and return the result
S3CopyObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest(engineRequest);
versionId = engineResponse.getCopyVersion();