use of com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method deleteObjects.
/*
* (non-Javadoc)
* @see
* com.amazonaws.services.s3.AmazonS3#deleteObjects(com.amazonaws.services
* .s3.model.DeleteObjectsRequest)
*/
@Override
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) {
final Request<DeleteObjectsRequest> request = createRequest(deleteObjectsRequest.getBucketName(), null, deleteObjectsRequest, HttpMethodName.POST);
request.addParameter("delete", null);
if (deleteObjectsRequest.getMfa() != null) {
populateRequestWithMfaDetails(request, deleteObjectsRequest.getMfa());
}
populateRequesterPaysHeader(request, deleteObjectsRequest.isRequesterPays());
final byte[] content = new MultiObjectDeleteXmlFactory().convertToXmlByteArray(deleteObjectsRequest);
request.addHeader("Content-Length", String.valueOf(content.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(content));
try {
final byte[] md5 = Md5Utils.computeMD5Hash(content);
final String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch (final Exception e) {
throw new AmazonClientException("Couldn't compute md5 sum", e);
}
@SuppressWarnings("unchecked") final ResponseHeaderHandlerChain<DeleteObjectsResponse> responseHandler = new ResponseHeaderHandlerChain<DeleteObjectsResponse>(new Unmarshallers.DeleteObjectsResultUnmarshaller(), new S3RequesterChargedHeaderHandler<DeleteObjectsResponse>());
final DeleteObjectsResponse response = invoke(request, responseHandler, deleteObjectsRequest.getBucketName(), null);
/*
* If the result was only partially successful, throw an exception
*/
if (!response.getErrors().isEmpty()) {
final Map<String, String> headers = responseHandler.getResponseHeaders();
final MultiObjectDeleteException ex = new MultiObjectDeleteException(response.getErrors(), response.getDeletedObjects());
ex.setStatusCode(200);
ex.setRequestId(headers.get(Headers.REQUEST_ID));
ex.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
ex.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
throw ex;
}
final DeleteObjectsResult result = new DeleteObjectsResult(response.getDeletedObjects(), response.isRequesterCharged());
return result;
}
use of com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method deleteObjectTagging.
@Override
public DeleteObjectTaggingResult deleteObjectTagging(DeleteObjectTaggingRequest deleteObjectTaggingRequest) {
assertParameterNotNull(deleteObjectTaggingRequest, "The request parameter must be specified when delete the object tags");
final String bucketName = assertStringNotEmpty(deleteObjectTaggingRequest.getBucketName(), "BucketName");
final String key = assertStringNotEmpty(deleteObjectTaggingRequest.getKey(), "Key");
final Request<DeleteObjectTaggingRequest> request = createRequest(bucketName, key, deleteObjectTaggingRequest, HttpMethodName.DELETE);
request.addParameter("tagging", null);
addParameterIfNotNull(request, "versionId", deleteObjectTaggingRequest.getVersionId());
final ResponseHeaderHandlerChain<DeleteObjectTaggingResult> handlerChain = new ResponseHeaderHandlerChain<DeleteObjectTaggingResult>(new Unmarshallers.DeleteObjectTaggingResponseUnmarshaller(), new DeleteObjectTaggingHeaderHandler());
return invoke(request, handlerChain, bucketName, key);
}
use of com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method setObjectTagging.
@Override
public SetObjectTaggingResult setObjectTagging(SetObjectTaggingRequest setObjectTaggingRequest) {
assertParameterNotNull(setObjectTaggingRequest, "The request parameter must be specified setting the object tags");
final String bucketName = assertStringNotEmpty(setObjectTaggingRequest.getBucketName(), "BucketName");
final String key = assertNotNull(setObjectTaggingRequest.getKey(), "Key");
final ObjectTagging tagging = assertNotNull(setObjectTaggingRequest.getTagging(), "ObjectTagging");
final Request<SetObjectTaggingRequest> request = createRequest(bucketName, key, setObjectTaggingRequest, HttpMethodName.PUT);
request.addParameter("tagging", null);
addParameterIfNotNull(request, "versionId", setObjectTaggingRequest.getVersionId());
final byte[] content = new ObjectTaggingXmlFactory().convertToXmlByteArray(tagging);
setContent(request, content, "application/xml", true);
final ResponseHeaderHandlerChain<SetObjectTaggingResult> handlerChain = new ResponseHeaderHandlerChain<SetObjectTaggingResult>(new Unmarshallers.SetObjectTaggingResponseUnmarshaller(), new SetObjectTaggingResponseHeaderHandler());
return invoke(request, handlerChain, bucketName, key);
}
use of com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method getObjectTagging.
@Override
public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest) {
assertParameterNotNull(getObjectTaggingRequest, "The request parameter must be specified when getting the object tags");
final String bucketName = assertStringNotEmpty(getObjectTaggingRequest.getBucketName(), "BucketName");
final String key = assertNotNull(getObjectTaggingRequest.getKey(), "Key");
final Request<GetObjectTaggingRequest> request = createRequest(bucketName, key, getObjectTaggingRequest, HttpMethodName.GET);
request.addParameter("tagging", null);
addParameterIfNotNull(request, "versionId", getObjectTaggingRequest.getVersionId());
final ResponseHeaderHandlerChain<GetObjectTaggingResult> handlerChain = new ResponseHeaderHandlerChain<GetObjectTaggingResult>(new Unmarshallers.GetObjectTaggingResponseUnmarshaller(), new GetObjectTaggingResponseHeaderHandler());
return invoke(request, handlerChain, bucketName, key);
}
use of com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method completeMultipartUpload.
/*
* (non-Javadoc)
* @see
* com.amazonaws.services.s3.AmazonS3#completeMultipartUpload(com.amazonaws
* .services.s3.model.CompleteMultipartUploadRequest)
*/
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest completeMultipartUploadRequest) throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(completeMultipartUploadRequest, "The request parameter must be specified when completing a multipart upload");
final String bucketName = completeMultipartUploadRequest.getBucketName();
final String key = completeMultipartUploadRequest.getKey();
final String uploadId = completeMultipartUploadRequest.getUploadId();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when completing a multipart upload");
assertParameterNotNull(key, "The key parameter must be specified when completing a multipart upload");
assertParameterNotNull(uploadId, "The upload ID parameter must be specified when completing a multipart upload");
assertParameterNotNull(completeMultipartUploadRequest.getPartETags(), "The part ETags parameter must be specified when completing a multipart upload");
int retries = 0;
CompleteMultipartUploadHandler handler;
do {
final Request<CompleteMultipartUploadRequest> request = createRequest(bucketName, key, completeMultipartUploadRequest, HttpMethodName.POST);
request.addParameter("uploadId", uploadId);
populateRequesterPaysHeader(request, completeMultipartUploadRequest.isRequesterPays());
final byte[] xml = RequestXmlFactory.convertToXmlByteArray(completeMultipartUploadRequest.getPartETags());
request.addHeader("Content-Type", "application/xml");
request.addHeader("Content-Length", String.valueOf(xml.length));
request.setContent(new ByteArrayInputStream(xml));
@SuppressWarnings("unchecked") final ResponseHeaderHandlerChain<CompleteMultipartUploadHandler> responseHandler = new ResponseHeaderHandlerChain<CompleteMultipartUploadHandler>(// xml payload unmarshaller
new Unmarshallers.CompleteMultipartUploadResultUnmarshaller(), // header handlers
new ServerSideEncryptionHeaderHandler<CompleteMultipartUploadHandler>(), new ObjectExpirationHeaderHandler<CompleteMultipartUploadHandler>(), new S3VersionHeaderHandler<CompleteMultipartUploadHandler>(), new S3RequesterChargedHeaderHandler<CompleteMultipartUploadHandler>());
handler = invoke(request, responseHandler, bucketName, key);
if (handler.getCompleteMultipartUploadResult() != null) {
return handler.getCompleteMultipartUploadResult();
}
} while (shouldRetryCompleteMultipartUpload(completeMultipartUploadRequest, handler.getAmazonS3Exception(), retries++));
throw handler.getAmazonS3Exception();
}
Aggregations