Search in sources :

Example 1 with RequestChecksumHanlder

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

the class OSSOperation method doOperation.

protected <T> T doOperation(RequestMessage request, ResponseParser<T> parser, String bucketName, String key, boolean keepResponseOpen, List<RequestHandler> requestHandlers, List<ResponseHandler> reponseHandlers) throws OSSException, ClientException {
    final WebServiceRequest originalRequest = request.getOriginalRequest();
    request.getHeaders().putAll(client.getClientConfiguration().getDefaultHeaders());
    request.getHeaders().putAll(originalRequest.getHeaders());
    request.getParameters().putAll(originalRequest.getParameters());
    ExecutionContext context = createDefaultContext(request.getMethod(), bucketName, key);
    if (context.getCredentials().useSecurityToken() && !request.isUseUrlSignature()) {
        request.addHeader(OSSHeaders.OSS_SECURITY_TOKEN, context.getCredentials().getSecurityToken());
    }
    context.addRequestHandler(new RequestProgressHanlder());
    if (requestHandlers != null) {
        for (RequestHandler handler : requestHandlers) context.addRequestHandler(handler);
    }
    if (client.getClientConfiguration().isCrcCheckEnabled()) {
        context.addRequestHandler(new RequestChecksumHanlder());
    }
    context.addResponseHandler(new ResponseProgressHandler(originalRequest));
    if (reponseHandlers != null) {
        for (ResponseHandler handler : reponseHandlers) context.addResponseHandler(handler);
    }
    if (client.getClientConfiguration().isCrcCheckEnabled()) {
        context.addResponseHandler(new ResponseChecksumHandler());
    }
    List<RequestSigner> signerHandlers = this.client.getClientConfiguration().getSignerHandlers();
    if (signerHandlers != null) {
        for (RequestSigner signer : signerHandlers) {
            context.addSignerHandler(signer);
        }
    }
    ResponseMessage response = send(request, context, keepResponseOpen);
    try {
        return parser.parse(response);
    } catch (ResponseParseException rpe) {
        OSSException oe = ExceptionFactory.createInvalidResponseException(response.getRequestId(), rpe.getMessage(), rpe);
        logException("Unable to parse response error: ", rpe);
        throw oe;
    }
}
Also used : ResponseHandler(com.aliyun.oss.common.comm.ResponseHandler) RequestChecksumHanlder(com.aliyun.oss.common.comm.RequestChecksumHanlder) OSSException(com.aliyun.oss.OSSException) ResponseMessage(com.aliyun.oss.common.comm.ResponseMessage) RequestProgressHanlder(com.aliyun.oss.common.comm.RequestProgressHanlder) ResponseProgressHandler(com.aliyun.oss.common.comm.ResponseProgressHandler) ExecutionContext(com.aliyun.oss.common.comm.ExecutionContext) WebServiceRequest(com.aliyun.oss.model.WebServiceRequest) RequestHandler(com.aliyun.oss.common.comm.RequestHandler) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ResponseChecksumHandler(com.aliyun.oss.common.comm.ResponseChecksumHandler) RequestSigner(com.aliyun.oss.common.auth.RequestSigner)

Aggregations

OSSException (com.aliyun.oss.OSSException)1 RequestSigner (com.aliyun.oss.common.auth.RequestSigner)1 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)1 RequestChecksumHanlder (com.aliyun.oss.common.comm.RequestChecksumHanlder)1 RequestHandler (com.aliyun.oss.common.comm.RequestHandler)1 RequestProgressHanlder (com.aliyun.oss.common.comm.RequestProgressHanlder)1 ResponseChecksumHandler (com.aliyun.oss.common.comm.ResponseChecksumHandler)1 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)1 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)1 ResponseProgressHandler (com.aliyun.oss.common.comm.ResponseProgressHandler)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 WebServiceRequest (com.aliyun.oss.model.WebServiceRequest)1