1212import org .slf4j .LoggerFactory ;
1313import software .amazon .awssdk .annotations .Generated ;
1414import software .amazon .awssdk .annotations .SdkInternalApi ;
15+ import software .amazon .awssdk .awscore .AwsRequestOverrideConfiguration ;
1516import software .amazon .awssdk .awscore .client .handler .AwsAsyncClientHandler ;
1617import software .amazon .awssdk .awscore .exception .AwsServiceException ;
1718import software .amazon .awssdk .awscore .internal .AwsProtocolMetadata ;
1819import software .amazon .awssdk .awscore .internal .AwsServiceProtocol ;
1920import software .amazon .awssdk .awscore .retry .AwsRetryStrategy ;
21+ import software .amazon .awssdk .core .ApiName ;
2022import software .amazon .awssdk .core .RequestOverrideConfiguration ;
2123import software .amazon .awssdk .core .SdkPlugin ;
2224import software .amazon .awssdk .core .SdkRequest ;
6668import software .amazon .awssdk .services .smithyrpcv2protocol .model .SimpleScalarPropertiesRequest ;
6769import software .amazon .awssdk .services .smithyrpcv2protocol .model .SimpleScalarPropertiesResponse ;
6870import software .amazon .awssdk .services .smithyrpcv2protocol .model .SmithyRpcV2ProtocolException ;
71+ import software .amazon .awssdk .services .smithyrpcv2protocol .model .SmithyRpcV2ProtocolRequest ;
6972import software .amazon .awssdk .services .smithyrpcv2protocol .model .SparseNullsOperationRequest ;
7073import software .amazon .awssdk .services .smithyrpcv2protocol .model .SparseNullsOperationResponse ;
7174import software .amazon .awssdk .services .smithyrpcv2protocol .model .ValidationException ;
@@ -173,7 +176,7 @@ public CompletableFuture<EmptyInputOutputResponse> emptyInputOutput(EmptyInputOu
173176 .withMarshaller (new EmptyInputOutputRequestMarshaller (protocolFactory ))
174177 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
175178 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
176- .withInput (emptyInputOutputRequest ));
179+ .withInput (applyRpcV2CborUserAgent ( emptyInputOutputRequest ) ));
177180 CompletableFuture <EmptyInputOutputResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
178181 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
179182 });
@@ -246,7 +249,7 @@ public CompletableFuture<Float16Response> float16(Float16Request float16Request)
246249 .withProtocolMetadata (protocolMetadata ).withMarshaller (new Float16RequestMarshaller (protocolFactory ))
247250 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
248251 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
249- .withInput (float16Request ));
252+ .withInput (applyRpcV2CborUserAgent ( float16Request ) ));
250253 CompletableFuture <Float16Response > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
251254 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
252255 });
@@ -321,7 +324,7 @@ public CompletableFuture<FractionalSecondsResponse> fractionalSeconds(Fractional
321324 .withMarshaller (new FractionalSecondsRequestMarshaller (protocolFactory ))
322325 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
323326 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
324- .withInput (fractionalSecondsRequest ));
327+ .withInput (applyRpcV2CborUserAgent ( fractionalSecondsRequest ) ));
325328 CompletableFuture <FractionalSecondsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
326329 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
327330 });
@@ -398,7 +401,7 @@ public CompletableFuture<GreetingWithErrorsResponse> greetingWithErrors(Greeting
398401 .withMarshaller (new GreetingWithErrorsRequestMarshaller (protocolFactory ))
399402 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
400403 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
401- .withInput (greetingWithErrorsRequest ));
404+ .withInput (applyRpcV2CborUserAgent ( greetingWithErrorsRequest ) ));
402405 CompletableFuture <GreetingWithErrorsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
403406 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
404407 });
@@ -472,7 +475,7 @@ public CompletableFuture<NoInputOutputResponse> noInputOutput(NoInputOutputReque
472475 .withMarshaller (new NoInputOutputRequestMarshaller (protocolFactory ))
473476 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
474477 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
475- .withInput (noInputOutputRequest ));
478+ .withInput (applyRpcV2CborUserAgent ( noInputOutputRequest ) ));
476479 CompletableFuture <NoInputOutputResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
477480 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
478481 });
@@ -549,7 +552,7 @@ public CompletableFuture<OperationWithDefaultsResponse> operationWithDefaults(
549552 .withMarshaller (new OperationWithDefaultsRequestMarshaller (protocolFactory ))
550553 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
551554 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
552- .withInput (operationWithDefaultsRequest ));
555+ .withInput (applyRpcV2CborUserAgent ( operationWithDefaultsRequest ) ));
553556 CompletableFuture <OperationWithDefaultsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
554557 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
555558 });
@@ -625,7 +628,7 @@ public CompletableFuture<OptionalInputOutputResponse> optionalInputOutput(
625628 .withMarshaller (new OptionalInputOutputRequestMarshaller (protocolFactory ))
626629 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
627630 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
628- .withInput (optionalInputOutputRequest ));
631+ .withInput (applyRpcV2CborUserAgent ( optionalInputOutputRequest ) ));
629632 CompletableFuture <OptionalInputOutputResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
630633 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
631634 });
@@ -700,7 +703,7 @@ public CompletableFuture<RecursiveShapesResponse> recursiveShapes(RecursiveShape
700703 .withMarshaller (new RecursiveShapesRequestMarshaller (protocolFactory ))
701704 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
702705 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
703- .withInput (recursiveShapesRequest ));
706+ .withInput (applyRpcV2CborUserAgent ( recursiveShapesRequest ) ));
704707 CompletableFuture <RecursiveShapesResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
705708 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
706709 });
@@ -776,7 +779,7 @@ public CompletableFuture<RpcV2CborDenseMapsResponse> rpcV2CborDenseMaps(RpcV2Cbo
776779 .withMarshaller (new RpcV2CborDenseMapsRequestMarshaller (protocolFactory ))
777780 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
778781 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
779- .withInput (rpcV2CborDenseMapsRequest ));
782+ .withInput (applyRpcV2CborUserAgent ( rpcV2CborDenseMapsRequest ) ));
780783 CompletableFuture <RpcV2CborDenseMapsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
781784 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
782785 });
@@ -851,7 +854,7 @@ public CompletableFuture<RpcV2CborListsResponse> rpcV2CborLists(RpcV2CborListsRe
851854 .withMarshaller (new RpcV2CborListsRequestMarshaller (protocolFactory ))
852855 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
853856 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
854- .withInput (rpcV2CborListsRequest ));
857+ .withInput (applyRpcV2CborUserAgent ( rpcV2CborListsRequest ) ));
855858 CompletableFuture <RpcV2CborListsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
856859 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
857860 });
@@ -928,7 +931,7 @@ public CompletableFuture<RpcV2CborSparseMapsResponse> rpcV2CborSparseMaps(
928931 .withMarshaller (new RpcV2CborSparseMapsRequestMarshaller (protocolFactory ))
929932 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
930933 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
931- .withInput (rpcV2CborSparseMapsRequest ));
934+ .withInput (applyRpcV2CborUserAgent ( rpcV2CborSparseMapsRequest ) ));
932935 CompletableFuture <RpcV2CborSparseMapsResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
933936 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
934937 });
@@ -1004,7 +1007,7 @@ public CompletableFuture<SimpleScalarPropertiesResponse> simpleScalarProperties(
10041007 .withMarshaller (new SimpleScalarPropertiesRequestMarshaller (protocolFactory ))
10051008 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
10061009 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
1007- .withInput (simpleScalarPropertiesRequest ));
1010+ .withInput (applyRpcV2CborUserAgent ( simpleScalarPropertiesRequest ) ));
10081011 CompletableFuture <SimpleScalarPropertiesResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
10091012 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
10101013 });
@@ -1080,7 +1083,7 @@ public CompletableFuture<SparseNullsOperationResponse> sparseNullsOperation(
10801083 .withMarshaller (new SparseNullsOperationRequestMarshaller (protocolFactory ))
10811084 .withResponseHandler (responseHandler ).withErrorResponseHandler (errorResponseHandler )
10821085 .withRequestConfiguration (clientConfiguration ).withMetricCollector (apiCallMetricCollector )
1083- .withInput (sparseNullsOperationRequest ));
1086+ .withInput (applyRpcV2CborUserAgent ( sparseNullsOperationRequest ) ));
10841087 CompletableFuture <SparseNullsOperationResponse > whenCompleted = executeFuture .whenComplete ((r , e ) -> {
10851088 metricPublishers .forEach (p -> p .publish (apiCallMetricCollector .collect ()));
10861089 });
@@ -1102,6 +1105,15 @@ public final String serviceName() {
11021105 return SERVICE_NAME ;
11031106 }
11041107
1108+ private static <T extends SmithyRpcV2ProtocolRequest > T applyRpcV2CborUserAgent (T request ) {
1109+ Consumer <AwsRequestOverrideConfiguration .Builder > userAgentApplier = b -> b .addApiName (ApiName .builder ()
1110+ .name ("sdk-metrics" ).version ("M" ).build ());
1111+ AwsRequestOverrideConfiguration overrideConfiguration = request .overrideConfiguration ()
1112+ .map (c -> c .toBuilder ().applyMutation (userAgentApplier ).build ())
1113+ .orElse ((AwsRequestOverrideConfiguration .builder ().applyMutation (userAgentApplier ).build ()));
1114+ return (T ) request .toBuilder ().overrideConfiguration (overrideConfiguration ).build ();
1115+ }
1116+
11051117 private <T extends BaseAwsJsonProtocolFactory .Builder <T >> T init (T builder ) {
11061118 return builder .clientConfiguration (clientConfiguration )
11071119 .defaultServiceExceptionSupplier (SmithyRpcV2ProtocolException ::builder )
@@ -1170,4 +1182,4 @@ private HttpResponseHandler<AwsServiceException> createErrorResponseHandler(Base
11701182 public void close () {
11711183 clientHandler .close ();
11721184 }
1173- }
1185+ }
0 commit comments