use of com.aliyun.oss.HttpMethod in project aliyun-oss-java-sdk by aliyun.
the class ChunkedEncodingTest method testPutObjectChunked2.
@Ignore
public void testPutObjectChunked2() {
try {
Date expiration = DateUtil.parseRfc822Date("Wed, 12 Mar 2015 03:15:00 GMT");
HttpMethod method = HttpMethod.PUT;
URL signedUrl = client.generatePresignedUrl(bucketName, key, expiration, method);
File f = new File(filePath);
FileInputStream fin = new FileInputStream(f);
Map<String, String> customHeaders = new HashMap<String, String>();
customHeaders.put("x-oss-meta-author", "aliy");
customHeaders.put("x-oss-tag", "byurl");
// Using url signature & chunked encoding to upload specified inputstream.
PutObjectResult result = client.putObject(signedUrl, fin, f.length(), customHeaders, true);
fin = new FileInputStream(f);
byte[] binaryData = IOUtils.readStreamAsByteArray(fin);
String expectedETag = BinaryUtil.encodeMD5(binaryData);
String actualETag = result.getETag();
Assert.assertEquals(expectedETag, actualETag);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.HttpMethod in project aliyun-oss-java-sdk by aliyun.
the class HttpRequestFactory method createHttpRequest.
public HttpRequestBase createHttpRequest(ServiceClient.Request request, ExecutionContext context) {
String uri = request.getUri();
HttpRequestBase httpRequest;
HttpMethod method = request.getMethod();
if (method == HttpMethod.POST) {
HttpPost postMethod = new HttpPost(uri);
if (request.getContent() != null) {
postMethod.setEntity(new RepeatableInputStreamEntity(request));
}
httpRequest = postMethod;
} else if (method == HttpMethod.PUT) {
HttpPut putMethod = new HttpPut(uri);
if (request.getContent() != null) {
if (request.isUseChunkEncoding()) {
putMethod.setEntity(buildChunkedInputStreamEntity(request));
} else {
putMethod.setEntity(new RepeatableInputStreamEntity(request));
}
}
httpRequest = putMethod;
} else if (method == HttpMethod.GET) {
httpRequest = new HttpGet(uri);
} else if (method == HttpMethod.DELETE) {
httpRequest = new HttpDelete(uri);
} else if (method == HttpMethod.HEAD) {
httpRequest = new HttpHead(uri);
} else if (method == HttpMethod.OPTIONS) {
httpRequest = new HttpOptions(uri);
} else {
throw new ClientException("Unknown HTTP method name: " + method.toString());
}
configureRequestHeaders(request, context, httpRequest);
return httpRequest;
}
Aggregations