Search in sources :

Example 56 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method getBucketMetadata.

public BucketMetadata getBucketMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String bucketName = genericRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.HEAD).setBucket(bucketName).setOriginalRequest(genericRequest).build();
    List<ResponseHandler> reponseHandlers = new ArrayList<ResponseHandler>();
    reponseHandlers.add(new ResponseHandler() {

        @Override
        public void handle(ResponseMessage response) throws ServiceException, ClientException {
            if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                safeCloseResponse(response);
                throw ExceptionFactory.createOSSException(response.getHeaders().get(OSSHeaders.OSS_HEADER_REQUEST_ID), OSSErrorCode.NO_SUCH_BUCKET, OSS_RESOURCE_MANAGER.getString("NoSuchBucket"));
            }
        }
    });
    return doOperation(request, ResponseParsers.getBucketMetadataResponseParser, bucketName, null, true, null, reponseHandlers);
}
Also used : ResponseHandler(com.aliyun.oss.common.comm.ResponseHandler) ServiceException(com.aliyun.oss.ServiceException) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) ArrayList(java.util.ArrayList) ResponseMessage(com.aliyun.oss.common.comm.ResponseMessage) ClientException(com.aliyun.oss.ClientException)

Example 57 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method getBucketLifecycle.

/**
 * Get bucket lifecycle.
 */
public List<LifecycleRule> getBucketLifecycle(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(SUBRESOURCE_LIFECYCLE, null);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
    return doOperation(request, getBucketLifecycleResponseParser, bucketName, null, true);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 58 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method getBucketReferer.

/**
 * Get bucket referer.
 */
public BucketReferer getBucketReferer(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(SUBRESOURCE_REFERER, null);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
    return doOperation(request, getBucketRefererResponseParser, bucketName, null, true);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 59 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method getImageStyle.

public GetImageStyleResult getImageStyle(String bucketName, String styleName, GenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(bucketName, "bucketName");
    assertParameterNotNull(styleName, "styleName");
    ensureBucketNameValid(bucketName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(SUBRESOURCE_STYLE, null);
    params.put(STYLE_NAME, styleName);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
    return doOperation(request, getImageStyleResponseParser, bucketName, null, true);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 60 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method addBucketCname.

public void addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException {
    assertParameterNotNull(addBucketCnameRequest, "addBucketCnameRequest");
    assertParameterNotNull(addBucketCnameRequest.getDomain(), "addBucketCnameRequest.domain");
    String bucketName = addBucketCnameRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_CNAME, null);
    params.put(RequestParameters.SUBRESOURCE_COMP, RequestParameters.COMP_ADD);
    byte[] rawContent = addBucketCnameRequestMarshaller.marshall(addBucketCnameRequest);
    Map<String, String> headers = new HashMap<String, String>();
    addRequestRequiredHeaders(headers, rawContent);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setBucket(bucketName).setParameters(params).setHeaders(headers).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).setOriginalRequest(addBucketCnameRequest).build();
    doOperation(request, emptyResponseParser, bucketName, null);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) 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