use of com.qcloud.cos.internal.CosServiceRequest in project cos-java-sdk-v5 by tencentyun.
the class COSClient method setAcl.
/**
* Sets the ACL for the specified resource in COS. If only bucketName is specified, the ACL will
* be applied to the bucket, otherwise if bucketName and key are specified, the ACL will be
* applied to the object.
*
* @param bucketName The name of the bucket containing the specified key, or if no key is
* listed, the bucket whose ACL will be set.
* @param key The optional object key within the specified bucket whose ACL will be set. If not
* specified, the bucket ACL will be set.
* @param versionId The version ID of the object version whose ACL is being set.
* @param acl The ACL to apply to the resource.
* @param originalRequest The original, user facing request object.
*/
private void setAcl(String bucketName, String key, String versionId, AccessControlList acl, CosServiceRequest originalRequest) {
if (originalRequest == null)
originalRequest = new GenericBucketRequest(bucketName);
CosHttpRequest<CosServiceRequest> request = createRequest(bucketName, key, originalRequest, HttpMethodName.PUT);
request.addParameter("acl", null);
if (versionId != null)
request.addParameter("versionId", versionId);
byte[] aclAsXml = new AclXmlFactory().convertToXmlByteArray(acl);
request.addHeader("Content-Type", "application/xml");
request.addHeader("Content-Length", String.valueOf(aclAsXml.length));
request.setContent(new ByteArrayInputStream(aclAsXml));
invoke(request, voidCosResponseHandler);
}
use of com.qcloud.cos.internal.CosServiceRequest in project cos-java-sdk-v5 by tencentyun.
the class COSClient method invoke.
private <X, Y extends CosServiceRequest> X invoke(CosHttpRequest<Y> request, HttpResponseHandler<CosServiceResponse<X>> responseHandler) throws CosClientException, CosServiceException {
COSSigner cosSigner = clientConfig.getCosSigner();
COSCredentials cosCredentials;
CosServiceRequest cosServiceRequest = request.getOriginalRequest();
if (cosServiceRequest != null && cosServiceRequest.getCosCredentials() != null) {
cosCredentials = cosServiceRequest.getCosCredentials();
} else {
cosCredentials = fetchCredential();
}
Date expiredTime = new Date(System.currentTimeMillis() + clientConfig.getSignExpired() * 1000);
boolean isCIWorkflowRequest = cosServiceRequest instanceof CIWorkflowServiceRequest;
cosSigner.setCIWorkflowRequest(isCIWorkflowRequest);
cosSigner.sign(request, cosCredentials, expiredTime);
return this.cosHttpClient.exeute(request, responseHandler);
}
use of com.qcloud.cos.internal.CosServiceRequest 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);
}
Aggregations