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));
}
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;
}
}
Aggregations