Search in sources :

Example 1 with WebServiceRequest

use of com.aliyun.oss.model.WebServiceRequest in project aliyun-oss-java-sdk by aliyun.

the class RequestProgressHanlder method handle.

@Override
public void handle(RequestMessage request) throws OSSException, ClientException {
    final WebServiceRequest originalRequest = request.getOriginalRequest();
    final ProgressListener listener = originalRequest.getProgressListener();
    Map<String, String> headers = request.getHeaders();
    String s = headers.get(HttpHeaders.CONTENT_LENGTH);
    if (s != null) {
        try {
            long contentLength = Long.parseLong(s);
            publishRequestContentLength(listener, contentLength);
        } catch (NumberFormatException e) {
            logException("Cannot parse the Content-Length header of the request: ", e);
        }
    }
    InputStream content = request.getContent();
    if (content == null) {
        return;
    }
    if (!content.markSupported()) {
        content = new BufferedInputStream(content);
    }
    request.setContent(listener == ProgressListener.NOOP ? content : ProgressInputStream.inputStreamForRequest(content, originalRequest));
}
Also used : WebServiceRequest(com.aliyun.oss.model.WebServiceRequest) ProgressListener(com.aliyun.oss.event.ProgressListener) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ProgressInputStream(com.aliyun.oss.event.ProgressInputStream) InputStream(java.io.InputStream)

Example 2 with WebServiceRequest

use of com.aliyun.oss.model.WebServiceRequest 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

WebServiceRequest (com.aliyun.oss.model.WebServiceRequest)2 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 ProgressInputStream (com.aliyun.oss.event.ProgressInputStream)1 ProgressListener (com.aliyun.oss.event.ProgressListener)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1