Search in sources :

Example 41 with RequestMessage

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 42 with RequestMessage

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);
}
Also used : RequestMessage(com.aliyun.oss.common.comm.RequestMessage) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with RequestMessage

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);
}
Also used : UploadPartCopyResponseParser(com.aliyun.oss.internal.ResponseParsers.UploadPartCopyResponseParser) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) LinkedHashMap(java.util.LinkedHashMap)

Example 44 with RequestMessage

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) IOUtils.newRepeatableInputStream(com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ResponseMessage(com.aliyun.oss.common.comm.ResponseMessage) LinkedHashMap(java.util.LinkedHashMap) UploadPartResult(com.aliyun.oss.model.UploadPartResult) ProgressListener(com.aliyun.oss.event.ProgressListener) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) ClientException(com.aliyun.oss.ClientException)

Example 45 with RequestMessage

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Aggregations

RequestMessage (com.aliyun.oss.common.comm.RequestMessage)98 LinkedHashMap (java.util.LinkedHashMap)88 HashMap (java.util.HashMap)78 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ClientException (com.aliyun.oss.ClientException)9 ClientConfiguration (com.aliyun.oss.ClientConfiguration)6 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)6 InputStream (java.io.InputStream)6 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)5 IOUtils.newRepeatableInputStream (com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream)5 ProgressListener (com.aliyun.oss.event.ProgressListener)5 ArrayList (java.util.ArrayList)5 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)4 ProgressInputStream (com.aliyun.oss.event.ProgressInputStream)4 URI (java.net.URI)4 CheckedInputStream (java.util.zip.CheckedInputStream)4 ServiceException (com.aliyun.oss.ServiceException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Credentials (com.aliyun.oss.common.auth.Credentials)2