34
34
import software .amazon .awssdk .protocols .json .JsonOperationMetadata ;
35
35
import software .amazon .awssdk .retries .api .RetryStrategy ;
36
36
import software .amazon .awssdk .services .querytojsoncompatible .internal .QueryToJsonCompatibleServiceClientConfigurationBuilder ;
37
+ import software .amazon .awssdk .services .querytojsoncompatible .internal .ServiceVersionUserAgent ;
37
38
import software .amazon .awssdk .services .querytojsoncompatible .model .APostOperationRequest ;
38
39
import software .amazon .awssdk .services .querytojsoncompatible .model .APostOperationResponse ;
39
40
import software .amazon .awssdk .services .querytojsoncompatible .model .InvalidInputException ;
@@ -53,7 +54,7 @@ final class DefaultQueryToJsonCompatibleClient implements QueryToJsonCompatibleC
53
54
private static final Logger log = Logger .loggerFor (DefaultQueryToJsonCompatibleClient .class );
54
55
55
56
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata .builder ()
56
- .serviceProtocol (AwsServiceProtocol .AWS_JSON ).build ();
57
+ .serviceProtocol (AwsServiceProtocol .AWS_JSON ).build ();
57
58
58
59
private final SyncClientHandler clientHandler ;
59
60
@@ -63,7 +64,8 @@ final class DefaultQueryToJsonCompatibleClient implements QueryToJsonCompatibleC
63
64
64
65
protected DefaultQueryToJsonCompatibleClient (SdkClientConfiguration clientConfiguration ) {
65
66
this .clientHandler = new AwsSyncClientHandler (clientConfiguration );
66
- this .clientConfiguration = clientConfiguration .toBuilder ().option (SdkClientOption .SDK_CLIENT , this ).build ();
67
+ this .clientConfiguration = clientConfiguration .toBuilder ().option (SdkClientOption .SDK_CLIENT , this )
68
+ .option (SdkClientOption .API_METADATA , ServiceVersionUserAgent .USER_AGENT ).build ();
67
69
this .protocolFactory = init (AwsJsonProtocolFactory .builder ()).build ();
68
70
}
69
71
@@ -89,45 +91,45 @@ protected DefaultQueryToJsonCompatibleClient(SdkClientConfiguration clientConfig
89
91
*/
90
92
@ Override
91
93
public APostOperationResponse aPostOperation (APostOperationRequest aPostOperationRequest ) throws InvalidInputException ,
92
- AwsServiceException , SdkClientException , QueryToJsonCompatibleException {
94
+ AwsServiceException , SdkClientException , QueryToJsonCompatibleException {
93
95
JsonOperationMetadata operationMetadata = JsonOperationMetadata .builder ().hasStreamingSuccessResponse (false )
94
- .isPayloadJson (true ).build ();
96
+ .isPayloadJson (true ).build ();
95
97
96
98
HttpResponseHandler <APostOperationResponse > responseHandler = protocolFactory .createResponseHandler (operationMetadata ,
97
- APostOperationResponse ::builder );
99
+ APostOperationResponse ::builder );
98
100
Function <String , Optional <ExceptionMetadata >> exceptionMetadataMapper = errorCode -> {
99
101
if (errorCode == null ) {
100
102
return Optional .empty ();
101
103
}
102
104
switch (errorCode ) {
103
- case "InvalidInput" :
104
- return Optional .of (ExceptionMetadata .builder ().errorCode ("InvalidInput" ).httpStatusCode (400 )
105
- .exceptionBuilderSupplier (InvalidInputException ::builder ).build ());
106
- default :
107
- return Optional .empty ();
105
+ case "InvalidInput" :
106
+ return Optional .of (ExceptionMetadata .builder ().errorCode ("InvalidInput" ).httpStatusCode (400 )
107
+ .exceptionBuilderSupplier (InvalidInputException ::builder ).build ());
108
+ default :
109
+ return Optional .empty ();
108
110
}
109
111
};
110
112
HttpResponseHandler <AwsServiceException > errorResponseHandler = createErrorResponseHandler (protocolFactory ,
111
- operationMetadata , exceptionMetadataMapper );
113
+ operationMetadata , exceptionMetadataMapper );
112
114
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration (aPostOperationRequest , this .clientConfiguration );
113
115
List <MetricPublisher > metricPublishers = resolveMetricPublishers (clientConfiguration , aPostOperationRequest
114
- .overrideConfiguration ().orElse (null ));
116
+ .overrideConfiguration ().orElse (null ));
115
117
MetricCollector apiCallMetricCollector = metricPublishers .isEmpty () ? NoOpMetricCollector .create () : MetricCollector
116
- .create ("ApiCall" );
118
+ .create ("ApiCall" );
117
119
try {
118
120
apiCallMetricCollector .reportMetric (CoreMetric .SERVICE_ID , "QueryToJsonCompatibleService" );
119
121
apiCallMetricCollector .reportMetric (CoreMetric .OPERATION_NAME , "APostOperation" );
120
122
String hostPrefix = "{StringMember}-foo." ;
121
123
HostnameValidator .validateHostnameCompliant (aPostOperationRequest .stringMember (), "StringMember" ,
122
- "aPostOperationRequest" );
124
+ "aPostOperationRequest" );
123
125
String resolvedHostExpression = String .format ("%s-foo." , aPostOperationRequest .stringMember ());
124
126
125
127
return clientHandler .execute (new ClientExecutionParams <APostOperationRequest , APostOperationResponse >()
126
- .withOperationName ("APostOperation" ).withProtocolMetadata (protocolMetadata )
127
- .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
128
- .hostPrefixExpression (resolvedHostExpression ).withRequestConfiguration (clientConfiguration )
129
- .withInput (aPostOperationRequest ).withMetricCollector (apiCallMetricCollector )
130
- .withMarshaller (new APostOperationRequestMarshaller (protocolFactory )));
128
+ .withOperationName ("APostOperation" ).withProtocolMetadata (protocolMetadata )
129
+ .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
130
+ .hostPrefixExpression (resolvedHostExpression ).withRequestConfiguration (clientConfiguration )
131
+ .withInput (aPostOperationRequest ).withMetricCollector (apiCallMetricCollector )
132
+ .withMarshaller (new APostOperationRequestMarshaller (protocolFactory )));
131
133
} finally {
132
134
metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
133
135
}
@@ -139,7 +141,7 @@ public final String serviceName() {
139
141
}
140
142
141
143
private static List <MetricPublisher > resolveMetricPublishers (SdkClientConfiguration clientConfiguration ,
142
- RequestOverrideConfiguration requestOverrideConfiguration ) {
144
+ RequestOverrideConfiguration requestOverrideConfiguration ) {
143
145
List <MetricPublisher > publishers = null ;
144
146
if (requestOverrideConfiguration != null ) {
145
147
publishers = requestOverrideConfiguration .metricPublishers ();
@@ -154,7 +156,7 @@ private static List<MetricPublisher> resolveMetricPublishers(SdkClientConfigurat
154
156
}
155
157
156
158
private HttpResponseHandler <AwsServiceException > createErrorResponseHandler (BaseAwsJsonProtocolFactory protocolFactory ,
157
- JsonOperationMetadata operationMetadata , Function <String , Optional <ExceptionMetadata >> exceptionMetadataMapper ) {
159
+ JsonOperationMetadata operationMetadata , Function <String , Optional <ExceptionMetadata >> exceptionMetadataMapper ) {
158
160
return protocolFactory .createErrorResponseHandler (operationMetadata , exceptionMetadataMapper );
159
161
}
160
162
@@ -188,7 +190,7 @@ private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request,
188
190
return configuration .build ();
189
191
}
190
192
QueryToJsonCompatibleServiceClientConfigurationBuilder serviceConfigBuilder = new QueryToJsonCompatibleServiceClientConfigurationBuilder (
191
- configuration );
193
+ configuration );
192
194
for (SdkPlugin plugin : plugins ) {
193
195
plugin .configureClient (serviceConfigBuilder );
194
196
}
@@ -198,8 +200,8 @@ private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request,
198
200
199
201
private <T extends BaseAwsJsonProtocolFactory .Builder <T >> T init (T builder ) {
200
202
return builder .clientConfiguration (clientConfiguration )
201
- .defaultServiceExceptionSupplier (QueryToJsonCompatibleException ::builder ).protocol (AwsJsonProtocol .AWS_JSON )
202
- .protocolVersion ("1.1" ).hasAwsQueryCompatible (true );
203
+ .defaultServiceExceptionSupplier (QueryToJsonCompatibleException ::builder ).protocol (AwsJsonProtocol .AWS_JSON )
204
+ .protocolVersion ("1.1" ).hasAwsQueryCompatible (true );
203
205
}
204
206
205
207
@ Override
0 commit comments