use of com.qcloud.cos.endpoint.RegionEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class COSClient method populateRequestWithCopyPartParameters.
private void populateRequestWithCopyPartParameters(CosHttpRequest<? extends CosServiceRequest> request, CopyPartRequest copyPartRequest) {
Region sourceRegion = copyPartRequest.getSourceBucketRegion();
EndpointBuilder srcEndpointBuilder = null;
// 如果用户没有设置源region, 则默认和目的region一致
if (sourceRegion == null) {
srcEndpointBuilder = this.clientConfig.getEndpointBuilder();
} else {
srcEndpointBuilder = new RegionEndpointBuilder(sourceRegion);
}
if (copyPartRequest.getSourceEndpointBuilder() != null) {
srcEndpointBuilder = copyPartRequest.getSourceEndpointBuilder();
}
String sourceKey = formatKey(copyPartRequest.getSourceKey());
String sourceBucket = formatBucket(copyPartRequest.getSourceBucketName(), (copyPartRequest.getSourceAppid() != null) ? copyPartRequest.getSourceAppid() : fetchCredential().getCOSAppId());
String copySourceHeader = String.format("%s%s", srcEndpointBuilder.buildGeneralApiEndpoint(sourceBucket), UrlEncoderUtils.encodeEscapeDelimiter(sourceKey));
if (copyPartRequest.getSourceVersionId() != null) {
copySourceHeader += "?versionId=" + copyPartRequest.getSourceVersionId();
}
request.addHeader("x-cos-copy-source", copySourceHeader);
addDateHeader(request, Headers.COPY_SOURCE_IF_MODIFIED_SINCE, copyPartRequest.getModifiedSinceConstraint());
addDateHeader(request, Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE, copyPartRequest.getUnmodifiedSinceConstraint());
addStringListHeader(request, Headers.COPY_SOURCE_IF_MATCH, copyPartRequest.getMatchingETagConstraints());
addStringListHeader(request, Headers.COPY_SOURCE_IF_NO_MATCH, copyPartRequest.getNonmatchingETagConstraints());
if (copyPartRequest.getFirstByte() != null && copyPartRequest.getLastByte() != null) {
String range = "bytes=" + copyPartRequest.getFirstByte() + "-" + copyPartRequest.getLastByte();
request.addHeader(Headers.COPY_PART_RANGE, range);
}
// Populate the SSE-C parameters for the source and destination object
populateSSE_C(request, copyPartRequest.getDestinationSSECustomerKey());
populateSourceSSE_C(request, copyPartRequest.getSourceSSECustomerKey());
}
use of com.qcloud.cos.endpoint.RegionEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class COSClient method populateRequestWithCopyObjectParameters.
private void populateRequestWithCopyObjectParameters(CosHttpRequest<? extends CosServiceRequest> request, CopyObjectRequest copyObjectRequest) {
Region sourceRegion = copyObjectRequest.getSourceBucketRegion();
EndpointBuilder srcEndpointBuilder = null;
// 如果用户没有设置源region, 则默认和目的region一致
if (sourceRegion == null) {
srcEndpointBuilder = this.clientConfig.getEndpointBuilder();
} else {
srcEndpointBuilder = new RegionEndpointBuilder(sourceRegion);
}
if (copyObjectRequest.getSourceEndpointBuilder() != null) {
srcEndpointBuilder = copyObjectRequest.getSourceEndpointBuilder();
}
String sourceKey = formatKey(copyObjectRequest.getSourceKey());
String sourceBucket = formatBucket(copyObjectRequest.getSourceBucketName(), (copyObjectRequest.getSourceAppid() != null) ? copyObjectRequest.getSourceAppid() : fetchCredential().getCOSAppId());
String copySourceHeader = String.format("%s%s", srcEndpointBuilder.buildGeneralApiEndpoint(sourceBucket), UrlEncoderUtils.encodeEscapeDelimiter(sourceKey));
if (copyObjectRequest.getSourceVersionId() != null) {
copySourceHeader += "?versionId=" + copyObjectRequest.getSourceVersionId();
}
request.addHeader("x-cos-copy-source", copySourceHeader);
addDateHeader(request, Headers.COPY_SOURCE_IF_MODIFIED_SINCE, copyObjectRequest.getModifiedSinceConstraint());
addDateHeader(request, Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE, copyObjectRequest.getUnmodifiedSinceConstraint());
addStringListHeader(request, Headers.COPY_SOURCE_IF_MATCH, copyObjectRequest.getMatchingETagConstraints());
addStringListHeader(request, Headers.COPY_SOURCE_IF_NO_MATCH, copyObjectRequest.getNonmatchingETagConstraints());
if (copyObjectRequest.getAccessControlList() != null) {
addAclHeaders(request, copyObjectRequest.getAccessControlList());
} else if (copyObjectRequest.getCannedAccessControlList() != null) {
request.addHeader(Headers.COS_CANNED_ACL, copyObjectRequest.getCannedAccessControlList().toString());
}
if (copyObjectRequest.getStorageClass() != null) {
request.addHeader(Headers.STORAGE_CLASS, copyObjectRequest.getStorageClass());
}
if (copyObjectRequest.getRedirectLocation() != null) {
request.addHeader(Headers.REDIRECT_LOCATION, copyObjectRequest.getRedirectLocation());
}
ObjectMetadata newObjectMetadata = copyObjectRequest.getNewObjectMetadata();
if (copyObjectRequest.getMetadataDirective() != null) {
request.addHeader(Headers.METADATA_DIRECTIVE, copyObjectRequest.getMetadataDirective());
} else if (newObjectMetadata != null) {
request.addHeader(Headers.METADATA_DIRECTIVE, "REPLACE");
}
if (newObjectMetadata != null) {
populateRequestMetadata(request, newObjectMetadata);
}
// Populate the SSE-C parameters for the source and destination object
populateSSE_C(request, copyObjectRequest.getDestinationSSECustomerKey());
populateSourceSSE_C(request, copyObjectRequest.getSourceSSECustomerKey());
populateSSE_KMS(request, copyObjectRequest.getSSECOSKeyManagementParams());
}
use of com.qcloud.cos.endpoint.RegionEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class ClientConfig method setRegion.
public void setRegion(Region region) {
this.region = region;
this.endpointBuilder = new RegionEndpointBuilder(this.region);
}
Aggregations