Skip to content

Commit 8ad1d54

Browse files
Feature release 3.0.2 (#8)
* make sure error requests are closed to prevent connection leak during high-error counts * correct spelling of HEADER_IF_UNMODIFIED_SINCE * fixed bug in shareable URLs with UTF-8 non-ASCII characters * fixed MD search ObjectName test
1 parent 3d4ca66 commit 8ad1d54

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

src/main/java/com/emc/object/s3/S3SignerV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public URL generatePresignedUrl(PresignedUrlRequest request) {
8282
URI uri = s3Config.resolvePath(request.getPath(), null); // don't care about the query string yet
8383

8484
// must construct both the final URL and the resource for signing
85-
String resource = "/" + request.getBucketName() + uri.getPath();
85+
String resource = "/" + request.getBucketName() + RestUtil.getEncodedPath(uri);
8686

8787
// insert namespace in host
8888
if (namespace != null) {

src/main/java/com/emc/object/s3/jersey/ErrorFilter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio
7070
throw parseErrorResponse(new InputStreamReader(response.getEntityInputStream()), response.getStatus());
7171
} else {
7272
// No response entity. Don't try to parse it.
73+
try {
74+
response.close();
75+
} catch (Throwable t) {
76+
log.warn("could not close response after error", t);
77+
}
7378
Response.StatusType st = response.getStatusInfo();
7479
throw new S3Exception(st.getReasonPhrase(), st.getStatusCode(), guessStatus(st.getStatusCode()),
7580
response.getHeaders().getFirst("x-amz-request-id"));

src/main/java/com/emc/object/s3/request/GetObjectRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Map<String, List<Object>> getHeaders() {
6969
if (ifModifiedSince != null)
7070
RestUtil.putSingle(headers, RestUtil.HEADER_IF_MODIFIED_SINCE, RestUtil.headerFormat(ifModifiedSince));
7171
if (ifUnmodifiedSince != null)
72-
RestUtil.putSingle(headers, RestUtil.HEADER_IF_UNMODIFIED_SINE, RestUtil.headerFormat(ifUnmodifiedSince));
72+
RestUtil.putSingle(headers, RestUtil.HEADER_IF_UNMODIFIED_SINCE, RestUtil.headerFormat(ifUnmodifiedSince));
7373
if (ifMatch != null) RestUtil.putSingle(headers, RestUtil.HEADER_IF_MATCH, ifMatch);
7474
if (ifNoneMatch != null) RestUtil.putSingle(headers, RestUtil.HEADER_IF_NONE_MATCH, ifNoneMatch);
7575
return headers;

src/main/java/com/emc/object/s3/request/PutObjectRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Map<String, List<Object>> getHeaders() {
7272
if (ifModifiedSince != null)
7373
RestUtil.putSingle(headers, RestUtil.HEADER_IF_MODIFIED_SINCE, RestUtil.headerFormat(ifModifiedSince));
7474
if (ifUnmodifiedSince != null)
75-
RestUtil.putSingle(headers, RestUtil.HEADER_IF_UNMODIFIED_SINE, RestUtil.headerFormat(ifUnmodifiedSince));
75+
RestUtil.putSingle(headers, RestUtil.HEADER_IF_UNMODIFIED_SINCE, RestUtil.headerFormat(ifUnmodifiedSince));
7676
if (ifMatch != null) RestUtil.putSingle(headers, RestUtil.HEADER_IF_MATCH, ifMatch);
7777
if (ifNoneMatch != null) RestUtil.putSingle(headers, RestUtil.HEADER_IF_NONE_MATCH, ifNoneMatch);
7878
if (acl != null) headers.putAll(acl.toHeaders());

src/main/java/com/emc/object/util/RestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class RestUtil {
5454
public static final String HEADER_IF_MATCH = "If-Match";
5555
public static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
5656
public static final String HEADER_IF_NONE_MATCH = "If-None-Match";
57-
public static final String HEADER_IF_UNMODIFIED_SINE = "If-Unmodified-Since";
57+
public static final String HEADER_IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
5858
public static final String HEADER_LAST_MODIFIED = "Last-Modified";
5959
public static final String HEADER_RANGE = "Range";
6060
public static final String HEADER_USER_AGENT = "User-Agent";

src/test/java/com/emc/object/s3/S3JerseyClientTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,16 @@ public void testPreSignedUrl() throws Exception {
21142114
url.toString());
21152115
}
21162116

2117+
@Test
2118+
public void testPreSignedUrlWithChinese() throws Exception {
2119+
S3Client tempClient = new S3JerseyClient(new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
2120+
.withIdentity("stu").withSecretKey("/QcPo5pEvQh7EOHKs2XjzCARrt7HokZhlpdGKbHs"));
2121+
URL url = tempClient.getPresignedUrl("test-bucket", "解析依頼C1B068.txt", new Date(1500998758000L));
2122+
Assert.assertEquals("https://test-bucket.s3.amazonaws.com/%E8%A7%A3%E6%9E%90%E4%BE%9D%E9%A0%BCC1B068.txt" +
2123+
"?AWSAccessKeyId=stu&Expires=1500998758&Signature=AjZv1TlZgGqlbNsLiYKFkV6gaqg%3D",
2124+
url.toString());
2125+
}
2126+
21172127
@Test
21182128
public void testStaleReadsAllowed() throws Exception {
21192129
// there's no way to test the result, so if no error is returned, assume success
@@ -2304,6 +2314,17 @@ public void run() {
23042314
Assert.assertTrue(Math.abs(Math.round(faultRate * (float) requests) - failures.get()) <= requests / 10); // within 10%
23052315
}
23062316

2317+
@Test
2318+
public void testCifsEcs() {
2319+
String key = "_$folder$";
2320+
2321+
PutObjectRequest request = new PutObjectRequest(getTestBucket(), key, new byte[0]);
2322+
// for some stupid reason, Jersey always uses chunked transfer with "identity" content-encoding
2323+
request.withObjectMetadata(new S3ObjectMetadata().withContentEncoding("identity"));
2324+
client.putObject(request);
2325+
Assert.assertNotNull(client.getObjectMetadata(getTestBucket(), key));
2326+
}
2327+
23072328
protected void assertAclEquals(AccessControlList acl1, AccessControlList acl2) {
23082329
Assert.assertEquals(acl1.getOwner(), acl2.getOwner());
23092330
Assert.assertEquals(acl1.getGrants(), acl2.getGrants());

src/test/java/com/emc/object/s3/S3MetadataSearchTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public S3Client createS3Client() throws Exception {
2525
}
2626

2727
private final MetadataSearchKey[] bucketMetadataSearchKeys = new MetadataSearchKey[] {
28+
new MetadataSearchKey("ObjectName", MetadataSearchDatatype.string),
2829
new MetadataSearchKey("x-amz-meta-datetime1", MetadataSearchDatatype.datetime),
2930
new MetadataSearchKey("x-amz-meta-decimal1", MetadataSearchDatatype.decimal),
3031
new MetadataSearchKey("x-amz-meta-integer1", MetadataSearchDatatype.integer),
31-
new MetadataSearchKey("x-amz-meta-string1", MetadataSearchDatatype.string),
32+
new MetadataSearchKey("x-amz-meta-string1", MetadataSearchDatatype.string)
3233
};
3334

3435
@Override
@@ -95,13 +96,11 @@ public int compare(MetadataSearchKey o1, MetadataSearchKey o2) {
9596

9697
@Test
9798
public void testObjectName() throws Exception {
98-
String bucket = "name-test";
99-
100-
QueryObjectsRequest request = new QueryObjectsRequest(bucket)
99+
QueryObjectsRequest request = new QueryObjectsRequest(getTestBucket())
101100
.withQuery("ObjectName>''");
102101
QueryObjectsResult result = client.queryObjects(request);
103102

104-
Assert.assertEquals(bucket, result.getBucketName());
103+
Assert.assertEquals(getTestBucket(), result.getBucketName());
105104
}
106105

107106
@Test

0 commit comments

Comments
 (0)