|
43 | 43 | import software.amazon.awssdk.codegen.poet.PoetExtensions;
|
44 | 44 | import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
|
45 | 45 | import software.amazon.awssdk.core.SdkResponse;
|
| 46 | +import software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler; |
46 | 47 | import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
|
47 | 48 | import software.amazon.awssdk.core.http.HttpResponseHandler;
|
48 | 49 | import software.amazon.awssdk.core.internal.protocol.json.VoidJsonUnmarshaller;
|
@@ -112,51 +113,20 @@ public CodeBlock responseHandler(IntermediateModel model, OperationModel opModel
|
112 | 113 |
|
113 | 114 | // TODO remove this once kinesis supports CBOR for event streaming
|
114 | 115 | String protocolFactory = opModel.hasEventStreamOutput() ? "jsonProtocolFactory" : "protocolFactory";
|
115 |
| - CodeBlock.Builder builder = CodeBlock |
116 |
| - .builder() |
117 |
| - .add("\n\n$T<$T> responseHandler = $L.createResponseHandler(new $T()" + |
118 |
| - " .withPayloadJson($L)" + |
119 |
| - " .withHasStreamingSuccessResponse($L), new $T());", |
120 |
| - HttpResponseHandler.class, |
121 |
| - pojoResponseType, |
122 |
| - protocolFactory, |
123 |
| - JsonOperationMetadata.class, |
124 |
| - !opModel.getHasBlobMemberAsPayload(), |
125 |
| - opModel.hasStreamingOutput(), |
126 |
| - unmarshaller); |
| 116 | + CodeBlock.Builder builder = CodeBlock.builder(); |
127 | 117 | if (opModel.hasEventStreamOutput()) {
|
128 |
| - builder.add("\n\n$T<$T> voidResponseHandler = $L.createResponseHandler(new $T()" + |
129 |
| - " .withPayloadJson(false)" + |
130 |
| - " .withHasStreamingSuccessResponse(true), new $T());", |
| 118 | + responseHandlersForEventStreaming(opModel, unmarshaller, pojoResponseType, protocolFactory, builder); |
| 119 | + } else { |
| 120 | + builder.add("\n\n$T<$T> responseHandler = $L.createResponseHandler(new $T()" + |
| 121 | + " .withPayloadJson($L)" + |
| 122 | + " .withHasStreamingSuccessResponse($L), new $T());", |
131 | 123 | HttpResponseHandler.class,
|
132 |
| - SdkResponse.class, |
| 124 | + pojoResponseType, |
133 | 125 | protocolFactory,
|
134 | 126 | JsonOperationMetadata.class,
|
135 |
| - VoidJsonUnmarshaller.class); |
136 |
| - EventStreamUtils eventStreamUtils = EventStreamUtils.create(poetExtensions, opModel); |
137 |
| - ClassName eventStreamBaseClass = eventStreamUtils.eventStreamBaseClass(); |
138 |
| - builder |
139 |
| - .add("\n\n$T<$T> eventResponseHandler = $L.createResponseHandler(new $T()" + |
140 |
| - " .withPayloadJson($L)" + |
141 |
| - " .withHasStreamingSuccessResponse($L), " |
142 |
| - + "$T.builder()", |
143 |
| - HttpResponseHandler.class, |
144 |
| - WildcardTypeName.subtypeOf(eventStreamBaseClass), |
145 |
| - protocolFactory, |
146 |
| - JsonOperationMetadata.class, |
147 |
| - true, |
148 |
| - false, |
149 |
| - ClassName.get(EventStreamTaggedUnionJsonUnmarshaller.class)); |
150 |
| - |
151 |
| - eventStreamUtils.getEventStreamMembers() |
152 |
| - .forEach(m -> { |
153 |
| - String unmarshallerClassName = m.getShape().getVariable().getVariableType() + "Unmarshaller"; |
154 |
| - builder.add(".addUnmarshaller(\"$L\", $T.getInstance())\n", |
155 |
| - m.getC2jName(), |
156 |
| - poetExtensions.getTransformClass(unmarshallerClassName)); |
157 |
| - }); |
158 |
| - builder.add(".defaultUnmarshaller((in) -> $T.UNKNOWN)\n" |
159 |
| - + ".build());\n", eventStreamUtils.eventStreamBaseClass()); |
| 127 | + !opModel.getHasBlobMemberAsPayload(), |
| 128 | + opModel.hasStreamingOutput(), |
| 129 | + unmarshaller); |
160 | 130 | }
|
161 | 131 | return builder.build();
|
162 | 132 | }
|
@@ -375,4 +345,56 @@ private ClassName baseExceptionClassName(IntermediateModel model) {
|
375 | 345 |
|
376 | 346 | return ClassName.get(exceptionPath, model.getSdkModeledExceptionBaseClassName());
|
377 | 347 | }
|
| 348 | + |
| 349 | + |
| 350 | + /** |
| 351 | + * Add responseHandlers for event streaming operations |
| 352 | + */ |
| 353 | + private void responseHandlersForEventStreaming(OperationModel opModel, ClassName unmarshaller, TypeName pojoResponseType, |
| 354 | + String protocolFactory, CodeBlock.Builder builder) { |
| 355 | + builder.add("\n\n$T<$T> responseHandler = new $T($L.createResponseHandler(new $T()" + |
| 356 | + " .withPayloadJson($L)" + |
| 357 | + " .withHasStreamingSuccessResponse($L), new $T()));", |
| 358 | + HttpResponseHandler.class, |
| 359 | + pojoResponseType, |
| 360 | + AttachHttpMetadataResponseHandler.class, |
| 361 | + protocolFactory, |
| 362 | + JsonOperationMetadata.class, |
| 363 | + !opModel.getHasBlobMemberAsPayload(), |
| 364 | + opModel.hasStreamingOutput(), |
| 365 | + unmarshaller); |
| 366 | + |
| 367 | + builder.add("\n\n$T<$T> voidResponseHandler = $L.createResponseHandler(new $T()" + |
| 368 | + " .withPayloadJson(false)" + |
| 369 | + " .withHasStreamingSuccessResponse(true), new $T());", |
| 370 | + HttpResponseHandler.class, |
| 371 | + SdkResponse.class, |
| 372 | + protocolFactory, |
| 373 | + JsonOperationMetadata.class, |
| 374 | + VoidJsonUnmarshaller.class); |
| 375 | + EventStreamUtils eventStreamUtils = EventStreamUtils.create(poetExtensions, opModel); |
| 376 | + ClassName eventStreamBaseClass = eventStreamUtils.eventStreamBaseClass(); |
| 377 | + builder |
| 378 | + .add("\n\n$T<$T> eventResponseHandler = $L.createResponseHandler(new $T()" + |
| 379 | + " .withPayloadJson($L)" + |
| 380 | + " .withHasStreamingSuccessResponse($L), " |
| 381 | + + "$T.builder()", |
| 382 | + HttpResponseHandler.class, |
| 383 | + WildcardTypeName.subtypeOf(eventStreamBaseClass), |
| 384 | + protocolFactory, |
| 385 | + JsonOperationMetadata.class, |
| 386 | + true, |
| 387 | + false, |
| 388 | + ClassName.get(EventStreamTaggedUnionJsonUnmarshaller.class)); |
| 389 | + |
| 390 | + eventStreamUtils.getEventStreamMembers() |
| 391 | + .forEach(m -> { |
| 392 | + String unmarshallerClassName = m.getShape().getVariable().getVariableType() + "Unmarshaller"; |
| 393 | + builder.add(".addUnmarshaller(\"$L\", $T.getInstance())\n", |
| 394 | + m.getC2jName(), |
| 395 | + poetExtensions.getTransformClass(unmarshallerClassName)); |
| 396 | + }); |
| 397 | + builder.add(".defaultUnmarshaller((in) -> $T.UNKNOWN)\n" |
| 398 | + + ".build());\n", eventStreamUtils.eventStreamBaseClass()); |
| 399 | + } |
378 | 400 | }
|
0 commit comments