Search in sources :

Example 6 with ResponseHeaderHandlerChain

use of com.qcloud.cos.internal.ResponseHeaderHandlerChain in project cos-java-sdk-v5 by tencentyun.

the class COSClient method getObjectTagging.

@Override
public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest) {
    rejectNull(getObjectTaggingRequest, "The request parameter must be specified when getting the object tags");
    rejectNull(getObjectTaggingRequest.getBucketName(), "The request bucketName must be specified when getting the object tags");
    rejectNull(getObjectTaggingRequest.getKey(), "The request key must be specified when getting the object tags");
    CosHttpRequest<GetObjectTaggingRequest> request = createRequest(getObjectTaggingRequest.getBucketName(), getObjectTaggingRequest.getKey(), getObjectTaggingRequest, HttpMethodName.GET);
    request.addParameter("tagging", null);
    addParameterIfNotNull(request, "versionId", getObjectTaggingRequest.getVersionId());
    ResponseHeaderHandlerChain<GetObjectTaggingResult> handlerChain = new ResponseHeaderHandlerChain<GetObjectTaggingResult>(new Unmarshallers.GetObjectTaggingResponseUnmarshaller(), new GetObjectTaggingResponseHeaderHandler());
    return invoke(request, handlerChain);
}
Also used : Unmarshallers(com.qcloud.cos.internal.Unmarshallers) GetObjectTaggingResponseHeaderHandler(com.qcloud.cos.internal.GetObjectTaggingResponseHeaderHandler) ResponseHeaderHandlerChain(com.qcloud.cos.internal.ResponseHeaderHandlerChain)

Example 7 with ResponseHeaderHandlerChain

use of com.qcloud.cos.internal.ResponseHeaderHandlerChain in project cos-java-sdk-v5 by tencentyun.

the class COSClient method deleteObjectTagging.

@Override
public DeleteObjectTaggingResult deleteObjectTagging(DeleteObjectTaggingRequest deleteObjectTaggingRequest) {
    rejectNull(deleteObjectTaggingRequest, "The request parameter must be specified when delete the object tags");
    rejectNull(deleteObjectTaggingRequest.getBucketName(), "The request bucketName must be specified setting the object tags");
    rejectNull(deleteObjectTaggingRequest.getKey(), "The request key must be specified setting the object tags");
    CosHttpRequest<DeleteObjectTaggingRequest> request = createRequest(deleteObjectTaggingRequest.getBucketName(), deleteObjectTaggingRequest.getKey(), deleteObjectTaggingRequest, HttpMethodName.DELETE);
    request.addParameter("tagging", null);
    addParameterIfNotNull(request, "versionId", deleteObjectTaggingRequest.getVersionId());
    ResponseHeaderHandlerChain<DeleteObjectTaggingResult> handlerChain = new ResponseHeaderHandlerChain<DeleteObjectTaggingResult>(new Unmarshallers.DeleteObjectTaggingResponseUnmarshaller(), new DeleteObjectTaggingHeaderHandler());
    return invoke(request, handlerChain);
}
Also used : Unmarshallers(com.qcloud.cos.internal.Unmarshallers) DeleteObjectTaggingHeaderHandler(com.qcloud.cos.internal.DeleteObjectTaggingHeaderHandler) ResponseHeaderHandlerChain(com.qcloud.cos.internal.ResponseHeaderHandlerChain)

Example 8 with ResponseHeaderHandlerChain

use of com.qcloud.cos.internal.ResponseHeaderHandlerChain in project cos-java-sdk-v5 by tencentyun.

the class COSClient method getAcl.

/**
 * <p>
 * Gets the AccessControlList for the specified resource. (bucket if only the bucketName
 * parameter is specified, otherwise the object with the specified key in the bucket).
 * </p>
 *
 * @param bucketName The name of the bucket whose ACL should be returned if the key parameter is
 *        not specified, otherwise the bucket containing the specified key.
 * @param key The object key whose ACL should be retrieve. If not specified, the bucket's ACL is
 *        returned.
 * @param versionId The version ID of the object version whose ACL is being retrieved.
 * @param originalRequest The original, user facing request object.
 *
 * @return The ACL for the specified resource.
 */
