Skip to content

Commit d487c82

Browse files
committed
fix 2.2.1 bugs
1 parent 74eccbf commit d487c82

39 files changed

+477
-68
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>com.aliyun.oss</groupId>
1111
<artifactId>aliyun-sdk-oss</artifactId>
12-
<version>2.2.2-SNAPSHOT</version>
12+
<version>2.2.3-SNAPSHOT</version>
1313
<packaging>jar</packaging>
1414
<name>Aliyun OSS SDK for Java</name>
1515
<description>The Aliyun OSS SDK for Java used for accessing Aliyun Object Storage Service</description>

src/main/java/com/aliyun/oss/common/comm/DefaultServiceClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ protected static ResponseMessage buildResponse(ServiceClient.Request request,
126126

127127
ResponseMessage response = new ResponseMessage(request);
128128
response.setUrl(request.getUri());
129+
response.setHttpResponse(httpResponse);
129130

130131
if (httpResponse.getStatusLine() != null) {
131132
response.setStatusCode(httpResponse.getStatusLine().getStatusCode());

src/main/java/com/aliyun/oss/common/comm/ResponseMessage.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
package com.aliyun.oss.common.comm;
2121

22+
import java.io.IOException;
23+
24+
import org.apache.http.client.methods.CloseableHttpResponse;
25+
2226
import com.aliyun.oss.internal.OSSHeaders;
2327

2428
public class ResponseMessage extends HttpMesssage {
@@ -29,7 +33,8 @@ public class ResponseMessage extends HttpMesssage {
2933
private int statusCode;
3034

3135
private ServiceClient.Request request;
32-
36+
private CloseableHttpResponse httpResponse;
37+
3338
// For convenience of logging invalid response
3439
private String errorResponseAsString;
3540

@@ -72,4 +77,18 @@ public String getErrorResponseAsString() {
7277
public void setErrorResponseAsString(String errorResponseAsString) {
7378
this.errorResponseAsString = errorResponseAsString;
7479
}
80+
81+
public void abort() throws IOException {
82+
if (httpResponse != null) {
83+
httpResponse.close();
84+
}
85+
}
86+
87+
public CloseableHttpResponse getHttpResponse() {
88+
return httpResponse;
89+
}
90+
91+
public void setHttpResponse(CloseableHttpResponse httpResponse) {
92+
this.httpResponse = httpResponse;
93+
}
7594
}

src/main/java/com/aliyun/oss/common/comm/TimeoutServiceClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.ArrayBlockingQueue;
2727
import java.util.concurrent.Callable;
2828
import java.util.concurrent.ExecutionException;
29-
import java.util.concurrent.ExecutorService;
3029
import java.util.concurrent.Executors;
3130
import java.util.concurrent.Future;
3231
import java.util.concurrent.ThreadPoolExecutor;
@@ -47,15 +46,16 @@
4746
* Default implementation of {@link ServiceClient}.
4847
*/
4948
public class TimeoutServiceClient extends DefaultServiceClient {
50-
protected ExecutorService executor;
49+
protected ThreadPoolExecutor executor;
5150

5251
public TimeoutServiceClient(ClientConfiguration config) {
5352
super(config);
5453

5554
int processors = Runtime.getRuntime().availableProcessors();
56-
executor = new ThreadPoolExecutor(0, processors * 10, 60L, TimeUnit.SECONDS,
55+
executor = new ThreadPoolExecutor(processors * 5, processors * 10, 60L, TimeUnit.SECONDS,
5756
new ArrayBlockingQueue<Runnable>(processors * 100),
5857
Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
58+
executor.allowCoreThreadTimeOut(true);
5959
}
6060

6161
@Override

src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ public static OSSException createOSSException(String requestId, String errorCode
108108
String rawResponseError) {
109109
return new OSSException(message, errorCode, requestId, null, null, null, null, rawResponseError);
110110
}
111+
112+
public static OSSException createUnknownOSSException(String requestId, int statusCode) {
113+
String message = "No body in response, http status code " + Integer.toString(statusCode);
114+
return new OSSException(message, ClientErrorCode.UNKNOWN, requestId, null, null, null, null);
115+
}
111116
}

src/main/java/com/aliyun/oss/internal/OSSErrorResponseHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public void handle(ResponseMessage response)
6161
} else if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
6262
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.PRECONDITION_FAILED, "Precondition Failed");
6363
} else {
64-
throw ExceptionFactory.createInvalidResponseException(requestId,
65-
COMMON_RESOURCE_MANAGER.getString("ServerReturnsUnknownError"));
64+
throw ExceptionFactory.createUnknownOSSException(requestId, statusCode);
6665
}
6766
}
6867

src/main/java/com/aliyun/oss/internal/OSSMultipartOperation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public UploadPartResult uploadPart(UploadPartRequest uploadPartRequest)
353353
UploadPartResult result = new UploadPartResult();
354354
result.setPartNumber(partNumber);
355355
result.setETag(trimQuotes(response.getHeaders().get(OSSHeaders.ETAG)));
356+
result.setRequestId(response.getRequestId());
356357
return result;
357358
}
358359

@@ -438,6 +439,10 @@ private static void populateListMultipartUploadsRequestParameters(
438439
if (listMultipartUploadsRequest.getUploadIdMarker() != null) {
439440
params.put(UPLOAD_ID_MARKER, listMultipartUploadsRequest.getUploadIdMarker());
440441
}
442+
443+
if (listMultipartUploadsRequest.getEncodingType() != null) {
444+
params.put(ENCODING_TYPE, listMultipartUploadsRequest.getEncodingType());
445+
}
441446
}
442447

443448
private static void populateListPartsRequestParameters(ListPartsRequest listPartsRequest,

src/main/java/com/aliyun/oss/internal/OSSUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ public static void safeCloseResponse(ResponseMessage response) {
334334
} catch(IOException e) { }
335335
}
336336

337+
public static void mandatoryCloseResponse(ResponseMessage response) {
338+
try {
339+
response.abort();
340+
} catch(IOException e) { }
341+
}
342+
337343
public static long determineInputStreamLength(InputStream instream, long hintLength) {
338344

339345
if (hintLength <= 0 || !instream.markSupported()) {

src/main/java/com/aliyun/oss/internal/ResponseParsers.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ public PutObjectResult parse(ResponseMessage response)
401401
PutObjectResult result = new PutObjectResult();
402402
try {
403403
result.setETag(trimQuotes(response.getHeaders().get(OSSHeaders.ETAG)));
404+
result.setRequestId(response.getRequestId());
404405
return result;
405406
} finally {
406407
safeCloseResponse(response);
@@ -415,6 +416,7 @@ public static final class PutObjectCallbackReponseParser implements ResponsePars
415416
public PutObjectResult parse(ResponseMessage response)
416417
throws ResponseParseException {
417418
PutObjectResult result = new PutObjectResult();
419+
result.setRequestId(response.getRequestId());
418420
result.setETag(trimQuotes(response.getHeaders().get(OSSHeaders.ETAG)));
419421
result.setCallbackResponseBody(response.getContent());
420422
return result;
@@ -428,6 +430,7 @@ public static final class AppendObjectResponseParser implements ResponseParser<A
428430
public AppendObjectResult parse(ResponseMessage response)
429431
throws ResponseParseException {
430432
AppendObjectResult result = new AppendObjectResult();
433+
result.setRequestId(response.getRequestId());
431434
try {
432435
String nextPosition = response.getHeaders().get(OSSHeaders.OSS_NEXT_APPEND_POSITION);
433436
if (nextPosition != null) {
@@ -460,6 +463,7 @@ public OSSObject parse(ResponseMessage response)
460463
ossObject.setBucketName(this.bucketName);
461464
ossObject.setKey(this.key);
462465
ossObject.setObjectContent(response.getContent());
466+
ossObject.setRequestId(response.getRequestId());
463467
try {
464468
ossObject.setObjectMetadata(parseObjectMetadata(response.getHeaders()));
465469
return ossObject;
@@ -497,7 +501,7 @@ public SimplifiedObjectMeta parse(ResponseMessage response)
497501
try {
498502
return parseSimplifiedObjectMeta(response.getHeaders());
499503
} finally {
500-
//safeCloseResponse(response);
504+
OSSUtils.mandatoryCloseResponse(response);
501505
}
502506
}
503507

@@ -523,7 +527,9 @@ public static final class CopyObjectResponseParser implements ResponseParser<Cop
523527
public CopyObjectResult parse(ResponseMessage response)
524528
throws ResponseParseException {
525529
try {
526-
return parseCopyObjectResult(response.getContent());
530+
CopyObjectResult result = parseCopyObjectResult(response.getContent());
531+
result.setRequestId(response.getRequestId());
532+
return result;
527533
} finally {
528534
safeCloseResponse(response);
529535
}
@@ -538,11 +544,15 @@ public DeleteObjectsResult parse(ResponseMessage response)
538544
throws ResponseParseException {
539545
// Occurs when deleting multiple objects in quiet mode.
540546
if (response.getContentLength() == 0) {
541-
return new DeleteObjectsResult(null);
547+
DeleteObjectsResult result = new DeleteObjectsResult(null);
548+
result.setRequestId(response.getRequestId());
549+
return result;
542550
}
543551

544552
try {
545-
return parseDeleteObjectsResult(response.getContent());
553+
DeleteObjectsResult result = parseDeleteObjectsResult(response.getContent());
554+
result.setRequestId(response.getRequestId());
555+
return result;
546556
} finally {
547557
safeCloseResponse(response);
548558
}
@@ -556,7 +566,9 @@ public static final class CompleteMultipartUploadResponseParser implements Respo
556566
public CompleteMultipartUploadResult parse(ResponseMessage response)
557567
throws ResponseParseException {
558568
try {
559-
return parseCompleteMultipartUpload(response.getContent());
569+
CompleteMultipartUploadResult result = parseCompleteMultipartUpload(response.getContent());
570+
result.setRequestId(response.getRequestId());
571+
return result;
560572
} finally {
561573
safeCloseResponse(response);
562574
}
@@ -570,6 +582,7 @@ public static final class CompleteMultipartUploadCallbackResponseParser implemen
570582
public CompleteMultipartUploadResult parse(ResponseMessage response)
571583
throws ResponseParseException {
572584
CompleteMultipartUploadResult result = new CompleteMultipartUploadResult();
585+
result.setRequestId(response.getRequestId());
573586
result.setCallbackResponseBody(response.getContent());
574587
return result;
575588
}
@@ -582,7 +595,9 @@ public static final class InitiateMultipartUploadResponseParser implements Respo
582595
public InitiateMultipartUploadResult parse(ResponseMessage response)
583596
throws ResponseParseException {
584597
try {
585-
return parseInitiateMultipartUpload(response.getContent());
598+
InitiateMultipartUploadResult result = parseInitiateMultipartUpload(response.getContent());
599+
result.setRequestId(response.getRequestId());
600+
return result;
586601
} finally {
587602
safeCloseResponse(response);
588603
}
@@ -633,6 +648,7 @@ public UploadPartCopyResult parse(ResponseMessage response)
633648
UploadPartCopyResult result = new UploadPartCopyResult();
634649
result.setPartNumber(partNumber);
635650
result.setETag(trimQuotes(parseUploadPartCopy(response.getContent())));
651+
result.setRequestId(response.getRequestId());
636652
return result;
637653
} finally {
638654
safeCloseResponse(response);
@@ -952,6 +968,8 @@ public static SimplifiedObjectMeta parseSimplifiedObjectMeta(Map<String, String>
952968
objectMeta.setSize(value);
953969
} else if (key.equals(OSSHeaders.ETAG)) {
954970
objectMeta.setETag(trimQuotes(headers.get(key)));
971+
} else if (key.equals(OSSHeaders.OSS_HEADER_REQUEST_ID)) {
972+
objectMeta.setRequestId(headers.get(key));
955973
}
956974
}
957975

src/main/java/com/aliyun/oss/model/AppendObjectResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Successful response of append object operation.
2525
*/
26-
public class AppendObjectResult {
26+
public class AppendObjectResult extends GenericResult {
2727

2828
/* Indicates that which position to append at next time. */
2929
private Long nextPosition;

0 commit comments

Comments
 (0)