use of com.qcloud.cos.internal.XmlResponsesSaxParser.CompleteMultipartUploadHandler in project cos-java-sdk-v5 by tencentyun.
the class COSClient method completeMultipartUpload.
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest completeMultipartUploadRequest) throws CosClientException, CosServiceException {
rejectNull(completeMultipartUploadRequest, "The request parameter must be specified when completing a multipart upload");
String bucketName = completeMultipartUploadRequest.getBucketName();
String key = completeMultipartUploadRequest.getKey();
String uploadId = completeMultipartUploadRequest.getUploadId();
rejectNull(bucketName, "The bucket name parameter must be specified when completing a multipart upload");
rejectNull(key, "The key parameter must be specified when completing a multipart upload");
rejectNull(uploadId, "The upload ID parameter must be specified when completing a multipart upload");
rejectNull(completeMultipartUploadRequest.getPartETags(), "The part ETags parameter must be specified when completing a multipart upload");
rejectNull(clientConfig.getRegion(), "region is null, region in clientConfig must be specified when completing a multipart uploads");
int retries = 0;
CompleteMultipartUploadHandler handler;
do {
CosHttpRequest<CompleteMultipartUploadRequest> request = createRequest(bucketName, key, completeMultipartUploadRequest, HttpMethodName.POST);
request.addParameter("uploadId", uploadId);
byte[] xml = RequestXmlFactory.convertToXmlByteArray(completeMultipartUploadRequest.getPartETags());
request.addHeader("Content-Type", "application/xml");
request.addHeader("Content-Length", String.valueOf(xml.length));
ObjectMetadata objectMetadata = completeMultipartUploadRequest.getObjectMetadata();
if (objectMetadata != null) {
populateRequestMetadata(request, objectMetadata);
}
request.setContent(new ByteArrayInputStream(xml));
if (completeMultipartUploadRequest.getPicOperations() != null) {
request.addHeader(Headers.PIC_OPERATIONS, Jackson.toJsonString(completeMultipartUploadRequest.getPicOperations()));
}
@SuppressWarnings("unchecked") ResponseHeaderHandlerChain<CompleteMultipartUploadHandler> responseHandler = new ResponseHeaderHandlerChain<CompleteMultipartUploadHandler>(// xml payload unmarshaller
new Unmarshallers.CompleteMultipartUploadResultUnmarshaller(), // header handlers
new ServerSideEncryptionHeaderHandler<CompleteMultipartUploadHandler>(), new ObjectExpirationHeaderHandler<CompleteMultipartUploadHandler>(), new VIDResultHandler<CompleteMultipartUploadHandler>());
handler = invoke(request, responseHandler);
if (handler.getCompleteMultipartUploadResult() != null) {
Map<String, String> responseHeaders = responseHandler.getResponseHeaders();
String versionId = responseHeaders.get(Headers.COS_VERSION_ID);
String crc64Ecma = responseHeaders.get(Headers.COS_HASH_CRC64_ECMA);
handler.getCompleteMultipartUploadResult().setVersionId(versionId);
handler.getCompleteMultipartUploadResult().setCrc64Ecma(crc64Ecma);
// if ci request, set ciUploadResult to CompleteMultipartUploadResult
if (completeMultipartUploadRequest.getPicOperations() != null) {
handler.getCompleteMultipartUploadResult().setCiUploadResult(handler.getCiUploadResult());
}
return handler.getCompleteMultipartUploadResult();
}
} while (shouldRetryCompleteMultipartUpload(completeMultipartUploadRequest, handler.getCOSException(), retries++));
throw handler.getCOSException();
}
Aggregations