use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method getBucketCname.
public List<CnameConfiguration> getBucketCname(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> params = new HashMap<String, String>();
params.put(RequestParameters.SUBRESOURCE_CNAME, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
return doOperation(request, getBucketCnameResponseParser, bucketName, null, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method listMultipartUploads.
/**
* List multipart uploads.
*/
public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest) throws OSSException, ClientException {
assertParameterNotNull(listMultipartUploadsRequest, "listMultipartUploadsRequest");
String bucketName = listMultipartUploadsRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
// Use a LinkedHashMap to preserve the insertion order.
Map<String, String> params = new LinkedHashMap<String, String>();
populateListMultipartUploadsRequestParameters(listMultipartUploadsRequest, params);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(listMultipartUploadsRequest).build();
return doOperation(request, listMultipartUploadsResponseParser, bucketName, null, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method uploadPartCopy.
/**
* Upload part copy.
*/
public UploadPartCopyResult uploadPartCopy(UploadPartCopyRequest uploadPartCopyRequest) throws OSSException, ClientException {
assertParameterNotNull(uploadPartCopyRequest, "uploadPartCopyRequest");
String key = uploadPartCopyRequest.getKey();
String bucketName = uploadPartCopyRequest.getBucketName();
String uploadId = uploadPartCopyRequest.getUploadId();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
assertStringNotNullOrEmpty(uploadId, "uploadId");
Long partSize = uploadPartCopyRequest.getPartSize();
if (partSize != null) {
if (!checkParamRange(partSize, 0, true, DEFAULT_FILE_SIZE_LIMIT, true)) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("FileSizeOutOfRange"));
}
}
int partNumber = uploadPartCopyRequest.getPartNumber();
if (!checkParamRange(partNumber, 0, false, MAX_PART_NUMBER, true)) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("PartNumberOutOfRange"));
}
Map<String, String> headers = new HashMap<String, String>();
populateCopyPartRequestHeaders(uploadPartCopyRequest, headers);
// Use a LinkedHashMap to preserve the insertion order.
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(PART_NUMBER, Integer.toString(partNumber));
params.put(UPLOAD_ID, uploadId);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setKey(key).setParameters(params).setHeaders(headers).setOriginalRequest(uploadPartCopyRequest).build();
return doOperation(request, new UploadPartCopyResponseParser(partNumber), bucketName, key, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method uploadPart.
/**
* Upload part.
*/
public UploadPartResult uploadPart(UploadPartRequest uploadPartRequest) throws OSSException, ClientException {
assertParameterNotNull(uploadPartRequest, "uploadPartRequest");
String key = uploadPartRequest.getKey();
String bucketName = uploadPartRequest.getBucketName();
String uploadId = uploadPartRequest.getUploadId();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
assertStringNotNullOrEmpty(uploadId, "uploadId");
if (uploadPartRequest.getInputStream() == null) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetContentStream"));
}
InputStream repeatableInputStream = null;
try {
repeatableInputStream = newRepeatableInputStream(uploadPartRequest.buildPartialStream());
} catch (IOException ex) {
logException("Cannot wrap to repeatable input stream: ", ex);
throw new ClientException("Cannot wrap to repeatable input stream: ", ex);
}
int partNumber = uploadPartRequest.getPartNumber();
if (!checkParamRange(partNumber, 0, false, MAX_PART_NUMBER, true)) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("PartNumberOutOfRange"));
}
Map<String, String> headers = new HashMap<String, String>();
populateUploadPartOptionalHeaders(uploadPartRequest, headers);
// Use a LinkedHashMap to preserve the insertion order.
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(PART_NUMBER, Integer.toString(partNumber));
params.put(UPLOAD_ID, uploadId);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setKey(key).setParameters(params).setHeaders(headers).setInputStream(repeatableInputStream).setInputSize(uploadPartRequest.getPartSize()).setUseChunkEncoding(uploadPartRequest.isUseChunkEncoding()).setOriginalRequest(uploadPartRequest).build();
final ProgressListener listener = uploadPartRequest.getProgressListener();
ResponseMessage response = null;
try {
publishProgress(listener, ProgressEventType.TRANSFER_PART_STARTED_EVENT);
response = doOperation(request, emptyResponseParser, bucketName, key);
publishProgress(listener, ProgressEventType.TRANSFER_PART_COMPLETED_EVENT);
} catch (RuntimeException e) {
publishProgress(listener, ProgressEventType.TRANSFER_PART_FAILED_EVENT);
throw e;
}
UploadPartResult result = new UploadPartResult();
result.setPartNumber(partNumber);
result.setETag(trimQuotes(response.getHeaders().get(OSSHeaders.ETAG)));
result.setRequestId(response.getRequestId());
result.setPartSize(uploadPartRequest.getPartSize());
ResponseParsers.setCRC(result, response);
if (getInnerClient().getClientConfiguration().isCrcCheckEnabled()) {
OSSUtils.checkChecksum(result.getClientCRC(), result.getServerCRC(), result.getRequestId());
}
return result;
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method initiateMultipartUpload.
/**
* Initiate multipart upload.
*/
public InitiateMultipartUploadResult initiateMultipartUpload(InitiateMultipartUploadRequest initiateMultipartUploadRequest) throws OSSException, ClientException {
assertParameterNotNull(initiateMultipartUploadRequest, "initiateMultipartUploadRequest");
String key = initiateMultipartUploadRequest.getKey();
String bucketName = initiateMultipartUploadRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
Map<String, String> headers = new HashMap<String, String>();
if (initiateMultipartUploadRequest.getObjectMetadata() != null) {
populateRequestMetadata(headers, initiateMultipartUploadRequest.getObjectMetadata());
}
// Be careful that we don't send the object's total size as the content
// length for the InitiateMultipartUpload request.
removeHeader(headers, OSSHeaders.CONTENT_LENGTH);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_UPLOADS, null);
// Set the request content to be empty (but not null) to avoid putting
// parameters
// to request body. Set HttpRequestFactory#createHttpRequest for
// details.
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setBucket(bucketName).setKey(key).setHeaders(headers).setParameters(params).setInputStream(new ByteArrayInputStream(new byte[0])).setInputSize(0).setOriginalRequest(initiateMultipartUploadRequest).build();
return doOperation(request, initiateMultipartUploadResponseParser, bucketName, key, true);
}
Aggregations