Search in sources :

Example 1 with CompleteMultipartUploadHandler

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();
}
Also used : Unmarshallers(com.qcloud.cos.internal.Unmarshallers) ByteArrayInputStream(java.io.ByteArrayInputStream) CompleteMultipartUploadHandler(com.qcloud.cos.internal.XmlResponsesSaxParser.CompleteMultipartUploadHandler) ResponseHeaderHandlerChain(com.qcloud.cos.internal.ResponseHeaderHandlerChain)

Aggregations

ResponseHeaderHandlerChain (com.qcloud.cos.internal.ResponseHeaderHandlerChain)1 Unmarshallers (com.qcloud.cos.internal.Unmarshallers)1 CompleteMultipartUploadHandler (com.qcloud.cos.internal.XmlResponsesSaxParser.CompleteMultipartUploadHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1