Search in sources :

Example 11 with RequestMessage

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

the class OSSRequestMessageBuilder method build.

public RequestMessage build() {
    Map<String, String> sentHeaders = new HashMap<String, String>(this.headers);
    sentHeaders.put(OSSHeaders.DATE, DateUtil.formatRfc822Date(new Date()));
    Map<String, String> sentParameters = new LinkedHashMap<String, String>(this.parameters);
    RequestMessage request = new RequestMessage(this.originalRequest, this.bucket, this.key);
    ClientConfiguration clientCofig = this.innerClient.getClientConfiguration();
    request.setBucket(bucket);
    request.setKey(key);
    request.setEndpoint(determineFinalEndpoint(this.endpoint, this.bucket, clientCofig));
    request.setResourcePath(determineResourcePath(this.bucket, this.key, clientCofig.isSLDEnabled()));
    request.setHeaders(sentHeaders);
    request.setParameters(sentParameters);
    request.setMethod(this.method);
    request.setContent(this.inputStream);
    request.setContentLength(this.inputSize);
    request.setUseChunkEncoding(this.inputSize == -1 ? true : this.useChunkEncoding);
    return request;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) Date(java.util.Date) ClientConfiguration(com.aliyun.oss.ClientConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with RequestMessage

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

the class OSSUdfOperation method deleteUdfApplication.

public void deleteUdfApplication(UdfGenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String udfName = genericRequest.getName();
    assertParameterNotNull(udfName, "udfName");
    ensureBucketNameValid(udfName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_UDF_APPLICATION, null);
    params.put(RequestParameters.SUBRESOURCE_UDF_NAME, udfName);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.DELETE).setParameters(params).setOriginalRequest(genericRequest).build();
    doOperation(request, emptyResponseParser, null, null, true);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 13 with RequestMessage

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

the class OSSUdfOperation method uploadUdfImage.

/**
 * UDF Image
 */
public void uploadUdfImage(UploadUdfImageRequest uploadUdfImageRequest) throws OSSException, ClientException {
    assertParameterNotNull(uploadUdfImageRequest, "uploadUdfImageRequest");
    assertParameterNotNull(uploadUdfImageRequest.getUdfImage(), "udfImage");
    assertParameterNotNull(uploadUdfImageRequest.getName(), "udfImage");
    ensureBucketNameValid(uploadUdfImageRequest.getName());
    InputStream repeatableInputStream = null;
    try {
        repeatableInputStream = newRepeatableInputStream(uploadUdfImageRequest.getUdfImage());
    } catch (IOException ex) {
        logException("Cannot wrap to repeatable input stream: ", ex);
        throw new ClientException("Cannot wrap to repeatable input stream: ", ex);
    }
    Map<String, String> headers = new HashMap<String, String>();
    Map<String, String> params = new LinkedHashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_UDF_IMAGE, null);
    params.put(RequestParameters.SUBRESOURCE_UDF_NAME, uploadUdfImageRequest.getName());
    if (uploadUdfImageRequest.getUdfImageDesc() != null) {
        params.put(RequestParameters.SUBRESOURCE_UDF_IMAGE_DESC, uploadUdfImageRequest.getUdfImageDesc());
    }
    RequestMessage httpRequest = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setHeaders(headers).setParameters(params).setInputStream(repeatableInputStream).setInputSize(determineInputStreamLength(repeatableInputStream, 0)).setOriginalRequest(uploadUdfImageRequest).build();
    ProgressListener listener = uploadUdfImageRequest.getProgressListener();
    try {
        publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
        doOperation(httpRequest, emptyResponseParser, null, null, true);
        publishProgress(listener, ProgressEventType.TRANSFER_COMPLETED_EVENT);
    } catch (RuntimeException e) {
        publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
        throw e;
    }
}
Also used : ProgressListener(com.aliyun.oss.event.ProgressListener) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ProgressInputStream(com.aliyun.oss.event.ProgressInputStream) IOUtils.newRepeatableInputStream(com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream) InputStream(java.io.InputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) IOException(java.io.IOException) ClientException(com.aliyun.oss.ClientException) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with RequestMessage

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

the class OSSUdfOperation method createUdf.

/**
 * UDF
 */
public void createUdf(CreateUdfRequest createUdfRequest) throws OSSException, ClientException {
    assertParameterNotNull(createUdfRequest, "createUdfRequest");
    assertParameterNotNull(createUdfRequest.getName(), "createUdfRequest.name");
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_UDF, null);
    byte[] rawContent = RequestMarshallers.createUdfRequestMarshaller.marshall(createUdfRequest);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setParameters(params).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).setOriginalRequest(createUdfRequest).build();
    doOperation(request, emptyResponseParser, null, null);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 15 with RequestMessage

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

the class OSSUdfOperation method getUdfInfo.

public UdfInfo getUdfInfo(UdfGenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String udfName = genericRequest.getName();
    assertParameterNotNull(udfName, "udfName");
    ensureBucketNameValid(udfName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_UDF, null);
    params.put(RequestParameters.SUBRESOURCE_UDF_NAME, udfName);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setParameters(params).setOriginalRequest(genericRequest).build();
    return doOperation(request, ResponseParsers.getUdfInfoResponseParser, null, null, true);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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