Skip to content

Commit 54df1dd

Browse files
committed
Fix incorrect marshallerLocationName see #820
1 parent 09b45c5 commit 54df1dd

File tree

2 files changed

+110
-15
lines changed

2 files changed

+110
-15
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/AddShapes.java

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,12 @@ private String findRequestUri(Shape parentShape, Map<String, Shape> allC2jShapes
273273
private String deriveUnmarshallerLocationName(Shape memberShape, String memberName, Member member) {
274274
String locationName;
275275
if (memberShape.getListMember() != null && memberShape.isFlattened()) {
276-
locationName = memberShape.getListMember().getLocationName() == null ?
277-
member.getLocationName() : memberShape.getListMember().getLocationName();
276+
locationName = deriveLocationNameForListMember(memberShape, member);
278277
} else {
279278
locationName = member.getLocationName();
280279
}
281280

282-
if (locationName != null && !locationName.trim().isEmpty()) {
281+
if (StringUtils.isNotBlank(locationName)) {
283282
return locationName;
284283
}
285284

@@ -288,21 +287,47 @@ private String deriveUnmarshallerLocationName(Shape memberShape, String memberNa
288287

289288
private String deriveMarshallerLocationName(Shape memberShape, String memberName, Member member, String protocol) {
290289
String queryName = member.getQueryName();
291-
if (queryName != null && !queryName.trim().isEmpty()) {
290+
291+
if (StringUtils.isNotBlank(queryName)) {
292292
return queryName;
293+
}
294+
295+
String locationName;
296+
297+
if (Protocol.EC2.getValue().equalsIgnoreCase(protocol)) {
298+
locationName = deriveLocationNameForEc2(member);
299+
} else if (memberShape.getListMember() != null && memberShape.isFlattened()) {
300+
locationName = deriveLocationNameForListMember(memberShape, member);
293301
} else {
294-
String locationName = memberShape.getListMember() != null && memberShape.isFlattened() && !protocol.equals("ec2") ?
295-
memberShape.getListMember().getLocationName() : member.getLocationName();
296-
if (locationName != null && !locationName.trim().isEmpty()) {
297-
if (protocol.equals(Protocol.EC2.getValue())) {
298-
return StringUtils.upperCase(locationName.substring(0, 1)) +
299-
locationName.substring(1);
300-
}
301-
return locationName;
302-
} else {
303-
return memberName;
304-
}
302+
locationName = member.getLocationName();
303+
}
304+
305+
if (StringUtils.isNotBlank(locationName)) {
306+
return locationName;
307+
}
308+
309+
return memberName;
310+
}
311+
312+
private String deriveLocationNameForEc2(Member member) {
313+
String locationName = member.getLocationName();
314+
315+
if (StringUtils.isNotBlank(locationName)) {
316+
return StringUtils.upperCase(locationName.substring(0, 1)) +
317+
locationName.substring(1);
318+
}
319+
320+
return null;
321+
}
322+
323+
private String deriveLocationNameForListMember(Shape memberShape, Member member) {
324+
String locationName = memberShape.getListMember().getLocationName();
325+
326+
if (StringUtils.isNotBlank(locationName)) {
327+
return locationName;
305328
}
329+
330+
return member.getLocationName();
306331
}
307332

308333
private void fillContainerTypeMemberMetadata(Map<String, Shape> c2jShapes,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName;
20+
21+
import org.junit.AfterClass;
22+
import org.junit.BeforeClass;
23+
import org.junit.Test;
24+
import software.amazon.awssdk.core.sync.RequestBody;
25+
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse;
26+
import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload;
27+
import software.amazon.awssdk.services.s3.model.CompletedPart;
28+
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse;
29+
import software.amazon.awssdk.services.s3.model.UploadPartResponse;
30+
31+
public class UploadMultiplePartIntegrationTest extends S3IntegrationTestBase {
32+
33+
private static final String BUCKET = temporaryBucketName(UploadMultiplePartIntegrationTest.class);
34+
35+
private static final String KEY = "uploadpart";
36+
37+
@BeforeClass
38+
public static void setupFixture() {
39+
createBucket(BUCKET);
40+
}
41+
42+
@AfterClass
43+
public static void tearDownFixture() {
44+
deleteBucketAndAllContents(BUCKET);
45+
}
46+
47+
@Test
48+
public void uploadMultiplePart() {
49+
CreateMultipartUploadResponse multipartUpload = s3.createMultipartUpload(b ->
50+
b.bucket(BUCKET).key(KEY));
51+
long length = "helloworld".getBytes().length;
52+
UploadPartResponse uploadPartResponse =
53+
s3.uploadPart(b -> b.bucket(BUCKET).key(KEY)
54+
.uploadId(multipartUpload.uploadId())
55+
.partNumber(1)
56+
.contentLength(length), RequestBody.fromString("helloworld"));
57+
58+
String etag = uploadPartResponse.eTag();
59+
60+
CompleteMultipartUploadResponse completeMultipartUploadResponse =
61+
s3.completeMultipartUpload(b -> b.bucket(BUCKET).key(KEY).uploadId(multipartUpload.uploadId())
62+
.multipartUpload(CompletedMultipartUpload.builder()
63+
.parts(CompletedPart.builder().
64+
eTag(etag).partNumber(1).build())
65+
.build()).build());
66+
67+
assertThat(completeMultipartUploadResponse).isNotNull();
68+
}
69+
70+
}

0 commit comments

Comments
 (0)