Skip to content

Commit 735632f

Browse files
committed
AWS/Query and EC2 marshaller support.
1 parent 716acc5 commit 735632f

File tree

46 files changed

+1149
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1149
-358
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,24 @@ private ParameterHttpMapping generateParameterHttpMapping(Shape parentShape,
221221
ParameterHttpMapping mapping = new ParameterHttpMapping();
222222

223223
Shape memberShape = allC2jShapes.get(member.getShape());
224-
225224
mapping.withLocation(Location.forValue(member.getLocation()))
226-
.withPayload(member.isPayload()).withStreaming(member.isStreaming())
227-
.withFlattened(member.isFlattened() || memberShape.isFlattened())
228-
.withUnmarshallLocationName(deriveUnmarshallerLocationName(memberName, member))
229-
.withMarshallLocationName(
230-
deriveMarshallerLocationName(memberName, member, protocol))
231-
.withIsGreedy(isGreedy(parentShape, allC2jShapes, mapping));
225+
.withPayload(member.isPayload()).withStreaming(member.isStreaming())
226+
.withFlattened(isFlattened(member, protocol, memberShape))
227+
.withUnmarshallLocationName(deriveUnmarshallerLocationName(memberName, member))
228+
.withMarshallLocationName(
229+
deriveMarshallerLocationName(memberShape, memberName, member, protocol))
230+
.withIsGreedy(isGreedy(parentShape, allC2jShapes, mapping));
232231

233232
return mapping;
234233
}
235234