private AccessControlList getAcl(String bucketName, String key, String versionId, CosServiceRequest originalRequest) {
    if (originalRequest == null)
        originalRequest = new GenericBucketRequest(bucketName);
    CosHttpRequest<CosServiceRequest> request = createRequest(bucketName, key, originalRequest, HttpMethodName.GET);
    request.addParameter("acl", null);
    if (versionId != null) {
        request.addParameter("versionId", versionId);
    }
    @SuppressWarnings("unchecked") ResponseHeaderHandlerChain<AccessControlList> responseHandler = new ResponseHeaderHandlerChain<AccessControlList>(new Unmarshallers.AccessControlListUnmarshaller(), new COSDefaultAclHeaderHandler());
    return invoke(request, responseHandler);
}
Also used : Unmarshallers(com.qcloud.cos.internal.Unmarshallers) CosServiceRequest(com.qcloud.cos.internal.CosServiceRequest) COSDefaultAclHeaderHandler(com.qcloud.cos.internal.COSDefaultAclHeaderHandler) ResponseHeaderHandlerChain(com.qcloud.cos.internal.ResponseHeaderHandlerChain)

Example 9 with ResponseHeaderHandlerChain

use of com.qcloud.cos.internal.ResponseHeaderHandlerChain in project cos-java-sdk-v5 by tencentyun.

the class COSClient method deleteObjects.

@Override
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) throws MultiObjectDeleteException, CosClientException, CosServiceException {
    rejectNull(deleteObjectsRequest, "The DeleteObjectsRequest parameter must be specified when deleting objects");
    rejectNull(clientConfig.getRegion(), "region is null, region in clientConfig must be specified when deleting objects");
    CosHttpRequest<DeleteObjectsRequest> request = createRequest(deleteObjectsRequest.getBucketName(), null, deleteObjectsRequest, HttpMethodName.POST);
    request.addParameter("delete", null);
    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 {
        byte[] md5 = Md5Utils.computeMD5Hash(content);
        String md5Base64 = BinaryUtils.toBase64(md5);
        request.addHeader("Content-MD5", md5Base64);
    } catch (Exception e) {
        throw new CosClientException("Couldn't compute md5 sum", e);
    }
    @SuppressWarnings("unchecked") ResponseHeaderHandlerChain<DeleteObjectsResponse> responseHandler = new ResponseHeaderHandlerChain<DeleteObjectsResponse>(new Unmarshallers.DeleteObjectsResultUnmarshaller());
    DeleteObjectsResponse response = invoke(request, responseHandler);
    /*
         * If the result was only partially successful, throw an exception
         */
    if (!response.getErrors().isEmpty()) {
        Map<String, String> headers = responseHandler.getResponseHeaders();
        MultiObjectDeleteException ex = new MultiObjectDeleteException(response.getErrors(), response.getDeletedObjects());
        ex.setStatusCode(200);
        ex.setRequestId(headers.get(Headers.REQUEST_ID));
        throw ex;
    }
    DeleteObjectsResult result = new DeleteObjectsResult(response.getDeletedObjects());
    return result;
}
Also used : DeleteObjectsResponse(com.qcloud.cos.internal.DeleteObjectsResponse) Unmarshallers(com.qcloud.cos.internal.Unmarshallers) CosClientException(com.qcloud.cos.exception.CosClientException) DecoderException(org.apache.commons.codec.DecoderException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MultiObjectDeleteException(com.qcloud.cos.exception.MultiObjectDeleteException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) MalformedURLException(java.net.MalformedURLException) MultiObjectDeleteXmlFactory(com.qcloud.cos.internal.MultiObjectDeleteXmlFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiObjectDeleteException(com.qcloud.cos.exception.MultiObjectDeleteException) ResponseHeaderHandlerChain(com.qcloud.cos.internal.ResponseHeaderHandlerChain)

Aggregations

ResponseHeaderHandlerChain (com.qcloud.cos.internal.ResponseHeaderHandlerChain)9 Unmarshallers (com.qcloud.cos.internal.Unmarshallers)9 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CosClientException (com.qcloud.cos.exception.CosClientException)2 MultiObjectDeleteException (com.qcloud.cos.exception.MultiObjectDeleteException)2 CopyObjectResultHandler (com.qcloud.cos.internal.XmlResponsesSaxParser.CopyObjectResultHandler)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 DecoderException (org.apache.commons.codec.DecoderException)2 COSDefaultAclHeaderHandler (com.qcloud.cos.internal.COSDefaultAclHeaderHandler)1 COSVersionHeaderHandler (com.qcloud.cos.internal.COSVersionHeaderHandler)1 CosMetadataResponseHandler (com.qcloud.cos.internal.CosMetadataResponseHandler)1 CosServiceRequest (com.qcloud.cos.internal.CosServiceRequest)1 DeleteObjectTaggingHeaderHandler (com.qcloud.cos.internal.DeleteObjectTaggingHeaderHandler)1 DeleteObjectsResponse (com.qcloud.cos.internal.DeleteObjectsResponse)1 DigestValidationInputStream (com.qcloud.cos.internal.DigestValidationInputStream)1