235+
private boolean isFlattened(Member member, String protocol, Shape memberShape) {
236+
return member.isFlattened()
237+
|| memberShape.isFlattened()
238+
// EC2 lists are always flattened
239+
|| (memberShape.getListMember() != null && protocol.equalsIgnoreCase("ec2"));
240+
}
241+
236242
/**
237243
* @param parentShape Shape containing the member in question.
238244
* @param allC2jShapes All shapes in the service model.
@@ -277,12 +283,13 @@ private String deriveUnmarshallerLocationName(String memberName, Member member)
277283
return memberName;
278284
}
279285

280-
private String deriveMarshallerLocationName(String memberName, Member member, String protocol) {
281-
final String queryName = member.getQueryName();
286+
private String deriveMarshallerLocationName(Shape memberShape, String memberName, Member member, String protocol) {
287+
String queryName = member.getQueryName();
282288
if (queryName != null && !queryName.trim().isEmpty()) {
283289
return queryName;
284290
} else {
285-
final String locationName = member.getLocationName();
291+
String locationName = memberShape.getListMember() != null && memberShape.isFlattened() && !protocol.equals("ec2") ?
292+
memberShape.getListMember().getLocationName() : member.getLocationName();
286293
if (locationName != null && !locationName.trim().isEmpty()) {
287294
if (protocol.equals(Protocol.EC2.getValue())) {
288295
return StringUtils.upperCase(locationName.substring(0, 1)) +

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/MarshallerGeneratorTasks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
2929
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
3030
import software.amazon.awssdk.codegen.model.intermediate.Metadata;
31+
import software.amazon.awssdk.codegen.model.intermediate.Protocol;
3132
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
3233
import software.amazon.awssdk.codegen.model.intermediate.ShapeType;
3334
import software.amazon.awssdk.codegen.poet.transform.MarshallerSpec;
@@ -67,7 +68,7 @@ private boolean shouldGenerate(ShapeModel shapeModel) {
6768
}
6869

6970
private Stream<GeneratorTask> createTask(String javaShapeName, ShapeModel shapeModel) throws Exception {
70-
if (metadata.isJsonProtocol()) {
71+
if (metadata.isJsonProtocol() || metadata.getProtocol() == Protocol.QUERY || metadata.getProtocol() == Protocol.EC2) {
7172
return ShapeType.Request == shapeModel.getShapeType() ?
7273
Stream.of(createPoetGeneratorTask(new MarshallerSpec(model, shapeModel))) :
7374
Stream.empty();

codegen/src/main/java/software/amazon/awssdk/codegen/internal/Utils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ public static ShapeMarshaller createInputShapeMarshaller(ServiceMetadata service
314314
marshaller.setXmlNameSpaceUri(xmlNamespace.getUri());
315315
}
316316
}
317-
if (!StringUtils.isEmpty(service.getTargetPrefix()) && Metadata.isNotRestProtocol(service.getProtocol())) {
318-
marshaller.setTarget(service.getTargetPrefix() + "." + operation.getName());
317+
if (Metadata.isNotRestProtocol(service.getProtocol())) {
318+
marshaller.setTarget(StringUtils.isEmpty(service.getTargetPrefix()) ?
319+
operation.getName() :
320+
service.getTargetPrefix() + "." + operation.getName());
319321
}
320322
return marshaller;
321323

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public TypeSpec poetSpec() {
9494
.addMethods(operations())
9595
.addMethod(closeMethod())
9696
.addMethods(protocolSpec.additionalMethods())
97+
.addFields(protocolSpec.additionalFields())
9798
.addMethod(protocolSpec.initProtocolFactory(model));
9899

99100
// Kinesis doesn't support CBOR for STS yet so need another protocol factory for JSON

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import software.amazon.awssdk.codegen.poet.client.specs.JsonProtocolSpec;
4343
import software.amazon.awssdk.codegen.poet.client.specs.ProtocolSpec;
4444
import software.amazon.awssdk.codegen.poet.client.specs.QueryXmlProtocolSpec;
45+
import software.amazon.awssdk.codegen.poet.client.specs.XmlProtocolSpec;
4546
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
4647
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
4748
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
@@ -76,6 +77,8 @@ public TypeSpec poetSpec() {
7677
.addField(SdkClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL)
7778
.addMethod(constructor())
7879
.addMethod(nameMethod())
80+
.addFields(protocolSpec.additionalFields())
81+
.addMethods(protocolSpec.additionalMethods())
7982
.addMethods(operations());
8083

8184
protocolSpec.createErrorResponseHandler().ifPresent(classBuilder::addMethod);
@@ -185,8 +188,9 @@ private MethodSpec closeMethod() {
185188
static ProtocolSpec getProtocolSpecs(PoetExtensions poetExtensions, Protocol protocol) {
186189
switch (protocol) {
187190
case QUERY:
188-
case REST_XML:
189191
return new QueryXmlProtocolSpec(poetExtensions);
192+
case REST_XML:
193+
return new XmlProtocolSpec(poetExtensions);
190194
case EC2:
191195
return new Ec2ProtocolSpec(poetExtensions);
192196
case AWS_JSON:

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/ProtocolSpec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ default Class<? extends SyncClientHandler> getClientHandlerClass() {
5656
default List<MethodSpec> additionalMethods() {
5757
return new ArrayList<>();
5858
}
59+
60+
default List<FieldSpec> additionalFields() {
61+
return new ArrayList<>();
62+
}
5963
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryXmlProtocolSpec.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package software.amazon.awssdk.codegen.poet.client.specs;
1717

18+
import static java.util.Collections.singletonList;
19+
1820
import com.squareup.javapoet.ClassName;
1921
import com.squareup.javapoet.CodeBlock;
2022
import com.squareup.javapoet.FieldSpec;
@@ -30,6 +32,7 @@
3032
import software.amazon.awssdk.awscore.exception.AwsServiceException;
3133
import software.amazon.awssdk.awscore.http.response.DefaultErrorResponseHandler;
3234
import software.amazon.awssdk.awscore.http.response.StaxResponseHandler;
35+
import software.amazon.awssdk.awscore.protocol.query.AwsQueryProtocolFactory;
3336
import software.amazon.awssdk.awscore.protocol.xml.StandardErrorUnmarshaller;
3437
import software.amazon.awssdk.awscore.protocol.xml.StaxOperationMetadata;
3538
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
@@ -58,16 +61,21 @@ public QueryXmlProtocolSpec(PoetExtensions poetExtensions) {
5861

5962
@Override
6063
public FieldSpec protocolFactory(IntermediateModel model) {
64+
return FieldSpec.builder(AwsQueryProtocolFactory.class, "protocolFactory")
65+
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build();
66+
}
6167

62-
return FieldSpec.builder(listOfUnmarshallersType, "exceptionUnmarshallers")
63-
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
64-
.build();
68+
@Override
69+
public List<FieldSpec> additionalFields() {
70+
return singletonList(FieldSpec.builder(listOfUnmarshallersType, "exceptionUnmarshallers")
71+
.addModifiers(Modifier.PRIVATE)
72+
.build());
6573
}
6674

6775
@Override
6876
public MethodSpec initProtocolFactory(IntermediateModel model) {
6977
MethodSpec.Builder methodSpec = MethodSpec.methodBuilder("init")
70-
.returns(listOfUnmarshallersType)
78+
.returns(AwsQueryProtocolFactory.class)
7179
.addModifiers(Modifier.PRIVATE);
7280

7381
methodSpec.addStatement("$T<$T> unmarshallers = new $T<>()", List.class, unmarshallerType, ArrayList.class);
@@ -76,7 +84,8 @@ public MethodSpec initProtocolFactory(IntermediateModel model) {
7684
getErrorUnmarshallerClass(model),
7785
poetExtensions.getModelClass(model.getSdkModeledExceptionBaseClassName()))
7886
.build());
79-
methodSpec.addStatement("return $N", "unmarshallers");
87+
methodSpec.addStatement("this.exceptionUnmarshallers = unmarshallers");
88+
methodSpec.addStatement("return new $T()", AwsQueryProtocolFactory.class);
8089

8190
return methodSpec.build();
8291
}
@@ -132,12 +141,12 @@ public CodeBlock executionHandler(OperationModel opModel) {
132141
"errorResponseHandler",
133142
opModel.getInput().getVariableName());
134143
if (opModel.hasStreamingInput()) {
135-
return codeBlock.add(".withMarshaller(new $T(new $T(), requestBody)));",
144+
return codeBlock.add(".withMarshaller(new $T(new $T(protocolFactory), requestBody)));",
136145
ParameterizedTypeName.get(ClassName.get(StreamingRequestMarshaller.class), requestType),
137146
marshaller)
138147
.build();
139148
}
140-
return codeBlock.add(".withMarshaller(new $T()) $L);", marshaller,
149+
return codeBlock.add(".withMarshaller(new $T(protocolFactory)) $L);", marshaller,
141150
opModel.hasStreamingOutput() ? ", responseTransformer" : "").build();
142151
}
143152

@@ -150,7 +159,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
150159
String asyncRequestBody = opModel.hasStreamingInput() ? ".withAsyncRequestBody(requestBody)"
151160
: "";
152161
return CodeBlock.builder().add("\n\nreturn clientHandler.execute(new $T<$T, $T>()\n" +
153-
".withMarshaller(new $T())" +
162+
".withMarshaller(new $T(protocolFactory))" +
154163
".withResponseHandler(responseHandler)" +
155164
".withErrorResponseHandler($N)\n" +
156165
asyncRequestBody +

0 commit comments

Comments
 (0)