diff --git a/.changes/next-release/removal-AWSSDKforJavav2Codegenerator-673e0fe.json b/.changes/next-release/removal-AWSSDKforJavav2Codegenerator-673e0fe.json new file mode 100644 index 000000000000..3b3e5393934f --- /dev/null +++ b/.changes/next-release/removal-AWSSDKforJavav2Codegenerator-673e0fe.json @@ -0,0 +1,6 @@ +{ + "type": "removal", + "category": "AWS SDK for Java v2 Codegenerator", + "contributor": "", + "description": "Remove `useSraAuth` setting from customization config." +} diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java b/codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java index 515a8460aeb8..19257ae86aa9 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java @@ -287,11 +287,6 @@ public class CustomizationConfig { */ private boolean requiredTraitValidationEnabled = false; - /** - * Whether SRA based auth logic should be used. - */ - private boolean useSraAuth = true; - /** * Whether to generate auth scheme params based on endpoint params. */ @@ -834,16 +829,6 @@ public void setRequiredTraitValidationEnabled(boolean requiredTraitValidationEna this.requiredTraitValidationEnabled = requiredTraitValidationEnabled; } - public void setUseSraAuth(boolean useSraAuth) { - this.useSraAuth = useSraAuth; - } - - // TODO(post-sra-identity-auth): Remove this customization and all related switching logic, keeping only the - // useSraAuth==true branch going forward. - public boolean useSraAuth() { - return useSraAuth; - } - public void setEnableEndpointAuthSchemeParams(boolean enableEndpointAuthSchemeParams) { this.enableEndpointAuthSchemeParams = enableEndpointAuthSchemeParams; } diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecUtils.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecUtils.java index f6ea9e684b59..a5e27fb0b880 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecUtils.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecUtils.java @@ -31,14 +31,12 @@ public final class AuthSchemeSpecUtils { private static final Set DEFAULT_AUTH_SCHEME_PARAMS = setOf("region", "operation"); private final IntermediateModel intermediateModel; - private final boolean useSraAuth; private final Set allowedEndpointAuthSchemeParams; private final boolean allowedEndpointAuthSchemeParamsConfigured; public AuthSchemeSpecUtils(IntermediateModel intermediateModel) { this.intermediateModel = intermediateModel; CustomizationConfig customization = intermediateModel.getCustomizationConfig(); - this.useSraAuth = customization.useSraAuth(); if (customization.getAllowedEndpointAuthSchemeParamsConfigured()) { this.allowedEndpointAuthSchemeParams = Collections.unmodifiableSet( new HashSet<>(customization.getAllowedEndpointAuthSchemeParams())); @@ -49,10 +47,6 @@ public AuthSchemeSpecUtils(IntermediateModel intermediateModel) { } } - public boolean useSraAuth() { - return useSraAuth; - } - private String basePackage() { return intermediateModel.getMetadata().getFullAuthSchemePackageName(); } diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java index 41fd6da98ae2..44d8ce154e72 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java @@ -40,10 +40,8 @@ import javax.lang.model.element.Modifier; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; import software.amazon.awssdk.auth.token.credentials.StaticTokenProvider; import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; import software.amazon.awssdk.awscore.auth.AuthSchemePreferenceResolver; import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; import software.amazon.awssdk.awscore.client.config.AwsClientOption; @@ -51,7 +49,6 @@ import software.amazon.awssdk.codegen.internal.Utils; import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; import software.amazon.awssdk.codegen.model.intermediate.OperationModel; -import software.amazon.awssdk.codegen.model.service.AuthType; import software.amazon.awssdk.codegen.model.service.ClientContextParam; import software.amazon.awssdk.codegen.poet.ClassSpec; import software.amazon.awssdk.codegen.poet.PoetExtension; @@ -72,7 +69,6 @@ import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver; import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.core.endpointdiscovery.providers.DefaultEndpointDiscoveryProviderChain; @@ -81,7 +77,6 @@ import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; import software.amazon.awssdk.http.Protocol; import software.amazon.awssdk.http.ProtocolNegotiation; import software.amazon.awssdk.http.SdkHttpConfigurationOption; @@ -147,15 +142,13 @@ public TypeSpec poetSpec() { .build()); } - if (authSchemeSpecUtils.useSraAuth()) { - builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class), - ClassName.get(String.class), - GENERIC_AUTH_SCHEME_TYPE), - "additionalAuthSchemes") - .addModifiers(PRIVATE, FINAL) - .initializer("new $T<>()", HashMap.class) - .build()); - } + builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class), + ClassName.get(String.class), + GENERIC_AUTH_SCHEME_TYPE), + "additionalAuthSchemes") + .addModifiers(PRIVATE, FINAL) + .initializer("new $T<>()", HashMap.class) + .build()); builder.addMethod(serviceEndpointPrefixMethod()); builder.addMethod(serviceNameMethod()); @@ -164,18 +157,13 @@ public TypeSpec poetSpec() { mergeInternalDefaultsMethod().ifPresent(builder::addMethod); builder.addMethod(finalizeServiceConfigurationMethod()); - if (!authSchemeSpecUtils.useSraAuth()) { - defaultAwsAuthSignerMethod().ifPresent(builder::addMethod); - } builder.addMethod(signingNameMethod()); builder.addMethod(defaultEndpointProviderMethod()); - if (authSchemeSpecUtils.useSraAuth()) { - builder.addMethod(authSchemeProviderMethod()); - builder.addMethod(defaultAuthSchemeProviderMethod()); - builder.addMethod(putAuthSchemeMethod()); - builder.addMethod(authSchemesMethod()); - } + builder.addMethod(authSchemeProviderMethod()); + builder.addMethod(defaultAuthSchemeProviderMethod()); + builder.addMethod(putAuthSchemeMethod()); + builder.addMethod(authSchemesMethod()); if (hasRequestAlgorithmMember(model)) { builder.addMethod(requestChecksumCalculationMethod()); @@ -206,9 +194,6 @@ public TypeSpec poetSpec() { if (AuthUtils.usesBearerAuth(model)) { builder.addMethod(defaultBearerTokenProviderMethod()); - if (!authSchemeSpecUtils.useSraAuth()) { - builder.addMethod(defaultTokenAuthSignerMethod()); - } } addServiceHttpConfigIfNeeded(builder, model); builder.addMethod(invokePluginsMethod()); @@ -249,15 +234,6 @@ private MethodSpec signingNameMethod() { .build(); } - private Optional defaultAwsAuthSignerMethod() { - return awsAuthSignerDefinitionMethodBody().map(body -> MethodSpec.methodBuilder("defaultSigner") - .returns(Signer.class) - .addModifiers(PRIVATE) - .addCode(body) - .build()); - - } - private MethodSpec serviceEndpointPrefixMethod() { return MethodSpec.methodBuilder("serviceEndpointPrefix") .addAnnotation(Override.class) @@ -288,14 +264,10 @@ private MethodSpec mergeServiceDefaultsMethod() { builder.beginControlFlow("return config.merge(c -> "); builder.addCode("c.option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())", SdkClientOption.class); - if (authSchemeSpecUtils.useSraAuth()) { - if (!model.getCustomizationConfig().isEnableEnvironmentBearerToken()) { - builder.addCode(".option($T.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config))", SdkClientOption.class); - } - builder.addCode(".option($T.AUTH_SCHEMES, authSchemes())", SdkClientOption.class); - } else if (defaultAwsAuthSignerMethod().isPresent()) { - builder.addCode(".option($T.SIGNER, defaultSigner())\n", SdkAdvancedClientOption.class); + if (!model.getCustomizationConfig().isEnableEnvironmentBearerToken()) { + builder.addCode(".option($T.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config))", SdkClientOption.class); } + builder.addCode(".option($T.AUTH_SCHEMES, authSchemes())", SdkClientOption.class); builder.addCode(".option($T.CRC32_FROM_COMPRESSED_DATA_ENABLED, $L)\n", SdkClientOption.class, crc32FromCompressedDataEnabled); @@ -309,9 +281,6 @@ private MethodSpec mergeServiceDefaultsMethod() { builder.addCode(".lazyOption($1T.TOKEN_PROVIDER, p -> $2T.toSdkTokenProvider(p.get($1T.TOKEN_IDENTITY_PROVIDER)))", AwsClientOption.class, TokenUtils.class); builder.addCode(".option($T.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider())\n", AwsClientOption.class); - if (!authSchemeSpecUtils.useSraAuth()) { - builder.addCode(".option($T.TOKEN_SIGNER, defaultTokenSigner())", SdkAdvancedClientOption.class); - } } builder.addStatement(""); @@ -323,14 +292,6 @@ private MethodSpec mergeServiceDefaultsMethod() { } private void configureEnvironmentBearerToken(MethodSpec.Builder builder) { - if (!authSchemeSpecUtils.useSraAuth()) { - ValidationEntry entry = ValidationEntry.create(ValidationErrorId.INVALID_CODEGEN_CUSTOMIZATION, - ValidationErrorSeverity.DANGER, - "The enableEnvironmentBearerToken customization requires" - + " the useSraAuth customization but it is disabled."); - - throw ModelInvalidException.fromEntry(entry); - } if (!AuthUtils.usesBearerAuth(model)) { ValidationEntry entry = ValidationEntry.create(ValidationErrorId.INVALID_CODEGEN_CUSTOMIZATION, @@ -409,9 +370,7 @@ private MethodSpec finalizeServiceConfigurationMethod() { List builtInInterceptors = new ArrayList<>(); - if (authSchemeSpecUtils.useSraAuth()) { - builtInInterceptors.add(authSchemeSpecUtils.authSchemeInterceptor()); - } + builtInInterceptors.add(authSchemeSpecUtils.authSchemeInterceptor()); builtInInterceptors.add(endpointRulesSpecUtils.resolverInterceptorName()); builtInInterceptors.add(endpointRulesSpecUtils.requestModifierInterceptorName()); @@ -827,32 +786,6 @@ private CodeBlock serviceSpecificHttpConfigMethodBody(String serviceDefaultFqcn, return builder.build(); } - private Optional awsAuthSignerDefinitionMethodBody() { - AuthType authType = model.getMetadata().getAuthType(); - switch (authType) { - case V4: - return Optional.of(v4SignerDefinitionMethodBody()); - case S3: - case S3V4: - return Optional.of(s3SignerDefinitionMethodBody()); - case BEARER: - case NONE: - return Optional.empty(); - default: - throw new UnsupportedOperationException("Unsupported signer type: " + authType); - } - } - - private CodeBlock v4SignerDefinitionMethodBody() { - return CodeBlock.of("return $T.create();", Aws4Signer.class); - } - - - private CodeBlock s3SignerDefinitionMethodBody() { - return CodeBlock.of("return $T.create();\n", - ClassName.get("software.amazon.awssdk.auth.signer", "AwsS3V4Signer")); - } - private MethodSpec defaultEndpointProviderMethod() { return MethodSpec.methodBuilder("defaultEndpointProvider") .addModifiers(PRIVATE) @@ -961,14 +894,6 @@ private MethodSpec defaultBearerTokenProviderMethod() { .build(); } - private MethodSpec defaultTokenAuthSignerMethod() { - return MethodSpec.methodBuilder("defaultTokenSigner") - .returns(Signer.class) - .addModifiers(PRIVATE) - .addStatement("return $T.create()", BearerTokenSigner.class) - .build(); - } - private MethodSpec authSchemesMethod() { TypeName returns = ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class), ParameterizedTypeName.get(ClassName.get(AuthScheme.class), @@ -1133,21 +1058,7 @@ private MethodSpec validateClientOptionsMethod() { .addParameter(SdkClientConfiguration.class, "c") .returns(void.class); - if (AuthUtils.usesAwsAuth(model) && !authSchemeSpecUtils.useSraAuth()) { - builder.addStatement("$T.notNull(c.option($T.SIGNER), $S)", - Validate.class, - SdkAdvancedClientOption.class, - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - } - if (AuthUtils.usesBearerAuth(model)) { - if (!authSchemeSpecUtils.useSraAuth()) { - builder.addStatement("$T.notNull(c.option($T.TOKEN_SIGNER), $S)", - Validate.class, - SdkAdvancedClientOption.class, - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' " - + "must be configured in the client builder."); - } builder.addStatement("$T.notNull(c.option($T.TOKEN_IDENTITY_PROVIDER), $S)", Validate.class, AwsClientOption.class, diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java index 1d7a0df25ff6..539d5df35a43 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java @@ -25,7 +25,6 @@ import static javax.lang.model.element.Modifier.STATIC; import static software.amazon.awssdk.codegen.internal.Constant.EVENT_PUBLISHER_PARAM_NAME; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.addS3ArnableFieldCode; -import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.applySignerOverrideMethod; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.transformServiceId; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.updateSdkClientConfigurationMethod; import static software.amazon.awssdk.codegen.poet.client.SyncClientClass.addRequestModifierCode; @@ -54,7 +53,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; import software.amazon.awssdk.awscore.client.config.AwsClientOption; import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; @@ -68,11 +66,9 @@ import software.amazon.awssdk.codegen.model.intermediate.MemberModel; import software.amazon.awssdk.codegen.model.intermediate.OperationModel; import software.amazon.awssdk.codegen.model.intermediate.ShapeModel; -import software.amazon.awssdk.codegen.model.service.AuthType; import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.PoetUtils; import software.amazon.awssdk.codegen.poet.StaticImport; -import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeSpecUtils; import software.amazon.awssdk.codegen.poet.client.specs.ProtocolSpec; import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils; import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper; @@ -104,7 +100,6 @@ public final class AsyncClientClass extends AsyncClientInterface { private final ProtocolSpec protocolSpec; private final ClassName serviceClientConfigurationClassName; private final ServiceClientConfigurationUtils configurationUtils; - private final boolean useSraAuth; private boolean hasScheduledExecutor; public AsyncClientClass(GeneratorTaskParams dependencies) { @@ -114,7 +109,6 @@ public AsyncClientClass(GeneratorTaskParams dependencies) { this.className = poetExtensions.getClientClass(model.getMetadata().getAsyncClient()); this.protocolSpec = getProtocolSpecs(poetExtensions, model); this.serviceClientConfigurationClassName = new PoetExtension(model).getServiceConfigClass(); - this.useSraAuth = new AuthSchemeSpecUtils(model).useSraAuth(); this.configurationUtils = new ServiceClientConfigurationUtils(model); } @@ -173,12 +167,6 @@ protected void addAdditionalMethods(TypeSpec.Builder type) { .addMethod(protocolSpec.initProtocolFactory(model)) .addMethod(resolveMetricPublishersMethod()); - if (!useSraAuth) { - if (model.containsRequestSigners() || model.containsRequestEventStreams() || hasStreamingV4AuthOperations()) { - type.addMethod(applySignerOverrideMethod(poetExtensions, model)); - type.addMethod(isSignerOverriddenOnClientMethod()); - } - } type.addMethod(ClientClassUtils.updateRetryStrategyClientConfigurationMethod()); type.addMethod(updateSdkClientConfigurationMethod(configurationUtils.serviceClientConfigurationBuilderClassName(), model)); @@ -368,14 +356,6 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation "pair"); } - if (!useSraAuth) { - if (shouldUseAsyncWithBodySigner(opModel)) { - builder.addCode(applyAsyncWithBodyV4SignerOverride(opModel)); - } else { - builder.addCode(ClientClassUtils.callApplySignerOverrideMethod(opModel)); - } - } - builder.addCode(protocolSpec.responseHandler(model, opModel)); protocolSpec.errorResponseHandler(opModel).ifPresent(builder::addCode); builder.addCode(eventToByteBufferPublisher(opModel)); @@ -594,46 +574,6 @@ private MethodSpec resolveMetricPublishersMethod() { return methodBuilder.build(); } - private boolean shouldUseAsyncWithBodySigner(OperationModel opModel) { - if (opModel.getInputShape().getRequestSignerClassFqcn() != null) { - return false; - } - - AuthType authTypeForOperation = opModel.getAuthType(); - - if (authTypeForOperation == null) { - authTypeForOperation = model.getMetadata().getAuthType(); - } - - return authTypeForOperation == AuthType.V4 && opModel.hasStreamingInput(); - } - - private CodeBlock applyAsyncWithBodyV4SignerOverride(OperationModel opModel) { - return CodeBlock.builder() - .beginControlFlow("if (!isSignerOverridden($N))", "clientConfiguration") - .addStatement("$1L = applySignerOverride($1L, $2T.create())", - opModel.getInput().getVariableName(), AsyncAws4Signer.class) - .endControlFlow() - .build(); - } - - private MethodSpec isSignerOverriddenOnClientMethod() { - String clientConfigurationName = "clientConfiguration"; - - return MethodSpec.methodBuilder("isSignerOverridden") - .returns(boolean.class) - .addModifiers(PRIVATE, STATIC) - .addParameter(SdkClientConfiguration.class, clientConfigurationName) - .addStatement("return $T.TRUE.equals($N.option($T.$N))", Boolean.class, clientConfigurationName, - SdkClientOption.class, "SIGNER_OVERRIDDEN") - .build(); - } - - private boolean hasStreamingV4AuthOperations() { - return model.getOperations().values().stream() - .anyMatch(this::shouldUseAsyncWithBodySigner); - } - private void addScheduledExecutorIfNeeded(Builder classBuilder) { if (!hasScheduledExecutor) { classBuilder.addField(FieldSpec.builder(ClassName.get(ScheduledExecutorService.class), "executorService") diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java index 1052f91b6575..5736ddbecaf5 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java @@ -22,7 +22,6 @@ import static javax.lang.model.element.Modifier.STATIC; import static software.amazon.awssdk.codegen.poet.PoetUtils.classNameFromFqcn; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.addS3ArnableFieldCode; -import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.applySignerOverrideMethod; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.transformServiceId; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.updateSdkClientConfigurationMethod; @@ -55,7 +54,6 @@ import software.amazon.awssdk.codegen.model.service.PreClientExecutionRequestCustomizer; import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.PoetUtils; -import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeSpecUtils; import software.amazon.awssdk.codegen.poet.client.specs.Ec2ProtocolSpec; import software.amazon.awssdk.codegen.poet.client.specs.JsonProtocolSpec; import software.amazon.awssdk.codegen.poet.client.specs.ProtocolSpec; @@ -85,7 +83,6 @@ public class SyncClientClass extends SyncClientInterface { private final ProtocolSpec protocolSpec; private final ClassName serviceClientConfigurationClassName; private final ServiceClientConfigurationUtils configurationUtils; - private final boolean useSraAuth; public SyncClientClass(GeneratorTaskParams taskParams) { super(taskParams.getModel()); @@ -95,7 +92,6 @@ public SyncClientClass(GeneratorTaskParams taskParams) { this.protocolSpec = getProtocolSpecs(poetExtensions, model); this.serviceClientConfigurationClassName = new PoetExtension(model).getServiceConfigClass(); this.configurationUtils = new ServiceClientConfigurationUtils(model); - this.useSraAuth = new AuthSchemeSpecUtils(model).useSraAuth(); } @Override @@ -131,10 +127,6 @@ protected void addFields(TypeSpec.Builder type) { @Override protected void addAdditionalMethods(TypeSpec.Builder type) { - if (!useSraAuth && model.containsRequestSigners()) { - type.addMethod(applySignerOverrideMethod(poetExtensions, model)); - } - model.getEndpointOperation().ifPresent( o -> type.addField(EndpointDiscoveryRefreshCache.class, "endpointDiscoveryCache", PRIVATE)); @@ -255,9 +247,6 @@ private MethodSpec traditionalMethod(OperationModel opModel) { .addAnnotation(Override.class); addRequestModifierCode(opModel, model).ifPresent(method::addCode); - if (!useSraAuth) { - method.addCode(ClientClassUtils.callApplySignerOverrideMethod(opModel)); - } method.addCode(protocolSpec.responseHandler(model, opModel)); protocolSpec.errorResponseHandler(opModel).ifPresent(method::addCode); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java index 8e1afb25e8e0..b9b69d9bd8a0 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java @@ -41,10 +41,8 @@ import software.amazon.awssdk.codegen.model.intermediate.ShapeModel; import software.amazon.awssdk.codegen.model.intermediate.ShapeType; import software.amazon.awssdk.codegen.poet.PoetExtension; -import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeSpecUtils; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait; -import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait; import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait; import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils; import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper; @@ -69,12 +67,10 @@ public class JsonProtocolSpec implements ProtocolSpec { private final PoetExtension poetExtensions; private final IntermediateModel model; - private final boolean useSraAuth; public JsonProtocolSpec(PoetExtension poetExtensions, IntermediateModel model) { this.poetExtensions = poetExtensions; this.model = model; - this.useSraAuth = new AuthSchemeSpecUtils(model).useSraAuth(); } @Override @@ -229,10 +225,6 @@ public CodeBlock executionHandler(OperationModel opModel) { .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - codeBlock.add(NoneAuthTypeRequestTrait.create(opModel)); - } - codeBlock.add(RequestCompressionTrait.create(opModel, model)); if (opModel.hasStreamingOutput()) { @@ -310,10 +302,6 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - builder.add(NoneAuthTypeRequestTrait.create(opModel)); - } - if (opModel.hasStreamingOutput()) { builder.add(".withAsyncResponseTransformer(asyncResponseTransformer)"); } diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryProtocolSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryProtocolSpec.java index 4bf7d45d5f9c..bab1f29e7281 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryProtocolSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryProtocolSpec.java @@ -28,10 +28,8 @@ import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; import software.amazon.awssdk.codegen.model.intermediate.OperationModel; import software.amazon.awssdk.codegen.poet.PoetExtension; -import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeSpecUtils; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait; -import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait; import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait; import software.amazon.awssdk.core.async.AsyncResponseTransformer; import software.amazon.awssdk.core.client.handler.ClientExecutionParams; @@ -43,12 +41,10 @@ public class QueryProtocolSpec implements ProtocolSpec { protected final PoetExtension poetExtensions; protected final IntermediateModel intermediateModel; - protected final boolean useSraAuth; public QueryProtocolSpec(IntermediateModel intermediateModel, PoetExtension poetExtensions) { this.intermediateModel = intermediateModel; this.poetExtensions = poetExtensions; - this.useSraAuth = new AuthSchemeSpecUtils(intermediateModel).useSraAuth(); } @Override @@ -123,10 +119,6 @@ public CodeBlock executionHandler(OperationModel opModel) { .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - codeBlock.add(NoneAuthTypeRequestTrait.create(opModel)); - } - codeBlock.add(RequestCompressionTrait.create(opModel, intermediateModel)); if (opModel.hasStreamingOutput()) { codeBlock.add(".withResponseTransformer(responseTransformer)"); @@ -166,10 +158,6 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - builder.add(NoneAuthTypeRequestTrait.create(opModel)); - } - builder.add(RequestCompressionTrait.create(opModel, intermediateModel)); if (opModel.hasStreamingOutput()) { diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/XmlProtocolSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/XmlProtocolSpec.java index 1a081497f020..dbbd33f4276f 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/XmlProtocolSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/XmlProtocolSpec.java @@ -36,7 +36,6 @@ import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait; import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait; -import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait; import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait; import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils; import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper; @@ -139,10 +138,6 @@ public CodeBlock executionHandler(OperationModel opModel) { .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - codeBlock.add(NoneAuthTypeRequestTrait.create(opModel)); - } - codeBlock.add(RequestCompressionTrait.create(opModel, model)); s3ArnableFields(opModel, model).ifPresent(codeBlock::add); @@ -222,10 +217,6 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper .add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel)) .add(HttpChecksumTrait.create(opModel)); - if (!useSraAuth) { - builder.add(NoneAuthTypeRequestTrait.create(opModel)); - } - builder.add(RequestCompressionTrait.create(opModel, model)); s3ArnableFields(opModel, model).ifPresent(builder::add); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpec.java index 7bac753e88e5..eb73b199556d 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpec.java @@ -36,20 +36,14 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletionException; -import java.util.function.Supplier; import javax.lang.model.element.Modifier; import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.signer.AwsS3V4Signer; -import software.amazon.awssdk.auth.signer.SignerLoader; import software.amazon.awssdk.awscore.AwsExecutionAttribute; import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute; import software.amazon.awssdk.awscore.endpoints.authscheme.EndpointAuthScheme; import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme; import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme; -import software.amazon.awssdk.awscore.util.SignerOverrideUtils; import software.amazon.awssdk.codegen.internal.Utils; -import software.amazon.awssdk.codegen.model.config.customization.EndpointAuthSchemeConfig; import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; import software.amazon.awssdk.codegen.model.intermediate.OperationModel; import software.amazon.awssdk.codegen.model.rules.endpoints.ParameterModel; @@ -73,7 +67,6 @@ import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute; import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.signer.Signer; import software.amazon.awssdk.endpoints.Endpoint; import software.amazon.awssdk.http.SdkHttpRequest; import software.amazon.awssdk.http.auth.aws.scheme.AwsV4AuthScheme; @@ -98,7 +91,6 @@ public class EndpointResolverInterceptorSpec implements ClassSpec { private final PoetExtension poetExtension; private final JmesPathAcceptorGenerator jmesPathGenerator; private final boolean dependsOnHttpAuthAws; - private final boolean useSraAuth; private final boolean multiAuthSigv4a; private final boolean legacyAuthFromEndpointRulesService; @@ -117,7 +109,6 @@ public EndpointResolverInterceptorSpec(IntermediateModel model) { this.dependsOnHttpAuthAws = supportedAuthSchemes.contains(AwsV4AuthScheme.class) || supportedAuthSchemes.contains(AwsV4aAuthScheme.class); - this.useSraAuth = new AuthSchemeSpecUtils(model).useSraAuth(); this.multiAuthSigv4a = new AuthSchemeSpecUtils(model).usesSigV4a(); this.legacyAuthFromEndpointRulesService = new AuthSchemeSpecUtils(model).generateEndpointBasedParams(); } @@ -130,10 +121,6 @@ public TypeSpec poetSpec() { .addAnnotation(SdkInternalApi.class) .addSuperinterface(ExecutionInterceptor.class); - if (!useSraAuth) { - b.addField(endpointAuthSchemeStrategyFieldSpec); - b.addMethod(constructorMethodSpec(endpointAuthSchemeStrategyFieldSpec.name)); - } b.addMethod(modifyRequestMethod(endpointAuthSchemeStrategyFieldSpec.name)); b.addMethod(modifyHttpRequestMethod()); b.addMethod(ruleParams()); @@ -155,10 +142,6 @@ public TypeSpec poetSpec() { b.addMethod(hostPrefixMethod()); - if (!useSraAuth) { - b.addMethod(signerProviderMethod()); - } - endpointParamsKnowledgeIndex.addAccountIdMethodsIfPresent(b); b.addMethod(setMetricValuesMethod()); @@ -245,17 +228,6 @@ private MethodSpec modifyRequestMethod(String endpointAuthSchemeStrategyFieldNam SdkInternalExecutionAttribute.class); b.endControlFlow(); - // For pre SRA client, use Signer as determined by endpoint resolved auth scheme - if (!useSraAuth) { - b.beginControlFlow("if (endpointAuthSchemes != null)"); - b.addStatement("$T chosenAuthScheme = $N.chooseAuthScheme(endpointAuthSchemes)", EndpointAuthScheme.class, - endpointAuthSchemeStrategyFieldName); - b.addStatement("$T<$T> signerProvider = signerProvider(chosenAuthScheme)", Supplier.class, Signer.class); - b.addStatement("result = $T.overrideSignerIfNotOverridden(result, executionAttributes, signerProvider)", - SignerOverrideUtils.class); - b.endControlFlow(); - } - b.addStatement("executionAttributes.putAttribute(SdkInternalExecutionAttribute.RESOLVED_ENDPOINT, endpoint)"); b.addStatement("setMetricValues(endpoint, executionAttributes)"); b.addStatement("return result"); @@ -741,13 +713,11 @@ private MethodSpec authSchemeWithEndpointSignerPropertiesMethod() { method.beginControlFlow("for ($T endpointAuthScheme : endpointAuthSchemes)", EndpointAuthScheme.class); - if (useSraAuth) { - // Don't include signer properties for auth options that don't match our selected auth scheme - method.beginControlFlow("if (!endpointAuthScheme.schemeId()" - + ".equals(selectedAuthScheme.authSchemeOption().schemeId()))"); - method.addStatement("continue"); - method.endControlFlow(); - } + // Don't include signer properties for auth options that don't match our selected auth scheme + method.beginControlFlow("if (!endpointAuthScheme.schemeId()" + + ".equals(selectedAuthScheme.authSchemeOption().schemeId()))"); + method.addStatement("continue"); + method.endControlFlow(); method.addStatement("$T option = selectedAuthScheme.authSchemeOption().toBuilder()", AuthSchemeOption.Builder.class); @@ -858,57 +828,6 @@ private CodeBlock copyS3ExpressEndpointSignerPropertiesToAuth() { return code.build(); } - private MethodSpec signerProviderMethod() { - MethodSpec.Builder builder = MethodSpec.methodBuilder("signerProvider") - .addModifiers(Modifier.PRIVATE) - .addParameter(EndpointAuthScheme.class, "authScheme") - .returns(ParameterizedTypeName.get(Supplier.class, Signer.class)); - - builder.beginControlFlow("switch (authScheme.name())"); - builder.addCode("case $S:", "sigv4"); - if (endpointRulesSpecUtils.isS3() || endpointRulesSpecUtils.isS3Control()) { - builder.addStatement("return $T::create", AwsS3V4Signer.class); - } else { - builder.addStatement("return $T::create", Aws4Signer.class); - } - - builder.addCode("case $S:", "sigv4a"); - if (endpointRulesSpecUtils.isS3() || endpointRulesSpecUtils.isS3Control()) { - builder.addStatement("return $T::getS3SigV4aSigner", SignerLoader.class); - } else { - builder.addStatement("return $T::getSigV4aSigner", SignerLoader.class); - } - - builder.addCode("default:"); - builder.addStatement("break"); - builder.endControlFlow(); - - builder.addStatement("throw $T.create($S + authScheme.name())", - SdkClientException.class, - "Don't know how to create signer for auth scheme: "); - - return builder.build(); - } - - private MethodSpec constructorMethodSpec(String endpointAuthSchemeFieldName) { - MethodSpec.Builder b = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC); - EndpointAuthSchemeConfig endpointAuthSchemeConfig = model.getCustomizationConfig().getEndpointAuthSchemeConfig(); - String factoryLocalVarName = "endpointAuthSchemeStrategyFactory"; - if (endpointAuthSchemeConfig != null && endpointAuthSchemeConfig.getAuthSchemeStrategyFactoryClass() != null) { - b.addStatement("$T $N = new $T()", - endpointRulesSpecUtils.rulesRuntimeClassName("EndpointAuthSchemeStrategyFactory"), - factoryLocalVarName, - PoetUtils.classNameFromFqcn(endpointAuthSchemeConfig.getAuthSchemeStrategyFactoryClass())); - } else { - b.addStatement("$T $N = new $T()", - endpointRulesSpecUtils.rulesRuntimeClassName("EndpointAuthSchemeStrategyFactory"), - factoryLocalVarName, - endpointRulesSpecUtils.rulesRuntimeClassName("DefaultEndpointAuthSchemeStrategyFactory")); - } - b.addStatement("this.$N = $N.endpointAuthSchemeStrategy()", endpointAuthSchemeFieldName, factoryLocalVarName); - return b.build(); - } - private MethodSpec setMetricValuesMethod() { MethodSpec.Builder b = MethodSpec.methodBuilder("setMetricValues") .addModifiers(Modifier.PRIVATE) diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClassTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClassTest.java index 423ae5aba59a..aaf8473430e7 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClassTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClassTest.java @@ -36,101 +36,58 @@ * Validate BaseClientBuilderClass generation. */ public class BaseClientBuilderClassTest { - @Test - public void baseClientBuilderClass() { - validateBaseClientBuilderClassGeneration(restJsonServiceModels(), "test-client-builder-class.java"); - } - - @Test - public void baseClientBuilderClassWithBearerAuth() { - validateBaseClientBuilderClassGeneration(bearerAuthServiceModels(), "test-bearer-auth-client-builder-class.java"); - } - - @Test - public void baseClientBuilderClassWithNoAuthOperation() { - validateBaseClientBuilderClassGeneration(operationWithNoAuth(), "test-no-auth-ops-client-builder-class.java"); - } - - @Test - public void baseClientBuilderClassWithNoAuthService() { - validateBaseClientBuilderClassGeneration(serviceWithNoAuth(), "test-no-auth-service-client-builder-class.java"); - } - - @Test - public void baseClientBuilderClassWithInternalUserAgent() { - validateBaseClientBuilderClassGeneration(internalConfigModels(), "test-client-builder-internal-defaults-class.java"); - } - - @Test - public void baseQueryClientBuilderClass() { - validateBaseClientBuilderClassGeneration(queryServiceModels(), "test-query-client-builder-class.java"); - } - @Test - public void baseClientBuilderClassWithEndpointsAuthParams() { - validateBaseClientBuilderClassGeneration(queryServiceModelsEndpointAuthParamsWithAllowList(), - "test-client-builder-endpoints-auth-params.java"); - } - - @Test - public void syncComposedDefaultClientBuilderClass() { - validateBaseClientBuilderClassGeneration(composedClientJsonServiceModels(), - "test-composed-sync-default-client-builder.java"); - } - @Test void baseClientBuilderClass_sra() { - validateBaseClientBuilderClassGeneration(restJsonServiceModels(), "test-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(restJsonServiceModels(), "test-client-builder-class.java"); } @Test void baseClientBuilderClassWithBearerAuth_sra() { - validateBaseClientBuilderClassGeneration(bearerAuthServiceModels(), "test-bearer-auth-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(bearerAuthServiceModels(), "test-bearer-auth-client-builder-class.java"); } @Test void baseClientBuilderClassWithEnvBearerToken_sra() { validateBaseClientBuilderClassGeneration(envBearerTokenServiceModels(), - "test-env-bearer-token-client-builder-class.java", - true); + "test-env-bearer-token-client-builder-class.java"); } @Test void baseClientBuilderClassWithNoAuthOperation_sra() { - validateBaseClientBuilderClassGeneration(operationWithNoAuth(), "test-no-auth-ops-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(operationWithNoAuth(), "test-no-auth-ops-client-builder-class.java"); } @Test void baseClientBuilderClassWithMultiAuthSigv4a() { - validateBaseClientBuilderClassGeneration(opsWithSigv4a(), "test-multi-auth-sigv4a-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(opsWithSigv4a(), "test-multi-auth-sigv4a-client-builder-class.java"); } @Test void baseClientBuilderClassWithNoAuthService_sra() { - validateBaseClientBuilderClassGeneration(serviceWithNoAuth(), "test-no-auth-service-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(serviceWithNoAuth(), "test-no-auth-service-client-builder-class.java"); } @Test void baseClientBuilderClassWithInternalUserAgent_sra() { - validateBaseClientBuilderClassGeneration(internalConfigModels(), "test-client-builder-internal-defaults-class.java", - true); + validateBaseClientBuilderClassGeneration(internalConfigModels(), "test-client-builder-internal-defaults-class.java"); } @Test void baseQueryClientBuilderClass_sra() { - validateBaseClientBuilderClassGeneration(queryServiceModels(), "test-query-client-builder-class.java", true); + validateBaseClientBuilderClassGeneration(queryServiceModels(), "test-query-client-builder-class.java"); } @Test void baseClientBuilderClassWithEndpointsAuthParams_sra() { validateBaseClientBuilderClassGeneration(queryServiceModelsEndpointAuthParamsWithAllowList(), - "test-client-builder-endpoints-auth-params.java", true); + "test-client-builder-endpoints-auth-params.java"); } @Test void syncComposedDefaultClientBuilderClass_sra() { validateBaseClientBuilderClassGeneration(composedClientJsonServiceModels(), - "test-composed-sync-default-client-builder.java", true); + "test-composed-sync-default-client-builder.java"); } @Test @@ -144,16 +101,6 @@ void baseClientBuilderClassWithH2_usePriorKnowledgeForH2() { } private void validateBaseClientBuilderClassGeneration(IntermediateModel model, String expectedClassName) { - validateBaseClientBuilderClassGeneration(model, expectedClassName, false); - } - - private void validateBaseClientBuilderClassGeneration(IntermediateModel model, String expectedClassName, boolean sra) { - if (sra) { - model.getCustomizationConfig().setUseSraAuth(true); - validateGeneration(BaseClientBuilderClass::new, model, "sra/" + expectedClassName); - } else { - model.getCustomizationConfig().setUseSraAuth(false); - validateGeneration(BaseClientBuilderClass::new, model, expectedClassName); - } + validateGeneration(BaseClientBuilderClass::new, model, "sra/" + expectedClassName); } } diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClassTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClassTest.java index acf6c7093402..ec762d1e326c 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClassTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClassTest.java @@ -39,37 +39,25 @@ public class AsyncClientClassTest { @Test public void asyncClientClassRestJson() { - AsyncClientClass asyncClientClass = createAsyncClientClass(restJsonServiceModels(), false); - assertThat(asyncClientClass, generatesTo("test-json-async-client-class.java")); - - AsyncClientClass sraAsyncClientClass = createAsyncClientClass(restJsonServiceModels(), true); + AsyncClientClass sraAsyncClientClass = createAsyncClientClass(restJsonServiceModels()); assertThat(sraAsyncClientClass, generatesTo("sra/test-json-async-client-class.java")); } @Test public void asyncClientClassQuery() { - AsyncClientClass asyncClientClass = createAsyncClientClass(queryServiceModels(), false); - assertThat(asyncClientClass, generatesTo("test-query-async-client-class.java")); - - AsyncClientClass sraAsyncClientClass = createAsyncClientClass(queryServiceModels(), true); + AsyncClientClass sraAsyncClientClass = createAsyncClientClass(queryServiceModels()); assertThat(sraAsyncClientClass, generatesTo("sra/test-query-async-client-class.java")); } @Test public void asyncClientClassAwsJson() { - AsyncClientClass asyncClientClass = createAsyncClientClass(awsJsonServiceModels(), false); - assertThat(asyncClientClass, generatesTo("test-aws-json-async-client-class.java")); - - AsyncClientClass sraAsyncClientClass = createAsyncClientClass(awsJsonServiceModels(), true); + AsyncClientClass sraAsyncClientClass = createAsyncClientClass(awsJsonServiceModels()); assertThat(sraAsyncClientClass, generatesTo("sra/test-aws-json-async-client-class.java")); } @Test public void asyncClientClassCbor() { - AsyncClientClass asyncClientClass = createAsyncClientClass(cborServiceModels(), false); - assertThat(asyncClientClass, generatesTo("test-cbor-async-client-class.java")); - - AsyncClientClass sraAsyncClientClass = createAsyncClientClass(cborServiceModels(), true); + AsyncClientClass sraAsyncClientClass = createAsyncClientClass(cborServiceModels()); assertThat(sraAsyncClientClass, generatesTo("sra/test-cbor-async-client-class.java")); } @@ -81,10 +69,7 @@ public void asyncClientClassAwsQueryCompatibleJson() { @Test public void asyncClientClassXml() { - AsyncClientClass asyncClientClass = createAsyncClientClass(xmlServiceModels(), false); - assertThat(asyncClientClass, generatesTo("test-xml-async-client-class.java")); - - AsyncClientClass sraAsyncClientClass = createAsyncClientClass(xmlServiceModels(), true); + AsyncClientClass sraAsyncClientClass = createAsyncClientClass(xmlServiceModels()); assertThat(sraAsyncClientClass, generatesTo("sra/test-xml-async-client-class.java")); } @@ -108,7 +93,7 @@ public void asyncClientCustomPackageName() { @Test public void asyncClientClassRpcv2() { - AsyncClientClass asyncClientClass = createAsyncClientClass(rpcv2ServiceModels(), true); + AsyncClientClass asyncClientClass = createAsyncClientClass(rpcv2ServiceModels()); assertThat(asyncClientClass, generatesTo("test-rpcv2-async-client-class.java")); } @@ -120,7 +105,7 @@ public void asyncClientBatchManager() { @Test public void asyncClientWithStreamingUnsignedPayload() { - AsyncClientClass asyncClientClass = createAsyncClientClass(opsWithSigv4a(), false); + AsyncClientClass asyncClientClass = createAsyncClientClass(opsWithSigv4a()); assertThat(asyncClientClass, generatesTo("test-unsigned-payload-trait-async-client-class.java")); } @@ -133,9 +118,4 @@ public void asyncClientWithCustomContextParams() { private AsyncClientClass createAsyncClientClass(IntermediateModel model) { return new AsyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/")); } - - private AsyncClientClass createAsyncClientClass(IntermediateModel model, boolean useSraAuth) { - model.getCustomizationConfig().setUseSraAuth(useSraAuth); - return createAsyncClientClass(model); - } } diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/SyncClientClassTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/SyncClientClassTest.java index 9b3d0ea2fb0f..7a84cf35a019 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/SyncClientClassTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/SyncClientClassTest.java @@ -37,19 +37,13 @@ public class SyncClientClassTest { @Test public void syncClientClassRestJson() { - SyncClientClass syncClientClass = createSyncClientClass(restJsonServiceModels(), false); - assertThat(syncClientClass, generatesTo("test-json-client-class.java")); - - SyncClientClass sraSyncClientClass = createSyncClientClass(restJsonServiceModels(), true); + SyncClientClass sraSyncClientClass = createSyncClientClass(restJsonServiceModels()); assertThat(sraSyncClientClass, generatesTo("sra/test-json-client-class.java")); } @Test public void syncClientClassQuery() { - SyncClientClass syncClientClass = createSyncClientClass(queryServiceModels(), false); - assertThat(syncClientClass, generatesTo("test-query-client-class.java")); - - SyncClientClass sraSyncClientClass = createSyncClientClass(queryServiceModels(), true); + SyncClientClass sraSyncClientClass = createSyncClientClass(queryServiceModels()); assertThat(sraSyncClientClass, generatesTo("sra/test-query-client-class.java")); } @@ -61,11 +55,8 @@ public void syncClientClassAwsQueryCompatibleJson() { @Test public void syncClientClassXml() { - SyncClientClass syncClientClass = createSyncClientClass(xmlServiceModels(), false); - assertThat(syncClientClass, generatesTo("test-xml-client-class.java")); - - SyncClientClass sraSyncClientClass = createSyncClientClass(xmlServiceModels(), true); - assertThat(sraSyncClientClass, generatesTo("sra/test-xml-client-class.java")); + SyncClientClass syncClientClass = createSyncClientClass(xmlServiceModels()); + assertThat(syncClientClass, generatesTo("sra/test-xml-client-class.java")); } @Test @@ -88,13 +79,13 @@ public void syncClientCustomPackageName() { @Test public void syncClientClassRpcV2() { - ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(rpcv2ServiceModels(), true); + ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(rpcv2ServiceModels()); assertThat(syncClientCustomServiceMetaData, generatesTo("test-rpcv2-sync.java")); } @Test public void syncClientClassCbor() { - ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(cborServiceModels(), true); + ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(cborServiceModels()); assertThat(syncClientCustomServiceMetaData, generatesTo("test-cbor-client-class.java")); } @@ -108,11 +99,6 @@ private SyncClientClass createSyncClientClass(IntermediateModel model) { return new SyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/")); } - private SyncClientClass createSyncClientClass(IntermediateModel model, boolean useSraAuth) { - model.getCustomizationConfig().setUseSraAuth(useSraAuth); - return createSyncClientClass(model); - } - @Test public void syncClientClassWithUnsignedPayload() { SyncClientClass syncClientClass = createSyncClientClass(opsWithSigv4a()); diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpecTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpecTest.java index 77c5a44e3203..c31fd4c70690 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpecTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpecTest.java @@ -26,20 +26,12 @@ public class EndpointResolverInterceptorSpecTest { @Test public void endpointResolverInterceptorClass() { - ClassSpec endpointProviderInterceptor = new EndpointResolverInterceptorSpec(getModel(true)); + ClassSpec endpointProviderInterceptor = new EndpointResolverInterceptorSpec(getModel()); assertThat(endpointProviderInterceptor, generatesTo("endpoint-resolve-interceptor.java")); } - // TODO(post-sra-identity-auth): This can be deleted when useSraAuth is removed - @Test - public void endpointResolverInterceptorClass_preSra() { - ClassSpec endpointProviderInterceptor = new EndpointResolverInterceptorSpec(getModel(false)); - assertThat(endpointProviderInterceptor, generatesTo("endpoint-resolve-interceptor-preSra.java")); - } - - private static IntermediateModel getModel(boolean useSraAuth) { + private static IntermediateModel getModel() { IntermediateModel model = ClientTestModels.queryServiceModels(); - model.getCustomizationConfig().setUseSraAuth(useSraAuth); return model; } diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-service-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-service-client-builder-class.java similarity index 77% rename from codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-service-client-builder-class.java rename to codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-service-client-builder-class.java index eb724ba82245..76c1cd2fc7eb 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-service-client-builder-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-service-client-builder-class.java @@ -2,39 +2,43 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Consumer; import software.amazon.awssdk.annotations.Generated; import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.Aws4Signer; +import software.amazon.awssdk.awscore.auth.AuthSchemePreferenceResolver; import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; import software.amazon.awssdk.awscore.client.config.AwsClientOption; import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; import software.amazon.awssdk.core.SdkPlugin; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; import software.amazon.awssdk.http.Protocol; import software.amazon.awssdk.http.ProtocolNegotiation; import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.auth.aws.scheme.AwsV4AuthScheme; +import software.amazon.awssdk.http.auth.scheme.NoAuthAuthScheme; +import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme; import software.amazon.awssdk.identity.spi.IdentityProvider; import software.amazon.awssdk.identity.spi.IdentityProviders; import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; import software.amazon.awssdk.retries.api.RetryStrategy; +import software.amazon.awssdk.services.h2.auth.scheme.H2AuthSchemeProvider; +import software.amazon.awssdk.services.h2.auth.scheme.internal.H2AuthSchemeInterceptor; import software.amazon.awssdk.services.h2.endpoints.H2EndpointProvider; import software.amazon.awssdk.services.h2.endpoints.internal.H2RequestSetEndpointInterceptor; import software.amazon.awssdk.services.h2.endpoints.internal.H2ResolveEndpointInterceptor; import software.amazon.awssdk.services.h2.internal.H2ServiceClientConfigurationBuilder; import software.amazon.awssdk.utils.AttributeMap; import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; /** * Internal base class for {@link DefaultH2ClientBuilder} and {@link DefaultH2AsyncClientBuilder}. @@ -42,6 +46,8 @@ @Generated("software.amazon.awssdk:codegen") @SdkInternalApi abstract class DefaultH2BaseClientBuilder, C> extends AwsDefaultClientBuilder { + private final Map> additionalAuthSchemes = new HashMap<>(); + @Override protected final String serviceEndpointPrefix() { return "h2-service"; @@ -56,7 +62,8 @@ protected final String serviceName() { protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { return config.merge(c -> { c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) + .option(SdkClientOption.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config)) + .option(SdkClientOption.AUTH_SCHEMES, authSchemes()) .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false); }); } @@ -64,6 +71,7 @@ protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfigurati @Override protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { List endpointInterceptors = new ArrayList<>(); + endpointInterceptors.add(new H2AuthSchemeInterceptor()); endpointInterceptors.add(new H2ResolveEndpointInterceptor()); endpointInterceptors.add(new H2RequestSetEndpointInterceptor()); ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); @@ -103,10 +111,6 @@ protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientCon return builder.build(); } - private Signer defaultSigner() { - return Aws4Signer.create(); - } - @Override protected final String signingName() { return "h2-service"; @@ -116,6 +120,38 @@ private H2EndpointProvider defaultEndpointProvider() { return H2EndpointProvider.defaultProvider(); } + public B authSchemeProvider(H2AuthSchemeProvider authSchemeProvider) { + clientConfiguration.option(SdkClientOption.AUTH_SCHEME_PROVIDER, authSchemeProvider); + return thisBuilder(); + } + + private H2AuthSchemeProvider defaultAuthSchemeProvider(SdkClientConfiguration config) { + AuthSchemePreferenceResolver authSchemePreferenceProvider = AuthSchemePreferenceResolver.builder() + .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) + .profileName(config.option(SdkClientOption.PROFILE_NAME)).build(); + List preferences = authSchemePreferenceProvider.resolveAuthSchemePreference(); + if (!preferences.isEmpty()) { + return H2AuthSchemeProvider.defaultProvider(preferences); + } + return H2AuthSchemeProvider.defaultProvider(); + } + + @Override + public B putAuthScheme(AuthScheme authScheme) { + additionalAuthSchemes.put(authScheme.schemeId(), authScheme); + return thisBuilder(); + } + + private Map> authSchemes() { + Map> schemes = new HashMap<>(2 + this.additionalAuthSchemes.size()); + AwsV4AuthScheme awsV4AuthScheme = AwsV4AuthScheme.create(); + schemes.put(awsV4AuthScheme.schemeId(), awsV4AuthScheme); + NoAuthAuthScheme noAuthAuthScheme = NoAuthAuthScheme.create(); + schemes.put(noAuthAuthScheme.schemeId(), noAuthAuthScheme); + schemes.putAll(this.additionalAuthSchemes); + return schemes; + } + @Override protected final AttributeMap serviceHttpConfig() { AttributeMap result = AttributeMap.empty(); @@ -168,7 +204,5 @@ private List internalPlugins(SdkClientConfiguration config) { } protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); } } diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java similarity index 77% rename from codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java rename to codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java index a9dcec96847e..d3fc4996de98 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/sra/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java @@ -2,38 +2,42 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Consumer; import software.amazon.awssdk.annotations.Generated; import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.Aws4Signer; +import software.amazon.awssdk.awscore.auth.AuthSchemePreferenceResolver; import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; import software.amazon.awssdk.awscore.client.config.AwsClientOption; import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; import software.amazon.awssdk.core.SdkPlugin; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; import software.amazon.awssdk.http.Protocol; import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.auth.aws.scheme.AwsV4AuthScheme; +import software.amazon.awssdk.http.auth.scheme.NoAuthAuthScheme; +import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme; import software.amazon.awssdk.identity.spi.IdentityProvider; import software.amazon.awssdk.identity.spi.IdentityProviders; import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; import software.amazon.awssdk.retries.api.RetryStrategy; +import software.amazon.awssdk.services.h2.auth.scheme.H2AuthSchemeProvider; +import software.amazon.awssdk.services.h2.auth.scheme.internal.H2AuthSchemeInterceptor; import software.amazon.awssdk.services.h2.endpoints.H2EndpointProvider; import software.amazon.awssdk.services.h2.endpoints.internal.H2RequestSetEndpointInterceptor; import software.amazon.awssdk.services.h2.endpoints.internal.H2ResolveEndpointInterceptor; import software.amazon.awssdk.services.h2.internal.H2ServiceClientConfigurationBuilder; import software.amazon.awssdk.utils.AttributeMap; import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; /** * Internal base class for {@link DefaultH2ClientBuilder} and {@link DefaultH2AsyncClientBuilder}. @@ -41,6 +45,8 @@ @Generated("software.amazon.awssdk:codegen") @SdkInternalApi abstract class DefaultH2BaseClientBuilder, C> extends AwsDefaultClientBuilder { + private final Map> additionalAuthSchemes = new HashMap<>(); + @Override protected final String serviceEndpointPrefix() { return "h2-service"; @@ -55,7 +61,8 @@ protected final String serviceName() { protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { return config.merge(c -> { c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) + .option(SdkClientOption.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config)) + .option(SdkClientOption.AUTH_SCHEMES, authSchemes()) .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false); }); } @@ -63,6 +70,7 @@ protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfigurati @Override protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { List endpointInterceptors = new ArrayList<>(); + endpointInterceptors.add(new H2AuthSchemeInterceptor()); endpointInterceptors.add(new H2ResolveEndpointInterceptor()); endpointInterceptors.add(new H2RequestSetEndpointInterceptor()); ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); @@ -102,10 +110,6 @@ protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientCon return builder.build(); } - private Signer defaultSigner() { - return Aws4Signer.create(); - } - @Override protected final String signingName() { return "h2-service"; @@ -115,6 +119,38 @@ private H2EndpointProvider defaultEndpointProvider() { return H2EndpointProvider.defaultProvider(); } + public B authSchemeProvider(H2AuthSchemeProvider authSchemeProvider) { + clientConfiguration.option(SdkClientOption.AUTH_SCHEME_PROVIDER, authSchemeProvider); + return thisBuilder(); + } + + private H2AuthSchemeProvider defaultAuthSchemeProvider(SdkClientConfiguration config) { + AuthSchemePreferenceResolver authSchemePreferenceProvider = AuthSchemePreferenceResolver.builder() + .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) + .profileName(config.option(SdkClientOption.PROFILE_NAME)).build(); + List preferences = authSchemePreferenceProvider.resolveAuthSchemePreference(); + if (!preferences.isEmpty()) { + return H2AuthSchemeProvider.defaultProvider(preferences); + } + return H2AuthSchemeProvider.defaultProvider(); + } + + @Override + public B putAuthScheme(AuthScheme authScheme) { + additionalAuthSchemes.put(authScheme.schemeId(), authScheme); + return thisBuilder(); + } + + private Map> authSchemes() { + Map> schemes = new HashMap<>(2 + this.additionalAuthSchemes.size()); + AwsV4AuthScheme awsV4AuthScheme = AwsV4AuthScheme.create(); + schemes.put(awsV4AuthScheme.schemeId(), awsV4AuthScheme); + NoAuthAuthScheme noAuthAuthScheme = NoAuthAuthScheme.create(); + schemes.put(noAuthAuthScheme.schemeId(), noAuthAuthScheme); + schemes.putAll(this.additionalAuthSchemes); + return schemes; + } + @Override protected final AttributeMap serviceHttpConfig() { AttributeMap result = AttributeMap.empty(); @@ -166,7 +202,5 @@ private List internalPlugins(SdkClientConfiguration config) { } protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); } } diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-bearer-auth-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-bearer-auth-client-builder-class.java deleted file mode 100644 index c7932ab9f7c6..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-bearer-auth-client-builder-class.java +++ /dev/null @@ -1,175 +0,0 @@ -package software.amazon.awssdk.services.json; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider; -import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultJsonClientBuilder} and {@link DefaultJsonAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultJsonBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "json-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Json"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new JsonResolveEndpointInterceptor()); - endpointInterceptors.add(new JsonRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/json/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_JSON_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlJson") - .serviceProfileProperty("json_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - return builder.build(); - } - - @Override - protected final String signingName() { - return "json-service"; - } - - private JsonEndpointProvider defaultEndpointProvider() { - return JsonEndpointProvider.defaultProvider(); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-class.java deleted file mode 100644 index 2eca7dfdcf2c..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-class.java +++ /dev/null @@ -1,331 +0,0 @@ -package software.amazon.awssdk.services.json; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.MyServiceHttpConfig; -import software.amazon.MyServiceRetryPolicy; -import software.amazon.MyServiceRetryStrategy; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.codegen.poet.plugins.InternalTestPlugin1; -import software.amazon.awssdk.codegen.poet.plugins.InternalTestPlugin2; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculation; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.endpoints.JsonClientContextParams; -import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider; -import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.AttributeMap; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultJsonClientBuilder} and {@link DefaultJsonAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultJsonBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "json-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Json"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build()) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new JsonResolveEndpointInterceptor()); - endpointInterceptors.add(new JsonRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/json/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - ServiceConfiguration.Builder serviceConfigBuilder = ((ServiceConfiguration) config - .option(SdkClientOption.SERVICE_CONFIGURATION)).toBuilder(); - serviceConfigBuilder.profileFile(serviceConfigBuilder.profileFileSupplier() != null ? serviceConfigBuilder - .profileFileSupplier() : config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)); - serviceConfigBuilder.profileName(serviceConfigBuilder.profileName() != null ? serviceConfigBuilder.profileName() : config - .option(SdkClientOption.PROFILE_NAME)); - if (serviceConfigBuilder.dualstackEnabled() != null) { - Validate.validState( - config.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED) == null, - "Dualstack has been configured on both ServiceConfiguration and the client/global level. Please limit dualstack configuration to one location."); - } else { - serviceConfigBuilder.dualstackEnabled(config.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)); - } - if (serviceConfigBuilder.fipsModeEnabled() != null) { - Validate.validState( - config.option(AwsClientOption.FIPS_ENDPOINT_ENABLED) == null, - "Fips has been configured on both ServiceConfiguration and the client/global level. Please limit fips configuration to one location."); - } else { - serviceConfigBuilder.fipsModeEnabled(config.option(AwsClientOption.FIPS_ENDPOINT_ENABLED)); - } - if (serviceConfigBuilder.useArnRegionEnabled() != null) { - Validate.validState( - clientContextParams.get(JsonClientContextParams.USE_ARN_REGION) == null, - "UseArnRegion has been configured on both ServiceConfiguration and the client/global level. Please limit UseArnRegion configuration to one location."); - } else { - serviceConfigBuilder.useArnRegionEnabled(clientContextParams.get(JsonClientContextParams.USE_ARN_REGION)); - } - if (serviceConfigBuilder.multiRegionEnabled() != null) { - Validate.validState( - clientContextParams.get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS) == null, - "DisableMultiRegionAccessPoints has been configured on both ServiceConfiguration and the client/global level. Please limit DisableMultiRegionAccessPoints configuration to one location."); - } else if (clientContextParams.get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS) != null) { - serviceConfigBuilder.multiRegionEnabled(!clientContextParams - .get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS)); - } - if (serviceConfigBuilder.pathStyleAccessEnabled() != null) { - Validate.validState( - clientContextParams.get(JsonClientContextParams.FORCE_PATH_STYLE) == null, - "ForcePathStyle has been configured on both ServiceConfiguration and the client/global level. Please limit ForcePathStyle configuration to one location."); - } else { - serviceConfigBuilder.pathStyleAccessEnabled(clientContextParams.get(JsonClientContextParams.FORCE_PATH_STYLE)); - } - if (serviceConfigBuilder.accelerateModeEnabled() != null) { - Validate.validState( - clientContextParams.get(JsonClientContextParams.ACCELERATE) == null, - "Accelerate has been configured on both ServiceConfiguration and the client/global level. Please limit Accelerate configuration to one location."); - } else { - serviceConfigBuilder.accelerateModeEnabled(clientContextParams.get(JsonClientContextParams.ACCELERATE)); - } - Boolean checksumValidationEnabled = serviceConfigBuilder.checksumValidationEnabled(); - if (checksumValidationEnabled != null) { - Validate.validState( - config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION) == null, - "Checksum behavior has been configured on both ServiceConfiguration and the client/global level. Please limit checksum behavior configuration to one location."); - Validate.validState( - config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION) == null, - "Checksum behavior has been configured on both ServiceConfiguration and the client/global level. Please limit checksum behavior configuration to one location."); - if (checksumValidationEnabled) { - config = config.toBuilder() - .option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation.WHEN_SUPPORTED) - .option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation.WHEN_SUPPORTED).build(); - } else { - config = config.toBuilder() - .option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation.WHEN_REQUIRED) - .option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation.WHEN_REQUIRED).build(); - } - } - ServiceConfiguration finalServiceConfig = serviceConfigBuilder.build(); - clientContextParams.put(JsonClientContextParams.USE_ARN_REGION, finalServiceConfig.useArnRegionEnabled()); - clientContextParams.put(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS, - !finalServiceConfig.multiRegionEnabled()); - clientContextParams.put(JsonClientContextParams.FORCE_PATH_STYLE, finalServiceConfig.pathStyleAccessEnabled()); - clientContextParams.put(JsonClientContextParams.ACCELERATE, finalServiceConfig.accelerateModeEnabled()); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED, serviceConfigBuilder.dualstackEnabled()); - builder.option(AwsClientOption.FIPS_ENDPOINT_ENABLED, finalServiceConfig.fipsModeEnabled()); - builder.option(SdkClientOption.RETRY_STRATEGY, MyServiceRetryStrategy.resolveRetryStrategy(config)); - if (builder.option(SdkClientOption.RETRY_STRATEGY) == null) { - builder.option(SdkClientOption.RETRY_POLICY, MyServiceRetryPolicy.resolveRetryPolicy(config)); - } - builder.option(SdkClientOption.SERVICE_CONFIGURATION, finalServiceConfig); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_JSON_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlJson") - .serviceProfileProperty("json_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - SdkClientConfiguration clientConfig = config; - builder.lazyOption(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, c -> resolveRequestChecksumCalculation(clientConfig)); - builder.lazyOption(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, c -> resolveResponseChecksumValidation(clientConfig)); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "json-service"; - } - - private JsonEndpointProvider defaultEndpointProvider() { - return JsonEndpointProvider.defaultProvider(); - } - - public B requestChecksumCalculation(RequestChecksumCalculation requestChecksumCalculation) { - clientConfiguration.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, requestChecksumCalculation); - return thisBuilder(); - } - - public B responseChecksumValidation(ResponseChecksumValidation responseChecksumValidation) { - clientConfiguration.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, responseChecksumValidation); - return thisBuilder(); - } - - public B serviceConfiguration(ServiceConfiguration serviceConfiguration) { - clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION, serviceConfiguration); - return thisBuilder(); - } - - public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) { - serviceConfiguration(serviceConfiguration); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected final AttributeMap serviceHttpConfig() { - AttributeMap result = MyServiceHttpConfig.defaultHttpConfig(); - return result; - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - List internalPlugins = new ArrayList<>(); - internalPlugins.add(new InternalTestPlugin1()); - internalPlugins.add(new InternalTestPlugin2()); - return internalPlugins; - } - - private RequestChecksumCalculation resolveRequestChecksumCalculation(SdkClientConfiguration config) { - RequestChecksumCalculation configuredChecksumCalculation = config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION); - if (configuredChecksumCalculation == null) { - configuredChecksumCalculation = RequestChecksumCalculationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumCalculation(RequestChecksumCalculation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumCalculation; - } - - private ResponseChecksumValidation resolveResponseChecksumValidation(SdkClientConfiguration config) { - ResponseChecksumValidation configuredChecksumValidation = config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION); - if (configuredChecksumValidation == null) { - configuredChecksumValidation = ResponseChecksumValidationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumValidation(ResponseChecksumValidation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumValidation; - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-endpoints-auth-params.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-endpoints-auth-params.java deleted file mode 100644 index 4a8a346f1c76..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-endpoints-auth-params.java +++ /dev/null @@ -1,262 +0,0 @@ -package software.amazon.awssdk.services.query; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointMode; -import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointModeResolver; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculation; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.http.auth.aws.signer.RegionSet; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.query.endpoints.QueryClientContextParams; -import software.amazon.awssdk.services.query.endpoints.QueryEndpointProvider; -import software.amazon.awssdk.services.query.endpoints.internal.QueryRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.query.endpoints.internal.QueryResolveEndpointInterceptor; -import software.amazon.awssdk.services.query.internal.QueryServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultQueryClientBuilder} and {@link DefaultQueryAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultQueryBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "query-service"; - } - - @Override - protected final String serviceName() { - return "Query"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new QueryResolveEndpointInterceptor()); - endpointInterceptors.add(new QueryRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/query/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.option(SdkClientOption.CLIENT_CONTEXT_PARAMS, clientContextParams.build()); - builder.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE, resolveAccountIdEndpointMode(config)); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_QUERY_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlQuery") - .serviceProfileProperty("query_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - SdkClientConfiguration clientConfig = config; - builder.lazyOption(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, c -> resolveRequestChecksumCalculation(clientConfig)); - builder.lazyOption(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, c -> resolveResponseChecksumValidation(clientConfig)); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "query-service"; - } - - private QueryEndpointProvider defaultEndpointProvider() { - return QueryEndpointProvider.defaultProvider(); - } - - public B requestChecksumCalculation(RequestChecksumCalculation requestChecksumCalculation) { - clientConfiguration.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, requestChecksumCalculation); - return thisBuilder(); - } - - public B responseChecksumValidation(ResponseChecksumValidation responseChecksumValidation) { - clientConfiguration.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, responseChecksumValidation); - return thisBuilder(); - } - - public B booleanContextParam(Boolean booleanContextParam) { - clientContextParams.put(QueryClientContextParams.BOOLEAN_CONTEXT_PARAM, booleanContextParam); - return thisBuilder(); - } - - public B stringContextParam(String stringContextParam) { - clientContextParams.put(QueryClientContextParams.STRING_CONTEXT_PARAM, stringContextParam); - return thisBuilder(); - } - - public B accountIdEndpointMode(AccountIdEndpointMode accountIdEndpointMode) { - clientConfiguration.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE, accountIdEndpointMode); - return thisBuilder(); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - QueryServiceClientConfigurationBuilder serviceConfigBuilder = new QueryServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - private AccountIdEndpointMode resolveAccountIdEndpointMode(SdkClientConfiguration config) { - AccountIdEndpointMode configuredMode = config.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE); - if (configuredMode == null) { - configuredMode = AccountIdEndpointModeResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)).defaultMode(AccountIdEndpointMode.PREFERRED) - .resolve(); - } - return configuredMode; - } - - private RequestChecksumCalculation resolveRequestChecksumCalculation(SdkClientConfiguration config) { - RequestChecksumCalculation configuredChecksumCalculation = config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION); - if (configuredChecksumCalculation == null) { - configuredChecksumCalculation = RequestChecksumCalculationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumCalculation(RequestChecksumCalculation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumCalculation; - } - - private ResponseChecksumValidation resolveResponseChecksumValidation(SdkClientConfiguration config) { - ResponseChecksumValidation configuredChecksumValidation = config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION); - if (configuredChecksumValidation == null) { - configuredChecksumValidation = ResponseChecksumValidationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumValidation(ResponseChecksumValidation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumValidation; - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } - - public B sigv4aSigningRegionSet(RegionSet sigv4aSigningRegionSet) { - clientConfiguration.option(AwsClientOption.AWS_SIGV4A_SIGNING_REGION_SET, - sigv4aSigningRegionSet == null ? Collections.emptySet() : sigv4aSigningRegionSet.asSet()); - return thisBuilder(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-internal-defaults-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-internal-defaults-class.java deleted file mode 100644 index 4f1e5bbd8e0d..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-internal-defaults-class.java +++ /dev/null @@ -1,171 +0,0 @@ -package software.amazon.awssdk.services.json; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider; -import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultJsonClientBuilder} and {@link DefaultJsonAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultJsonBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "json-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Json"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false); - }); - } - - @Override - protected final SdkClientConfiguration mergeInternalDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.INTERNAL_USER_AGENT, "md/foobar"); - c.option(SdkClientOption.DEFAULT_RETRY_MODE, RetryMode.STANDARD); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new JsonResolveEndpointInterceptor()); - endpointInterceptors.add(new JsonRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/json/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_JSON_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlJson") - .serviceProfileProperty("json_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "json-service"; - } - - private JsonEndpointProvider defaultEndpointProvider() { - return JsonEndpointProvider.defaultProvider(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-composed-sync-default-client-builder.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-composed-sync-default-client-builder.java deleted file mode 100644 index 778b676c4975..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-composed-sync-default-client-builder.java +++ /dev/null @@ -1,250 +0,0 @@ -package software.amazon.awssdk.services.json; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculation; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.endpoints.JsonClientContextParams; -import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider; -import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultJsonClientBuilder} and {@link DefaultJsonAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultJsonBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "json-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Json"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build()) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new JsonResolveEndpointInterceptor()); - endpointInterceptors.add(new JsonRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/json/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - ServiceConfiguration.Builder serviceConfigBuilder = ((ServiceConfiguration) config - .option(SdkClientOption.SERVICE_CONFIGURATION)).toBuilder(); - serviceConfigBuilder.profileFile(serviceConfigBuilder.profileFileSupplier() != null ? serviceConfigBuilder - .profileFileSupplier() : config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)); - serviceConfigBuilder.profileName(serviceConfigBuilder.profileName() != null ? serviceConfigBuilder.profileName() : config - .option(SdkClientOption.PROFILE_NAME)); - ServiceConfiguration finalServiceConfig = serviceConfigBuilder.build(); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.option(SdkClientOption.SERVICE_CONFIGURATION, finalServiceConfig); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_JSON_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlJson") - .serviceProfileProperty("json_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - SdkClientConfiguration clientConfig = config; - builder.lazyOption(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, c -> resolveRequestChecksumCalculation(clientConfig)); - builder.lazyOption(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, c -> resolveResponseChecksumValidation(clientConfig)); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "json-service"; - } - - private JsonEndpointProvider defaultEndpointProvider() { - return JsonEndpointProvider.defaultProvider(); - } - - public B requestChecksumCalculation(RequestChecksumCalculation requestChecksumCalculation) { - clientConfiguration.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, requestChecksumCalculation); - return thisBuilder(); - } - - public B responseChecksumValidation(ResponseChecksumValidation responseChecksumValidation) { - clientConfiguration.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, responseChecksumValidation); - return thisBuilder(); - } - - public B customParameter(Boolean customParameter) { - clientContextParams.put(JsonClientContextParams.CUSTOM_PARAMETER, customParameter); - return thisBuilder(); - } - - public B serviceConfiguration(ServiceConfiguration serviceConfiguration) { - clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION, serviceConfiguration); - return thisBuilder(); - } - - public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) { - serviceConfiguration(serviceConfiguration); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - private RequestChecksumCalculation resolveRequestChecksumCalculation(SdkClientConfiguration config) { - RequestChecksumCalculation configuredChecksumCalculation = config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION); - if (configuredChecksumCalculation == null) { - configuredChecksumCalculation = RequestChecksumCalculationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumCalculation(RequestChecksumCalculation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumCalculation; - } - - private ResponseChecksumValidation resolveResponseChecksumValidation(SdkClientConfiguration config) { - ResponseChecksumValidation configuredChecksumValidation = config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION); - if (configuredChecksumValidation == null) { - configuredChecksumValidation = ResponseChecksumValidationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumValidation(ResponseChecksumValidation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumValidation; - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-ops-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-ops-client-builder-class.java deleted file mode 100644 index 5ec8c0facf9a..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-ops-client-builder-class.java +++ /dev/null @@ -1,189 +0,0 @@ -package software.amazon.awssdk.services.database; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.database.endpoints.DatabaseEndpointProvider; -import software.amazon.awssdk.services.database.endpoints.internal.DatabaseRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.database.endpoints.internal.DatabaseResolveEndpointInterceptor; -import software.amazon.awssdk.services.database.internal.DatabaseServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultDatabaseClientBuilder} and {@link DefaultDatabaseAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultDatabaseBaseClientBuilder, C> extends - AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "database-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Database"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new DatabaseResolveEndpointInterceptor()); - endpointInterceptors.add(new DatabaseRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/database/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_DATABASE_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlDatabase") - .serviceProfileProperty("database_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "database-service"; - } - - private DatabaseEndpointProvider defaultEndpointProvider() { - return DatabaseEndpointProvider.defaultProvider(); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - DatabaseServiceClientConfigurationBuilder serviceConfigBuilder = new DatabaseServiceClientConfigurationBuilder( - configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java deleted file mode 100644 index 6a8e2290d918..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java +++ /dev/null @@ -1,149 +0,0 @@ -package software.amazon.awssdk.services.database; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.database.endpoints.DatabaseEndpointProvider; -import software.amazon.awssdk.services.database.endpoints.internal.DatabaseRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.database.endpoints.internal.DatabaseResolveEndpointInterceptor; -import software.amazon.awssdk.services.database.internal.DatabaseServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; - -/** - * Internal base class for {@link DefaultDatabaseClientBuilder} and {@link DefaultDatabaseAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultDatabaseBaseClientBuilder, C> extends - AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "database-service-endpoint"; - } - - @Override - protected final String serviceName() { - return "Database"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()).option( - SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new DatabaseResolveEndpointInterceptor()); - endpointInterceptors.add(new DatabaseRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/database/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_DATABASE_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlDatabase") - .serviceProfileProperty("database_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - builder.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true); - return builder.build(); - } - - @Override - protected final String signingName() { - return "database-service"; - } - - private DatabaseEndpointProvider defaultEndpointProvider() { - return DatabaseEndpointProvider.defaultProvider(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - DatabaseServiceClientConfigurationBuilder serviceConfigBuilder = new DatabaseServiceClientConfigurationBuilder( - configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-query-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-query-client-builder-class.java deleted file mode 100644 index 2ef919b3671f..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-query-client-builder-class.java +++ /dev/null @@ -1,255 +0,0 @@ -package software.amazon.awssdk.services.query; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.credentials.TokenUtils; -import software.amazon.awssdk.auth.signer.Aws4Signer; -import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; -import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; -import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointMode; -import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointModeResolver; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculation; -import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; -import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.identity.spi.TokenIdentity; -import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.query.endpoints.QueryClientContextParams; -import software.amazon.awssdk.services.query.endpoints.QueryEndpointProvider; -import software.amazon.awssdk.services.query.endpoints.internal.QueryRequestSetEndpointInterceptor; -import software.amazon.awssdk.services.query.endpoints.internal.QueryResolveEndpointInterceptor; -import software.amazon.awssdk.services.query.internal.QueryServiceClientConfigurationBuilder; -import software.amazon.awssdk.utils.CollectionUtils; -import software.amazon.awssdk.utils.Validate; - -/** - * Internal base class for {@link DefaultQueryClientBuilder} and {@link DefaultQueryAsyncClientBuilder}. - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -abstract class DefaultQueryBaseClientBuilder, C> extends AwsDefaultClientBuilder { - @Override - protected final String serviceEndpointPrefix() { - return "query-service"; - } - - @Override - protected final String serviceName() { - return "Query"; - } - - @Override - protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { - return config.merge(c -> { - c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) - .option(SdkAdvancedClientOption.SIGNER, defaultSigner()) - .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) - .lazyOption(AwsClientOption.TOKEN_PROVIDER, - p -> TokenUtils.toSdkTokenProvider(p.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER))) - .option(AwsClientOption.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider()) - .option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()); - }); - } - - @Override - protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { - List endpointInterceptors = new ArrayList<>(); - endpointInterceptors.add(new QueryResolveEndpointInterceptor()); - endpointInterceptors.add(new QueryRequestSetEndpointInterceptor()); - ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); - List interceptors = interceptorFactory - .getInterceptors("software/amazon/awssdk/services/query/execution.interceptors"); - List additionalInterceptors = new ArrayList<>(); - interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); - interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); - interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); - SdkClientConfiguration.Builder builder = config.toBuilder(); - builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { - IdentityProviders.Builder result = IdentityProviders.builder(); - IdentityProvider tokenIdentityProvider = c.get(AwsClientOption.TOKEN_IDENTITY_PROVIDER); - if (tokenIdentityProvider != null) { - result.putIdentityProvider(tokenIdentityProvider); - } - IdentityProvider credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); - if (credentialsIdentityProvider != null) { - result.putIdentityProvider(credentialsIdentityProvider); - } - return result.build(); - }); - builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); - builder.option(SdkClientOption.CLIENT_CONTEXT_PARAMS, clientContextParams.build()); - builder.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE, resolveAccountIdEndpointMode(config)); - builder.lazyOptionIfAbsent( - SdkClientOption.CLIENT_ENDPOINT_PROVIDER, - c -> AwsClientEndpointProvider - .builder() - .serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_QUERY_SERVICE") - .serviceEndpointOverrideSystemProperty("aws.endpointUrlQuery") - .serviceProfileProperty("query_service") - .serviceEndpointPrefix(serviceEndpointPrefix()) - .defaultProtocol("https") - .region(c.get(AwsClientOption.AWS_REGION)) - .profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(c.get(SdkClientOption.PROFILE_NAME)) - .putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, - c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) - .dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) - .fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); - SdkClientConfiguration clientConfig = config; - builder.lazyOption(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, c -> resolveRequestChecksumCalculation(clientConfig)); - builder.lazyOption(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, c -> resolveResponseChecksumValidation(clientConfig)); - return builder.build(); - } - - private Signer defaultSigner() { - return Aws4Signer.create(); - } - - @Override - protected final String signingName() { - return "query-service"; - } - - private QueryEndpointProvider defaultEndpointProvider() { - return QueryEndpointProvider.defaultProvider(); - } - - public B requestChecksumCalculation(RequestChecksumCalculation requestChecksumCalculation) { - clientConfiguration.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, requestChecksumCalculation); - return thisBuilder(); - } - - public B responseChecksumValidation(ResponseChecksumValidation responseChecksumValidation) { - clientConfiguration.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, responseChecksumValidation); - return thisBuilder(); - } - - public B booleanContextParam(Boolean booleanContextParam) { - clientContextParams.put(QueryClientContextParams.BOOLEAN_CONTEXT_PARAM, booleanContextParam); - return thisBuilder(); - } - - public B stringContextParam(String stringContextParam) { - clientContextParams.put(QueryClientContextParams.STRING_CONTEXT_PARAM, stringContextParam); - return thisBuilder(); - } - - public B accountIdEndpointMode(AccountIdEndpointMode accountIdEndpointMode) { - clientConfiguration.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE, accountIdEndpointMode); - return thisBuilder(); - } - - private IdentityProvider defaultTokenProvider() { - return DefaultAwsTokenProvider.create(); - } - - private Signer defaultTokenSigner() { - return BearerTokenSigner.create(); - } - - @Override - protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { - List internalPlugins = internalPlugins(config); - List externalPlugins = plugins(); - if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { - return config; - } - List plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); - SdkClientConfiguration.Builder configuration = config.toBuilder(); - QueryServiceClientConfigurationBuilder serviceConfigBuilder = new QueryServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private List internalPlugins(SdkClientConfiguration config) { - return Collections.emptyList(); - } - - private AccountIdEndpointMode resolveAccountIdEndpointMode(SdkClientConfiguration config) { - AccountIdEndpointMode configuredMode = config.option(AwsClientOption.ACCOUNT_ID_ENDPOINT_MODE); - if (configuredMode == null) { - configuredMode = AccountIdEndpointModeResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)).defaultMode(AccountIdEndpointMode.PREFERRED) - .resolve(); - } - return configuredMode; - } - - private RequestChecksumCalculation resolveRequestChecksumCalculation(SdkClientConfiguration config) { - RequestChecksumCalculation configuredChecksumCalculation = config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION); - if (configuredChecksumCalculation == null) { - configuredChecksumCalculation = RequestChecksumCalculationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumCalculation(RequestChecksumCalculation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumCalculation; - } - - private ResponseChecksumValidation resolveResponseChecksumValidation(SdkClientConfiguration config) { - ResponseChecksumValidation configuredChecksumValidation = config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION); - if (configuredChecksumValidation == null) { - configuredChecksumValidation = ResponseChecksumValidationResolver.create() - .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) - .profileName(config.option(SdkClientOption.PROFILE_NAME)) - .defaultChecksumValidation(ResponseChecksumValidation.WHEN_SUPPORTED).resolve(); - } - return configuredChecksumValidation; - } - - protected static void validateClientOptions(SdkClientConfiguration c) { - Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), - "The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(SdkAdvancedClientOption.TOKEN_SIGNER), - "The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' must be configured in the client builder."); - Validate.notNull(c.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER), - "The 'tokenProvider' must be configured in the client builder."); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-json-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-json-async-client-class.java deleted file mode 100644 index b0b64c934764..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-json-async-client-class.java +++ /dev/null @@ -1,1466 +0,0 @@ -package software.amazon.awssdk.services.json; - -import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.function.Consumer; -import java.util.function.Function; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner; -import software.amazon.awssdk.auth.signer.EventStreamAws4Signer; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; -import software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils; -import software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkPojoBuilder; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.SdkResponse; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.async.AsyncResponseTransformer; -import software.amazon.awssdk.core.async.AsyncResponseTransformerUtils; -import software.amazon.awssdk.core.async.SdkPublisher; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.AsyncClientHandler; -import software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.protocol.VoidSdkResponse; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.json.AwsJsonProtocol; -import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.JsonOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.json.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.json.model.APostOperationRequest; -import software.amazon.awssdk.services.json.model.APostOperationResponse; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.json.model.EventStream; -import software.amazon.awssdk.services.json.model.EventStreamOperationRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponseHandler; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponseHandler; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse; -import software.amazon.awssdk.services.json.model.InputEventStream; -import software.amazon.awssdk.services.json.model.InputEventStreamTwo; -import software.amazon.awssdk.services.json.model.InvalidInputException; -import software.amazon.awssdk.services.json.model.JsonException; -import software.amazon.awssdk.services.json.model.JsonRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse; -import software.amazon.awssdk.services.json.model.ServiceFaultException; -import software.amazon.awssdk.services.json.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.json.model.inputeventstream.DefaultInputEvent; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventOne; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo; -import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventOneMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.CompletableFutureUtils; -import software.amazon.awssdk.utils.HostnameValidator; -import software.amazon.awssdk.utils.Pair; - -/** - * Internal implementation of {@link JsonAsyncClient}. - * - * @see JsonAsyncClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultJsonAsyncClient implements JsonAsyncClient { - private static final Logger log = LoggerFactory.getLogger(DefaultJsonAsyncClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.AWS_JSON).build(); - - private final AsyncClientHandler clientHandler; - - private final AwsJsonProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - private final Executor executor; - - protected DefaultJsonAsyncClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsAsyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Json_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build(); - this.executor = clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); - } - - @Override - public JsonUtilities utilities() { - return JsonUtilities.create(param1, param2, param3); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return A Java Future containing the result of the APostOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public CompletableFuture aPostOperation(APostOperationRequest aPostOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - String hostPrefix = "{StringMember}-foo."; - HostnameValidator.validateHostnameCompliant(aPostOperationRequest.stringMember(), "StringMember", - "aPostOperationRequest"); - String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember()); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return A Java Future containing the result of the APostOperationWithOutput operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • ServiceFaultException
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationWithOutputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(aPostOperationWithOutputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperation operation asynchronously. - * - * @param eventStreamOperationRequest - * @return A Java Future containing the result of the EventStreamOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperation(EventStreamOperationRequest eventStreamOperationRequest, - Publisher requestStream, EventStreamOperationResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperation"); - eventStreamOperationRequest = applySignerOverride(eventStreamOperationRequest, EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEvent.class, new InputEventMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder().eventStreamResponseHandler(asyncResponseHandler) - .eventResponseHandler(eventResponseHandler).initialResponseHandler(responseHandler) - .exceptionResponseHandler(errorEventResponseHandler).future(future).executor(executor) - .serviceName(serviceName()).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withFullDuplex(true) - .withInitialRequestEvent(true).withResponseHandler(voidResponseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationRequest), - asyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyInput operation asynchronously. - * - * @param eventStreamOperationWithOnlyInputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyInput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyInput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyInput( - EventStreamOperationWithOnlyInputRequest eventStreamOperationWithOnlyInputRequest, - Publisher requestStream) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyInputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyInputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyInput"); - eventStreamOperationWithOnlyInputRequest = applySignerOverride(eventStreamOperationWithOnlyInputRequest, - EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, EventStreamOperationWithOnlyInputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEventOne.class, new InputEventOneMarshaller(protocolFactory)) - .putMarshaller(DefaultInputEventTwo.class, new InputEventTwoMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyInput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyInputRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withInitialRequestEvent(true) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationWithOnlyInputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyOutput operation asynchronously. - * - * @param eventStreamOperationWithOnlyOutputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyOutput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyOutput( - EventStreamOperationWithOnlyOutputRequest eventStreamOperationWithOnlyOutputRequest, - EventStreamOperationWithOnlyOutputResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyOutputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationWithOnlyOutputResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder() - .eventStreamResponseHandler(asyncResponseHandler).eventResponseHandler(eventResponseHandler) - .initialResponseHandler(responseHandler).exceptionResponseHandler(errorEventResponseHandler).future(future) - .executor(executor).serviceName(serviceName()).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(voidResponseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationWithOnlyOutputRequest), asyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param getWithoutRequiredMembersRequest - * @return A Java Future containing the result of the GetWithoutRequiredMembers operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.GetWithoutRequiredMembers - * @see AWS API Documentation - */ - @Override - public CompletableFuture getWithoutRequiredMembers( - GetWithoutRequiredMembersRequest getWithoutRequiredMembersRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getWithoutRequiredMembersRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getWithoutRequiredMembersRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetWithoutRequiredMembersResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetWithoutRequiredMembers").withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(getWithoutRequiredMembersRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation asynchronously. - * - * @param operationWithChecksumRequiredRequest - * @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithChecksumRequiredResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation asynchronously. - * - * @param operationWithNoneAuthTypeRequest - * @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithNoneAuthTypeResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withInput(operationWithNoneAuthTypeRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithRequestCompression operation asynchronously. - * - * @param operationWithRequestCompressionRequest - * @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithRequestCompressionResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withInput(operationWithRequestCompressionRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation with result_key in paginators.json file - * - * @param paginatedOperationWithResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithResultKey( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PaginatedOperationWithResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation without result_key in paginators.json file - * - * @param paginatedOperationWithoutResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithoutResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithoutResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithoutResultKey( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithoutResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithoutResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, PaginatedOperationWithoutResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithoutResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithoutResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOperation( - StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - if (!isSignerOverridden(clientConfiguration)) { - streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create()); - } - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody) - .withInput(streamingInputOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with streaming input and streaming output - * - * @param streamingInputOutputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOutputOperation( - StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - streamingInputOutputOperationRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - streamingInputOutputOperationRequest = applySignerOverride(streamingInputOutputOperationRequest, - Aws4UnsignedPayloadSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingInputOutputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller - .builder() - .delegateMarshaller( - new StreamingInputOutputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).transferEncoding(true).build()) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncRequestBody(requestBody).withAsyncResponseTransformer(asyncResponseTransformer) - .withInput(streamingInputOutputOperationRequest), asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(streamingOutputOperationRequest), - asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - @Override - public final JsonServiceClientConfiguration serviceClientConfiguration() { - return new JsonServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private > T init(T builder) { - return builder.clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(JsonException::builder) - .protocol(AwsJsonProtocol.AWS_JSON).protocolVersion("1.1"); - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, - JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) { - return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-cbor-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-cbor-async-client-class.java deleted file mode 100644 index f158aad97cfa..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-cbor-async-client-class.java +++ /dev/null @@ -1,1470 +0,0 @@ -package software.amazon.awssdk.services.json; - -import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.function.Consumer; -import java.util.function.Function; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner; -import software.amazon.awssdk.auth.signer.EventStreamAws4Signer; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; -import software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils; -import software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkPojoBuilder; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.SdkResponse; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.async.AsyncResponseTransformer; -import software.amazon.awssdk.core.async.AsyncResponseTransformerUtils; -import software.amazon.awssdk.core.async.SdkPublisher; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.AsyncClientHandler; -import software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.protocol.VoidSdkResponse; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.cbor.AwsCborProtocolFactory; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.json.AwsJsonProtocol; -import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.JsonOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.json.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.json.model.APostOperationRequest; -import software.amazon.awssdk.services.json.model.APostOperationResponse; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.json.model.EventStream; -import software.amazon.awssdk.services.json.model.EventStreamOperationRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponseHandler; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponseHandler; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse; -import software.amazon.awssdk.services.json.model.InputEventStream; -import software.amazon.awssdk.services.json.model.InputEventStreamTwo; -import software.amazon.awssdk.services.json.model.InvalidInputException; -import software.amazon.awssdk.services.json.model.JsonException; -import software.amazon.awssdk.services.json.model.JsonRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse; -import software.amazon.awssdk.services.json.model.ServiceFaultException; -import software.amazon.awssdk.services.json.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.json.model.inputeventstream.DefaultInputEvent; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventOne; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo; -import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventOneMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.CompletableFutureUtils; -import software.amazon.awssdk.utils.HostnameValidator; -import software.amazon.awssdk.utils.Pair; - -/** - * Internal implementation of {@link JsonAsyncClient}. - * - * @see JsonAsyncClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultJsonAsyncClient implements JsonAsyncClient { - private static final Logger log = LoggerFactory.getLogger(DefaultJsonAsyncClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.CBOR).build(); - - private final AsyncClientHandler clientHandler; - - private final AwsCborProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - private final AwsJsonProtocolFactory jsonProtocolFactory; - - private final Executor executor; - - protected DefaultJsonAsyncClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsAsyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Json_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(AwsCborProtocolFactory.builder()).build(); - this.jsonProtocolFactory = init(AwsJsonProtocolFactory.builder()).build(); - this.executor = clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); - } - - @Override - public JsonUtilities utilities() { - return JsonUtilities.create(param1, param2, param3); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return A Java Future containing the result of the APostOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public CompletableFuture aPostOperation(APostOperationRequest aPostOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - String hostPrefix = "{StringMember}-foo."; - HostnameValidator.validateHostnameCompliant(aPostOperationRequest.stringMember(), "StringMember", - "aPostOperationRequest"); - String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember()); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return A Java Future containing the result of the APostOperationWithOutput operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • ServiceFaultException
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationWithOutputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(aPostOperationWithOutputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperation operation asynchronously. - * - * @param eventStreamOperationRequest - * @return A Java Future containing the result of the EventStreamOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperation(EventStreamOperationRequest eventStreamOperationRequest, - Publisher requestStream, EventStreamOperationResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperation"); - eventStreamOperationRequest = applySignerOverride(eventStreamOperationRequest, EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEvent.class, new InputEventMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder().eventStreamResponseHandler(asyncResponseHandler) - .eventResponseHandler(eventResponseHandler).initialResponseHandler(responseHandler) - .exceptionResponseHandler(errorEventResponseHandler).future(future).executor(executor) - .serviceName(serviceName()).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withFullDuplex(true) - .withInitialRequestEvent(true).withResponseHandler(voidResponseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationRequest), - asyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyInput operation asynchronously. - * - * @param eventStreamOperationWithOnlyInputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyInput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyInput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyInput( - EventStreamOperationWithOnlyInputRequest eventStreamOperationWithOnlyInputRequest, - Publisher requestStream) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyInputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyInputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyInput"); - eventStreamOperationWithOnlyInputRequest = applySignerOverride(eventStreamOperationWithOnlyInputRequest, - EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, EventStreamOperationWithOnlyInputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEventOne.class, new InputEventOneMarshaller(protocolFactory)) - .putMarshaller(DefaultInputEventTwo.class, new InputEventTwoMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyInput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyInputRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withInitialRequestEvent(true) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationWithOnlyInputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyOutput operation asynchronously. - * - * @param eventStreamOperationWithOnlyOutputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyOutput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyOutput( - EventStreamOperationWithOnlyOutputRequest eventStreamOperationWithOnlyOutputRequest, - EventStreamOperationWithOnlyOutputResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyOutputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationWithOnlyOutputResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder() - .eventStreamResponseHandler(asyncResponseHandler).eventResponseHandler(eventResponseHandler) - .initialResponseHandler(responseHandler).exceptionResponseHandler(errorEventResponseHandler).future(future) - .executor(executor).serviceName(serviceName()).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(voidResponseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationWithOnlyOutputRequest), asyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param getWithoutRequiredMembersRequest - * @return A Java Future containing the result of the GetWithoutRequiredMembers operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.GetWithoutRequiredMembers - * @see AWS API Documentation - */ - @Override - public CompletableFuture getWithoutRequiredMembers( - GetWithoutRequiredMembersRequest getWithoutRequiredMembersRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getWithoutRequiredMembersRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getWithoutRequiredMembersRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetWithoutRequiredMembersResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetWithoutRequiredMembers").withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(getWithoutRequiredMembersRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation asynchronously. - * - * @param operationWithChecksumRequiredRequest - * @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithChecksumRequiredResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation asynchronously. - * - * @param operationWithNoneAuthTypeRequest - * @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithNoneAuthTypeResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withInput(operationWithNoneAuthTypeRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithRequestCompression operation asynchronously. - * - * @param operationWithRequestCompressionRequest - * @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithRequestCompressionResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withInput(operationWithRequestCompressionRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation with result_key in paginators.json file - * - * @param paginatedOperationWithResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithResultKey( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PaginatedOperationWithResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation without result_key in paginators.json file - * - * @param paginatedOperationWithoutResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithoutResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithoutResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithoutResultKey( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithoutResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithoutResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, PaginatedOperationWithoutResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithoutResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithoutResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOperation( - StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - if (!isSignerOverridden(clientConfiguration)) { - streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create()); - } - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody) - .withInput(streamingInputOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with streaming input and streaming output - * - * @param streamingInputOutputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOutputOperation( - StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - streamingInputOutputOperationRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - streamingInputOutputOperationRequest = applySignerOverride(streamingInputOutputOperationRequest, - Aws4UnsignedPayloadSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingInputOutputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller - .builder() - .delegateMarshaller( - new StreamingInputOutputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).transferEncoding(true).build()) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncRequestBody(requestBody).withAsyncResponseTransformer(asyncResponseTransformer) - .withInput(streamingInputOutputOperationRequest), asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInputException": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInputException").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "ServiceFaultException": - return Optional.of(ExceptionMetadata.builder().errorCode("ServiceFaultException").httpStatusCode(500) - .exceptionBuilderSupplier(ServiceFaultException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(streamingOutputOperationRequest), - asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - @Override - public final JsonServiceClientConfiguration serviceClientConfiguration() { - return new JsonServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private > T init(T builder) { - return builder.clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(JsonException::builder) - .protocol(AwsJsonProtocol.AWS_JSON).protocolVersion("1.1"); - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, - JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) { - return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-class.java deleted file mode 100644 index ec4546d6b3c2..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-class.java +++ /dev/null @@ -1,1666 +0,0 @@ -package software.amazon.awssdk.services.json; - -import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; -import java.util.function.Consumer; -import java.util.function.Function; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner; -import software.amazon.awssdk.auth.signer.EventStreamAws4Signer; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; -import software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils; -import software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier; -import software.amazon.awssdk.awscore.eventstream.RestEventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkPojoBuilder; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.SdkResponse; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.async.AsyncResponseTransformer; -import software.amazon.awssdk.core.async.AsyncResponseTransformerUtils; -import software.amazon.awssdk.core.async.SdkPublisher; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.AsyncClientHandler; -import software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.protocol.VoidSdkResponse; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.json.AwsJsonProtocol; -import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.JsonOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.batchmanager.JsonAsyncBatchManager; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.json.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.json.model.APostOperationRequest; -import software.amazon.awssdk.services.json.model.APostOperationResponse; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.json.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.json.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.json.model.EventStream; -import software.amazon.awssdk.services.json.model.EventStreamOperationRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationResponseHandler; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputRequest; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponse; -import software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponseHandler; -import software.amazon.awssdk.services.json.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.json.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse; -import software.amazon.awssdk.services.json.model.InputEventStream; -import software.amazon.awssdk.services.json.model.InputEventStreamTwo; -import software.amazon.awssdk.services.json.model.InvalidInputException; -import software.amazon.awssdk.services.json.model.JsonException; -import software.amazon.awssdk.services.json.model.JsonRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse; -import software.amazon.awssdk.services.json.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.json.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.json.model.inputeventstream.DefaultInputEvent; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventOne; -import software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo; -import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventOneMarshaller; -import software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.CompletableFutureUtils; -import software.amazon.awssdk.utils.HostnameValidator; -import software.amazon.awssdk.utils.Pair; - -/** - * Internal implementation of {@link JsonAsyncClient}. - * - * @see JsonAsyncClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultJsonAsyncClient implements JsonAsyncClient { - private static final Logger log = LoggerFactory.getLogger(DefaultJsonAsyncClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.REST_JSON).build(); - - private final AsyncClientHandler clientHandler; - - private final AwsJsonProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - private final ScheduledExecutorService executorService; - - private final Executor executor; - - protected DefaultJsonAsyncClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsAsyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, - "Json_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build(); - this.executor = clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); - this.executorService = clientConfiguration.option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE); - } - - @Override - public JsonUtilities utilities() { - return JsonUtilities.create(param1, param2, param3); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return A Java Future containing the result of the APostOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public CompletableFuture aPostOperation(APostOperationRequest aPostOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - String hostPrefix = "{StringMember}-foo."; - HostnameValidator.validateHostnameCompliant(aPostOperationRequest.stringMember(), "StringMember", - "aPostOperationRequest"); - String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember()); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return A Java Future containing the result of the APostOperationWithOutput operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationWithOutputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(aPostOperationWithOutputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the BearerAuthOperation operation asynchronously. - * - * @param bearerAuthOperationRequest - * @return A Java Future containing the result of the BearerAuthOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture bearerAuthOperation( - BearerAuthOperationRequest bearerAuthOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, BearerAuthOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .credentialType(CredentialType.TOKEN).withInput(bearerAuthOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperation operation asynchronously. - * - * @param eventStreamOperationRequest - * @return A Java Future containing the result of the EventStreamOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperation(EventStreamOperationRequest eventStreamOperationRequest, - Publisher requestStream, EventStreamOperationResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperation"); - eventStreamOperationRequest = applySignerOverride(eventStreamOperationRequest, EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - case "errorOne": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "errorTwo": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEvent.class, new InputEventMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder().eventStreamResponseHandler(asyncResponseHandler) - .eventResponseHandler(eventResponseHandler).initialResponseHandler(responseHandler) - .exceptionResponseHandler(errorEventResponseHandler).future(future).executor(executor) - .serviceName(serviceName()).build(); - RestEventStreamAsyncResponseTransformer restAsyncResponseTransformer = RestEventStreamAsyncResponseTransformer - . builder() - .eventStreamAsyncResponseTransformer(asyncResponseTransformer) - .eventStreamResponseHandler(asyncResponseHandler).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withFullDuplex(true) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationRequest), restAsyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyInput operation asynchronously. - * - * @param eventStreamOperationWithOnlyInputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyInput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyInput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyInput( - EventStreamOperationWithOnlyInputRequest eventStreamOperationWithOnlyInputRequest, - Publisher requestStream) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyInputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyInputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyInput"); - eventStreamOperationWithOnlyInputRequest = applySignerOverride(eventStreamOperationWithOnlyInputRequest, - EventStreamAws4Signer.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, EventStreamOperationWithOnlyInputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder() - .putMarshaller(DefaultInputEventOne.class, new InputEventOneMarshaller(protocolFactory)) - .putMarshaller(DefaultInputEventTwo.class, new InputEventTwoMarshaller(protocolFactory)).build(); - SdkPublisher eventPublisher = SdkPublisher.adapt(requestStream); - Publisher adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map( - AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyInput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyInputRequestMarshaller(protocolFactory)) - .withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationWithOnlyInputRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperationWithOnlyOutput operation asynchronously. - * - * @param eventStreamOperationWithOnlyOutputRequest - * @return A Java Future containing the result of the EventStreamOperationWithOnlyOutput operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.EventStreamOperationWithOnlyOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperationWithOnlyOutput( - EventStreamOperationWithOnlyOutputRequest eventStreamOperationWithOnlyOutputRequest, - EventStreamOperationWithOnlyOutputResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationWithOnlyOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - eventStreamOperationWithOnlyOutputRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyOutput"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = new AttachHttpMetadataResponseHandler( - protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationWithOnlyOutputResponse::builder)); - - HttpResponseHandler voidResponseHandler = protocolFactory.createResponseHandler(JsonOperationMetadata - .builder().isPayloadJson(false).hasStreamingSuccessResponse(true).build(), VoidSdkResponse::builder); - - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - JsonOperationMetadata.builder().isPayloadJson(true).hasStreamingSuccessResponse(false).build(), - EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventOne", EventStream::eventOneBuilder) - .putSdkPojoSupplier("EventTheSecond", EventStream::eventTheSecondBuilder) - .putSdkPojoSupplier("secondEventOne", EventStream::secondEventOneBuilder) - .putSdkPojoSupplier("eventThree", EventStream::eventThreeBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build()); - - Function> eventstreamExceptionMetadataMapper = errorCode -> { - switch (errorCode) { - case "errorOne": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - case "errorTwo": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - - HttpResponseHandler errorEventResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, eventstreamExceptionMetadataMapper); - - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - CompletableFuture future = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder() - .eventStreamResponseHandler(asyncResponseHandler).eventResponseHandler(eventResponseHandler) - .initialResponseHandler(responseHandler).exceptionResponseHandler(errorEventResponseHandler).future(future) - .executor(executor).serviceName(serviceName()).build(); - RestEventStreamAsyncResponseTransformer restAsyncResponseTransformer = RestEventStreamAsyncResponseTransformer - . builder() - .eventStreamAsyncResponseTransformer(asyncResponseTransformer) - .eventStreamResponseHandler(asyncResponseHandler).build(); - - CompletableFuture executeFuture = clientHandler - .execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperationWithOnlyOutput") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationWithOnlyOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(eventStreamOperationWithOnlyOutputRequest), restAsyncResponseTransformer); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - try { - asyncResponseHandler.exceptionOccurred(e); - } finally { - future.completeExceptionally(e); - } - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(future, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the GetOperationWithChecksum operation asynchronously. - * - * @param getOperationWithChecksumRequest - * @return A Java Future containing the result of the GetOperationWithChecksum operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetOperationWithChecksumResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withInput(getOperationWithChecksumRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param getWithoutRequiredMembersRequest - * @return A Java Future containing the result of the GetWithoutRequiredMembers operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.GetWithoutRequiredMembers - * @see AWS API Documentation - */ - @Override - public CompletableFuture getWithoutRequiredMembers( - GetWithoutRequiredMembersRequest getWithoutRequiredMembersRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getWithoutRequiredMembersRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getWithoutRequiredMembersRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetWithoutRequiredMembersResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetWithoutRequiredMembers").withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(getWithoutRequiredMembersRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation asynchronously. - * - * @param operationWithChecksumRequiredRequest - * @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithChecksumRequiredResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithRequestCompression operation asynchronously. - * - * @param operationWithRequestCompressionRequest - * @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithRequestCompressionResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withInput(operationWithRequestCompressionRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation with result_key in paginators.json file - * - * @param paginatedOperationWithResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithResultKey( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PaginatedOperationWithResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some paginated operation without result_key in paginators.json file - * - * @param paginatedOperationWithoutResultKeyRequest - * @return A Java Future containing the result of the PaginatedOperationWithoutResultKey operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PaginatedOperationWithoutResultKey - * @see AWS API Documentation - */ - @Override - public CompletableFuture paginatedOperationWithoutResultKey( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithoutResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithoutResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey"); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(operationMetadata, PaginatedOperationWithoutResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithoutResultKey").withProtocolMetadata(protocolMetadata) - .withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(paginatedOperationWithoutResultKeyRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the PutOperationWithChecksum operation asynchronously. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows ' - *

- * Object data. - *

- * '. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture putOperationWithChecksum( - PutOperationWithChecksumRequest putOperationWithChecksumRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - if (!isSignerOverridden(clientConfiguration)) { - putOperationWithChecksumRequest = applySignerOverride(putOperationWithChecksumRequest, AsyncAws4Signer.create()); - } - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PutOperationWithChecksumResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .withAsyncRequestBody(requestBody) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(putOperationWithChecksumRequest), - asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOperation( - StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - if (!isSignerOverridden(clientConfiguration)) { - streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create()); - } - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody) - .withInput(streamingInputOperationRequest)); - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with streaming input and streaming output - * - * @param streamingInputOutputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingInputOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOutputOperation( - StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - streamingInputOutputOperationRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - streamingInputOutputOperationRequest = applySignerOverride(streamingInputOutputOperationRequest, - Aws4UnsignedPayloadSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingInputOutputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller - .builder() - .delegateMarshaller( - new StreamingInputOutputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).transferEncoding(true).build()) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncRequestBody(requestBody).withAsyncResponseTransformer(asyncResponseTransformer) - .withInput(streamingInputOutputOperationRequest), asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample JsonAsyncClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(streamingOutputOperationRequest), - asyncResponseTransformer); - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture); - return executeFuture; - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - @Override - public JsonAsyncBatchManager batchManager() { - return JsonAsyncBatchManager.builder().client(this).scheduledExecutor(executorService).build(); - } - - @Override - public final JsonServiceClientConfiguration serviceClientConfiguration() { - return new JsonServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private > T init(T builder) { - return builder.clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(JsonException::builder) - .protocol(AwsJsonProtocol.REST_JSON).protocolVersion("1.1"); - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, - JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) { - return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java deleted file mode 100644 index 4e633681cbbb..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java +++ /dev/null @@ -1,1139 +0,0 @@ -package software.amazon.awssdk.services.json; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Function; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.client.handler.SyncClientHandler; -import software.amazon.awssdk.core.exception.SdkClientException; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.StreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.sync.RequestBody; -import software.amazon.awssdk.core.sync.ResponseTransformer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.json.AwsJsonProtocol; -import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory; -import software.amazon.awssdk.protocols.json.JsonOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.json.internal.JsonServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.json.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.json.model.APostOperationRequest; -import software.amazon.awssdk.services.json.model.APostOperationResponse; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.json.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.json.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.json.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.json.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest; -import software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse; -import software.amazon.awssdk.services.json.model.InvalidInputException; -import software.amazon.awssdk.services.json.model.JsonException; -import software.amazon.awssdk.services.json.model.JsonRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest; -import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse; -import software.amazon.awssdk.services.json.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.json.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.json.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.json.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller; -import software.amazon.awssdk.services.json.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.HostnameValidator; -import software.amazon.awssdk.utils.Logger; - -/** - * Internal implementation of {@link JsonClient}. - * - * @see JsonClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultJsonClient implements JsonClient { - private static final Logger log = Logger.loggerFor(DefaultJsonClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.REST_JSON).build(); - - private final SyncClientHandler clientHandler; - - private final AwsJsonProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - protected DefaultJsonClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsSyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Json_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build(); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return Result of the APostOperation operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, - AwsServiceException, SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, - APostOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - String hostPrefix = "{StringMember}-foo."; - HostnameValidator.validateHostnameCompliant(aPostOperationRequest.stringMember(), "StringMember", - "aPostOperationRequest"); - String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember()); - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .hostPrefixExpression(resolvedHostExpression).withRequestConfiguration(clientConfiguration) - .withInput(aPostOperationRequest).withMetricCollector(apiCallMetricCollector) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return Result of the APostOperationWithOutput operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public APostOperationWithOutputResponse aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) throws InvalidInputException, AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, APostOperationWithOutputResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(aPostOperationWithOutputRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the BearerAuthOperation operation. - * - * @param bearerAuthOperationRequest - * @return Result of the BearerAuthOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public BearerAuthOperationResponse bearerAuthOperation(BearerAuthOperationRequest bearerAuthOperationRequest) - throws AwsServiceException, SdkClientException, JsonException { - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, BearerAuthOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .credentialType(CredentialType.TOKEN).withRequestConfiguration(clientConfiguration) - .withInput(bearerAuthOperationRequest).withMetricCollector(apiCallMetricCollector) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the GetOperationWithChecksum operation. - * - * @param getOperationWithChecksumRequest - * @return Result of the GetOperationWithChecksum operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public GetOperationWithChecksumResponse getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) throws AwsServiceException, SdkClientException, - JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetOperationWithChecksumResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(getOperationWithChecksumRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param getWithoutRequiredMembersRequest - * @return Result of the GetWithoutRequiredMembers operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.GetWithoutRequiredMembers - * @see AWS API Documentation - */ - @Override - public GetWithoutRequiredMembersResponse getWithoutRequiredMembers( - GetWithoutRequiredMembersRequest getWithoutRequiredMembersRequest) throws InvalidInputException, AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, GetWithoutRequiredMembersResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getWithoutRequiredMembersRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getWithoutRequiredMembersRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetWithoutRequiredMembers").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(getWithoutRequiredMembersRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation. - * - * @param operationWithChecksumRequiredRequest - * @return Result of the OperationWithChecksumRequired operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public OperationWithChecksumRequiredResponse operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) throws AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithChecksumRequiredResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithChecksumRequiredRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithRequestCompression operation. - * - * @param operationWithRequestCompressionRequest - * @return Result of the OperationWithRequestCompression operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public OperationWithRequestCompressionResponse operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) throws AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, OperationWithRequestCompressionResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithRequestCompressionRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some paginated operation with result_key in paginators.json file - * - * @param paginatedOperationWithResultKeyRequest - * @return Result of the PaginatedOperationWithResultKey operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.PaginatedOperationWithResultKey - * @see AWS API Documentation - */ - @Override - public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PaginatedOperationWithResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithResultKey").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(paginatedOperationWithResultKeyRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some paginated operation without result_key in paginators.json file - * - * @param paginatedOperationWithoutResultKeyRequest - * @return Result of the PaginatedOperationWithoutResultKey operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.PaginatedOperationWithoutResultKey - * @see AWS API Documentation - */ - @Override - public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResultKey( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PaginatedOperationWithoutResultKeyResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(paginatedOperationWithoutResultKeyRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - paginatedOperationWithoutResultKeyRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PaginatedOperationWithoutResultKey").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(paginatedOperationWithoutResultKeyRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the PutOperationWithChecksum operation. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * PutOperationWithChecksumResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows ' - *

- * Object data. - *

- * '. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public ReturnT putOperationWithChecksum(PutOperationWithChecksumRequest putOperationWithChecksumRequest, - RequestBody requestBody, ResponseTransformer responseTransformer) - throws AwsServiceException, SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, PutOperationWithChecksumResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - - return clientHandler.execute( - new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(putOperationWithChecksumRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withResponseTransformer(responseTransformer) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build()), responseTransformer); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows 'This be a stream' - * @return Result of the StreamingInputOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, - RequestBody requestBody) throws AwsServiceException, SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) - .isPayloadJson(true).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(streamingInputOperationRequest) - .withMetricCollector(apiCallMetricCollector) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build())); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with streaming input and streaming output - * - * @param streamingInputOutputOperationRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows 'This be a stream' - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * StreamingInputOutputOperationResponse and an InputStream to the response content are provided as - * parameters to the callback. The callback may return a transformed type which will be the return value of - * this method. See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing - * this interface and for links to pre-canned implementations for common scenarios like downloading to a - * file. The service documentation for the response content is as follows 'This be a stream'. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.StreamingInputOutputOperation - * @see AWS API Documentation - */ - @Override - public ReturnT streamingInputOutputOperation( - StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, RequestBody requestBody, - ResponseTransformer responseTransformer) throws AwsServiceException, - SdkClientException, JsonException { - streamingInputOutputOperationRequest = applySignerOverride(streamingInputOutputOperationRequest, - Aws4UnsignedPayloadSigner.create()); - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingInputOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - streamingInputOutputOperationRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation"); - - return clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingInputOutputOperation") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(streamingInputOutputOperationRequest) - .withMetricCollector(apiCallMetricCollector) - .withResponseTransformer(responseTransformer) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller - .builder() - .delegateMarshaller( - new StreamingInputOutputOperationRequestMarshaller(protocolFactory)) - .requestBody(requestBody).transferEncoding(true).build()), responseTransformer); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * StreamingOutputOperationResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows 'This be a stream'. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws JsonException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample JsonClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, - ResponseTransformer responseTransformer) throws AwsServiceException, - SdkClientException, JsonException { - JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true) - .isPayloadJson(false).build(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - operationMetadata, StreamingOutputOperationResponse::builder); - Function> exceptionMetadataMapper = errorCode -> { - if (errorCode == null) { - return Optional.empty(); - } - switch (errorCode) { - case "InvalidInput": - return Optional.of(ExceptionMetadata.builder().errorCode("InvalidInput").httpStatusCode(400) - .exceptionBuilderSupplier(InvalidInputException::builder).build()); - default: - return Optional.empty(); - } - }; - HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, - operationMetadata, exceptionMetadataMapper); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - - return clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(streamingOutputOperationRequest) - .withMetricCollector(apiCallMetricCollector).withResponseTransformer(responseTransformer) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Creates an instance of {@link JsonUtilities} object with the configuration set on this client. - */ - @Override - public JsonUtilities utilities() { - return JsonUtilities.create(param1, param2, param3); - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, - JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) { - return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - JsonServiceClientConfigurationBuilder serviceConfigBuilder = new JsonServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private > T init(T builder) { - return builder.clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(JsonException::builder) - .protocol(AwsJsonProtocol.REST_JSON).protocolVersion("1.1"); - } - - @Override - public final JsonServiceClientConfiguration serviceClientConfiguration() { - return new JsonServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-async-client-class.java deleted file mode 100644 index 6c91007359bf..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-async-client-class.java +++ /dev/null @@ -1,1252 +0,0 @@ -package software.amazon.awssdk.services.query; - -import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ScheduledExecutorService; -import java.util.function.Consumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.codegen.internal.UtilsTest; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.async.AsyncResponseTransformer; -import software.amazon.awssdk.core.async.AsyncResponseTransformerUtils; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.AsyncClientHandler; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.query.internal.QueryServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.query.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.query.model.APostOperationRequest; -import software.amazon.awssdk.services.query.model.APostOperationResponse; -import software.amazon.awssdk.services.query.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.query.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.query.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.query.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.query.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.query.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.query.model.InvalidInputException; -import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.query.model.OperationWithContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithCustomMemberRequest; -import software.amazon.awssdk.services.query.model.OperationWithCustomMemberResponse; -import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithMapOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithMapOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.query.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.query.model.OperationWithStaticContextParamsRequest; -import software.amazon.awssdk.services.query.model.OperationWithStaticContextParamsResponse; -import software.amazon.awssdk.services.query.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.query.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.query.model.QueryException; -import software.amazon.awssdk.services.query.model.QueryRequest; -import software.amazon.awssdk.services.query.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.query.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.query.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.query.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.query.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.query.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithCustomMemberRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithCustomizedOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithMapOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithStaticContextParamsRequestMarshaller; -import software.amazon.awssdk.services.query.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.query.waiters.QueryAsyncWaiter; -import software.amazon.awssdk.utils.CompletableFutureUtils; -import software.amazon.awssdk.utils.Pair; - -/** - * Internal implementation of {@link QueryAsyncClient}. - * - * @see QueryAsyncClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultQueryAsyncClient implements QueryAsyncClient { - private static final Logger log = LoggerFactory.getLogger(DefaultQueryAsyncClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.QUERY).build(); - - private final AsyncClientHandler clientHandler; - - private final AwsQueryProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - private final ScheduledExecutorService executorService; - - protected DefaultQueryAsyncClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsAsyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Query_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(); - this.executorService = clientConfiguration.option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return A Java Future containing the result of the APostOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public CompletableFuture aPostOperation(APostOperationRequest aPostOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(APostOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - String hostPrefix = "foo-"; - String resolvedHostExpression = "foo-"; - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return A Java Future containing the result of the APostOperationWithOutput operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(APostOperationWithOutputResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(aPostOperationWithOutputRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the BearerAuthOperation operation asynchronously. - * - * @param bearerAuthOperationRequest - * @return A Java Future containing the result of the BearerAuthOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture bearerAuthOperation( - BearerAuthOperationRequest bearerAuthOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(BearerAuthOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .credentialType(CredentialType.TOKEN).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withInput(bearerAuthOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the GetOperationWithChecksum operation asynchronously. - * - * @param getOperationWithChecksumRequest - * @return A Java Future containing the result of the GetOperationWithChecksum operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(GetOperationWithChecksumResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withInput(getOperationWithChecksumRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation asynchronously. - * - * @param operationWithChecksumRequiredRequest - * @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithChecksumRequiredResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithContextParam operation asynchronously. - * - * @param operationWithContextParamRequest - * @return A Java Future containing the result of the OperationWithContextParam operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithContextParam - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithContextParam( - OperationWithContextParamRequest operationWithContextParamRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithContextParamRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithContextParam"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithContextParam").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithContextParamRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithContextParamRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithCustomMember operation asynchronously. - * - * @param operationWithCustomMemberRequest - * @return A Java Future containing the result of the OperationWithCustomMember operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithCustomMember - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithCustomMember( - OperationWithCustomMemberRequest operationWithCustomMemberRequest) { - operationWithCustomMemberRequest = UtilsTest.dummyRequestModifier(operationWithCustomMemberRequest); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithCustomMemberRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithCustomMemberRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomMember"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithCustomMemberResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithCustomMember").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithCustomMemberRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithCustomMemberRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithCustomizedOperationContextParam operation asynchronously. - * - * @param operationWithCustomizedOperationContextParamRequest - * @return A Java Future containing the result of the OperationWithCustomizedOperationContextParam operation - * returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithCustomizedOperationContextParam - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithCustomizedOperationContextParam( - OperationWithCustomizedOperationContextParamRequest operationWithCustomizedOperationContextParamRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration( - operationWithCustomizedOperationContextParamRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithCustomizedOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomizedOperationContextParam"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithCustomizedOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithCustomizedOperationContextParam") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithCustomizedOperationContextParamRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithCustomizedOperationContextParamRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithMapOperationContextParam operation asynchronously. - * - * @param operationWithMapOperationContextParamRequest - * @return A Java Future containing the result of the OperationWithMapOperationContextParam operation returned by - * the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithMapOperationContextParam - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithMapOperationContextParam( - OperationWithMapOperationContextParamRequest operationWithMapOperationContextParamRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithMapOperationContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithMapOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithMapOperationContextParam"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithMapOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithMapOperationContextParam").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithMapOperationContextParamRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithMapOperationContextParamRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation asynchronously. - * - * @param operationWithNoneAuthTypeRequest - * @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithNoneAuthTypeResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withInput(operationWithNoneAuthTypeRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithOperationContextParam operation asynchronously. - * - * @param operationWithOperationContextParamRequest - * @return A Java Future containing the result of the OperationWithOperationContextParam operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithOperationContextParam - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithOperationContextParam( - OperationWithOperationContextParamRequest operationWithOperationContextParamRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithOperationContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithOperationContextParam"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithOperationContextParam").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithOperationContextParamRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithOperationContextParamRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithRequestCompression operation asynchronously. - * - * @param operationWithRequestCompressionRequest - * @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithRequestCompressionResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withInput(operationWithRequestCompressionRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithStaticContextParams operation asynchronously. - * - * @param operationWithStaticContextParamsRequest - * @return A Java Future containing the result of the OperationWithStaticContextParams operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.OperationWithStaticContextParams - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithStaticContextParams( - OperationWithStaticContextParamsRequest operationWithStaticContextParamsRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithStaticContextParamsRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithStaticContextParamsRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithStaticContextParams"); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithStaticContextParamsResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithStaticContextParams").withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithStaticContextParamsRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withInput(operationWithStaticContextParamsRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the PutOperationWithChecksum operation asynchronously. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows ' - *

- * Object data. - *

- * '. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture putOperationWithChecksum( - PutOperationWithChecksumRequest putOperationWithChecksumRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - if (!isSignerOverridden(clientConfiguration)) { - putOperationWithChecksumRequest = applySignerOverride(putOperationWithChecksumRequest, AsyncAws4Signer.create()); - } - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(PutOperationWithChecksumResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withAsyncResponseTransformer(asyncResponseTransformer).withAsyncRequestBody(requestBody) - .withInput(putOperationWithChecksumRequest), asyncResponseTransformer); - CompletableFuture whenCompleteFuture = null; - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOperation( - StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - if (!isSignerOverridden(clientConfiguration)) { - streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create()); - } - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(StreamingInputOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody) - .withInput(streamingInputOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an - * instance of this type.
  • - *
- * @sample QueryAsyncClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(StreamingOutputOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(streamingOutputOperationRequest), - asyncResponseTransformer); - CompletableFuture whenCompleteFuture = null; - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - @Override - public QueryAsyncWaiter waiter() { - return QueryAsyncWaiter.builder().client(this).scheduledExecutorService(executorService).build(); - } - - @Override - public final QueryServiceClientConfiguration serviceClientConfiguration() { - return new QueryServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private AwsQueryProtocolFactory init() { - return AwsQueryProtocolFactory - .builder() - .registerModeledException( - ExceptionMetadata.builder().errorCode("InvalidInput") - .exceptionBuilderSupplier(InvalidInputException::builder).httpStatusCode(400).build()) - .clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(QueryException::builder).build(); - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - QueryServiceClientConfigurationBuilder serviceConfigBuilder = new QueryServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-client-class.java deleted file mode 100644 index 1ab2cfbdee69..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-client-class.java +++ /dev/null @@ -1,1075 +0,0 @@ -package software.amazon.awssdk.services.query; - -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.codegen.internal.UtilsTest; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.client.handler.SyncClientHandler; -import software.amazon.awssdk.core.exception.SdkClientException; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.StreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.sync.RequestBody; -import software.amazon.awssdk.core.sync.ResponseTransformer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.query.internal.QueryServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.query.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.query.model.APostOperationRequest; -import software.amazon.awssdk.services.query.model.APostOperationResponse; -import software.amazon.awssdk.services.query.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.query.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.query.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.query.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.query.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.query.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.query.model.InvalidInputException; -import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.query.model.OperationWithContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithCustomMemberRequest; -import software.amazon.awssdk.services.query.model.OperationWithCustomMemberResponse; -import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithMapOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithMapOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamRequest; -import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamResponse; -import software.amazon.awssdk.services.query.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.query.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.query.model.OperationWithStaticContextParamsRequest; -import software.amazon.awssdk.services.query.model.OperationWithStaticContextParamsResponse; -import software.amazon.awssdk.services.query.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.query.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.query.model.QueryException; -import software.amazon.awssdk.services.query.model.QueryRequest; -import software.amazon.awssdk.services.query.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.query.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.query.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.query.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.query.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.query.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithCustomMemberRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithCustomizedOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithMapOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithOperationContextParamRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.query.transform.OperationWithStaticContextParamsRequestMarshaller; -import software.amazon.awssdk.services.query.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.query.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.services.query.waiters.QueryWaiter; -import software.amazon.awssdk.utils.Logger; - -/** - * Internal implementation of {@link QueryClient}. - * - * @see QueryClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultQueryClient implements QueryClient { - private static final Logger log = Logger.loggerFor(DefaultQueryClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.QUERY).build(); - - private final SyncClientHandler clientHandler; - - private final AwsQueryProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - protected DefaultQueryClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsSyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Query_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(); - } - - /** - *

- * Performs a post operation to the query service and has no output - *

- * - * @param aPostOperationRequest - * @return Result of the APostOperation operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, - AwsServiceException, SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(APostOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - String hostPrefix = "foo-"; - String resolvedHostExpression = "foo-"; - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .hostPrefixExpression(resolvedHostExpression).withRequestConfiguration(clientConfiguration) - .withInput(aPostOperationRequest).withMetricCollector(apiCallMetricCollector) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - *

- * Performs a post operation to the query service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return Result of the APostOperationWithOutput operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public APostOperationWithOutputResponse aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) throws InvalidInputException, AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(APostOperationWithOutputResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(aPostOperationWithOutputRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the BearerAuthOperation operation. - * - * @param bearerAuthOperationRequest - * @return Result of the BearerAuthOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public BearerAuthOperationResponse bearerAuthOperation(BearerAuthOperationRequest bearerAuthOperationRequest) - throws AwsServiceException, SdkClientException, QueryException { - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(BearerAuthOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .credentialType(CredentialType.TOKEN).withRequestConfiguration(clientConfiguration) - .withInput(bearerAuthOperationRequest).withMetricCollector(apiCallMetricCollector) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the GetOperationWithChecksum operation. - * - * @param getOperationWithChecksumRequest - * @return Result of the GetOperationWithChecksum operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public GetOperationWithChecksumResponse getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) throws AwsServiceException, SdkClientException, - QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(GetOperationWithChecksumResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(getOperationWithChecksumRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation. - * - * @param operationWithChecksumRequiredRequest - * @return Result of the OperationWithChecksumRequired operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public OperationWithChecksumRequiredResponse operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) throws AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithChecksumRequiredResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithChecksumRequiredRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithContextParam operation. - * - * @param operationWithContextParamRequest - * @return Result of the OperationWithContextParam operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithContextParam - * @see AWS API Documentation - */ - @Override - public OperationWithContextParamResponse operationWithContextParam( - OperationWithContextParamRequest operationWithContextParamRequest) throws AwsServiceException, SdkClientException, - QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithContextParamRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithContextParam"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithContextParam").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(operationWithContextParamRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithContextParamRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithCustomMember operation. - * - * @param operationWithCustomMemberRequest - * @return Result of the OperationWithCustomMember operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithCustomMember - * @see AWS API Documentation - */ - @Override - public OperationWithCustomMemberResponse operationWithCustomMember( - OperationWithCustomMemberRequest operationWithCustomMemberRequest) throws AwsServiceException, SdkClientException, - QueryException { - operationWithCustomMemberRequest = UtilsTest.dummyRequestModifier(operationWithCustomMemberRequest); - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithCustomMemberResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithCustomMemberRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithCustomMemberRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomMember"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithCustomMember").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(operationWithCustomMemberRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithCustomMemberRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithCustomizedOperationContextParam operation. - * - * @param operationWithCustomizedOperationContextParamRequest - * @return Result of the OperationWithCustomizedOperationContextParam operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithCustomizedOperationContextParam - * @see AWS API Documentation - */ - @Override - public OperationWithCustomizedOperationContextParamResponse operationWithCustomizedOperationContextParam( - OperationWithCustomizedOperationContextParamRequest operationWithCustomizedOperationContextParamRequest) - throws AwsServiceException, SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithCustomizedOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration( - operationWithCustomizedOperationContextParamRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithCustomizedOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomizedOperationContextParam"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithCustomizedOperationContextParam") - .withProtocolMetadata(protocolMetadata).withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration) - .withInput(operationWithCustomizedOperationContextParamRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithCustomizedOperationContextParamRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithMapOperationContextParam operation. - * - * @param operationWithMapOperationContextParamRequest - * @return Result of the OperationWithMapOperationContextParam operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithMapOperationContextParam - * @see AWS API Documentation - */ - @Override - public OperationWithMapOperationContextParamResponse operationWithMapOperationContextParam( - OperationWithMapOperationContextParamRequest operationWithMapOperationContextParamRequest) - throws AwsServiceException, SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithMapOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithMapOperationContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithMapOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithMapOperationContextParam"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithMapOperationContextParam").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithMapOperationContextParamRequest).withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithMapOperationContextParamRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation. - * - * @param operationWithNoneAuthTypeRequest - * @return Result of the OperationWithNoneAuthType operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public OperationWithNoneAuthTypeResponse operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) throws AwsServiceException, SdkClientException, - QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithNoneAuthTypeResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(operationWithNoneAuthTypeRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithOperationContextParam operation. - * - * @param operationWithOperationContextParamRequest - * @return Result of the OperationWithOperationContextParam operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithOperationContextParam - * @see AWS API Documentation - */ - @Override - public OperationWithOperationContextParamResponse operationWithOperationContextParam( - OperationWithOperationContextParamRequest operationWithOperationContextParamRequest) throws AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithOperationContextParamResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithOperationContextParamRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithOperationContextParamRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithOperationContextParam"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithOperationContextParam").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(operationWithOperationContextParamRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithOperationContextParamRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithRequestCompression operation. - * - * @param operationWithRequestCompressionRequest - * @return Result of the OperationWithRequestCompression operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public OperationWithRequestCompressionResponse operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) throws AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithRequestCompressionResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithRequestCompressionRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithStaticContextParams operation. - * - * @param operationWithStaticContextParamsRequest - * @return Result of the OperationWithStaticContextParams operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.OperationWithStaticContextParams - * @see AWS API Documentation - */ - @Override - public OperationWithStaticContextParamsResponse operationWithStaticContextParams( - OperationWithStaticContextParamsRequest operationWithStaticContextParamsRequest) throws AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(OperationWithStaticContextParamsResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithStaticContextParamsRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithStaticContextParamsRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithStaticContextParams"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithStaticContextParams").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(operationWithStaticContextParamsRequest) - .withMetricCollector(apiCallMetricCollector) - .withMarshaller(new OperationWithStaticContextParamsRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the PutOperationWithChecksum operation. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * PutOperationWithChecksumResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows ' - *

- * Object data. - *

- * '. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public ReturnT putOperationWithChecksum(PutOperationWithChecksumRequest putOperationWithChecksumRequest, - RequestBody requestBody, ResponseTransformer responseTransformer) - throws AwsServiceException, SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(PutOperationWithChecksumResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(putOperationWithChecksumRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withResponseTransformer(responseTransformer) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build())); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows 'This be a stream' - * @return Result of the StreamingInputOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, - RequestBody requestBody) throws AwsServiceException, SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(StreamingInputOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(streamingInputOperationRequest) - .withMetricCollector(apiCallMetricCollector) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build())); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * StreamingOutputOperationResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows 'This be a stream'. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws QueryException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample QueryClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, - ResponseTransformer responseTransformer) throws AwsServiceException, - SdkClientException, QueryException { - - HttpResponseHandler responseHandler = protocolFactory - .createResponseHandler(StreamingOutputOperationResponse::builder); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - - return clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(streamingOutputOperationRequest) - .withMetricCollector(apiCallMetricCollector).withResponseTransformer(responseTransformer) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Create an instance of {@link QueryWaiter} using this client. - *

- * Waiters created via this method are managed by the SDK and resources will be released when the service client is - * closed. - * - * @return an instance of {@link QueryWaiter} - */ - @Override - public QueryWaiter waiter() { - return QueryWaiter.builder().client(this).build(); - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - QueryServiceClientConfigurationBuilder serviceConfigBuilder = new QueryServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private AwsQueryProtocolFactory init() { - return AwsQueryProtocolFactory - .builder() - .registerModeledException( - ExceptionMetadata.builder().errorCode("InvalidInput") - .exceptionBuilderSupplier(InvalidInputException::builder).httpStatusCode(400).build()) - .clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(QueryException::builder).build(); - } - - @Override - public final QueryServiceClientConfiguration serviceClientConfiguration() { - return new QueryServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-unsigned-payload-trait-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-unsigned-payload-trait-async-client-class.java index 28d0d93f8299..efa307505463 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-unsigned-payload-trait-async-client-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-unsigned-payload-trait-async-client-class.java @@ -12,8 +12,6 @@ import org.slf4j.LoggerFactory; import software.amazon.awssdk.annotations.Generated; import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; @@ -32,7 +30,6 @@ import software.amazon.awssdk.core.metrics.CoreMetric; import software.amazon.awssdk.core.retry.RetryMode; import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -45,7 +42,6 @@ import software.amazon.awssdk.services.database.internal.DatabaseServiceClientConfigurationBuilder; import software.amazon.awssdk.services.database.internal.ServiceVersionInfo; import software.amazon.awssdk.services.database.model.DatabaseException; -import software.amazon.awssdk.services.database.model.DatabaseRequest; import software.amazon.awssdk.services.database.model.DeleteRowRequest; import software.amazon.awssdk.services.database.model.DeleteRowResponse; import software.amazon.awssdk.services.database.model.GetRowRequest; @@ -518,10 +514,6 @@ public CompletableFuture opWithS try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Database Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "opWithSigv4UnSignedPayloadAndStreaming"); - if (!isSignerOverridden(clientConfiguration)) { - opWithSigv4UnSignedPayloadAndStreamingRequest = applySignerOverride( - opWithSigv4UnSignedPayloadAndStreamingRequest, AsyncAws4Signer.create()); - } JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); @@ -969,21 +961,6 @@ private static List resolveMetricPublishers(SdkClientConfigurat return publishers; } - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); RetryMode retryMode = builder.retryMode(); diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-async-client-class.java deleted file mode 100644 index f9a463abbd47..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-async-client-class.java +++ /dev/null @@ -1,972 +0,0 @@ -package software.amazon.awssdk.services.xml; - -import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.function.Consumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AsyncAws4Signer; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; -import software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier; -import software.amazon.awssdk.awscore.eventstream.RestEventStreamAsyncResponseTransformer; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.Response; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkPojoBuilder; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.async.AsyncResponseTransformer; -import software.amazon.awssdk.core.async.AsyncResponseTransformerUtils; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.AsyncClientHandler; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.xml.AwsXmlProtocolFactory; -import software.amazon.awssdk.protocols.xml.XmlOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.xml.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.xml.internal.XmlServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.xml.model.APostOperationRequest; -import software.amazon.awssdk.services.xml.model.APostOperationResponse; -import software.amazon.awssdk.services.xml.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.xml.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.xml.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.xml.model.EventStream; -import software.amazon.awssdk.services.xml.model.EventStreamOperationRequest; -import software.amazon.awssdk.services.xml.model.EventStreamOperationResponse; -import software.amazon.awssdk.services.xml.model.EventStreamOperationResponseHandler; -import software.amazon.awssdk.services.xml.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.xml.model.InvalidInputException; -import software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.xml.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.xml.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.xml.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.xml.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.xml.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.xml.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.xml.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.xml.model.XmlException; -import software.amazon.awssdk.services.xml.model.XmlRequest; -import software.amazon.awssdk.services.xml.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.EventStreamOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.CompletableFutureUtils; -import software.amazon.awssdk.utils.Pair; - -/** - * Internal implementation of {@link XmlAsyncClient}. - * - * @see XmlAsyncClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultXmlAsyncClient implements XmlAsyncClient { - private static final Logger log = LoggerFactory.getLogger(DefaultXmlAsyncClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.REST_XML).build(); - - private final AsyncClientHandler clientHandler; - - private final AwsXmlProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - private final Executor executor; - - protected DefaultXmlAsyncClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsAsyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Xml_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(); - this.executor = clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); - } - - /** - *

- * Performs a post operation to the xml service and has no output - *

- * - * @param aPostOperationRequest - * @return A Java Future containing the result of the APostOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public CompletableFuture aPostOperation(APostOperationRequest aPostOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(APostOperationResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - String hostPrefix = "foo-"; - String resolvedHostExpression = "foo-"; - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperation").withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler).hostPrefixExpression(resolvedHostExpression) - .withMetricCollector(apiCallMetricCollector).withInput(aPostOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - *

- * Performs a post operation to the xml service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return A Java Future containing the result of the APostOperationWithOutput operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • InvalidInputException The request was rejected because an invalid or out-of-range value was supplied - * for an input parameter.
  • - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public CompletableFuture aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(APostOperationWithOutputResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .withInput(aPostOperationWithOutputRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the BearerAuthOperation operation asynchronously. - * - * @param bearerAuthOperationRequest - * @return A Java Future containing the result of the BearerAuthOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture bearerAuthOperation( - BearerAuthOperationRequest bearerAuthOperationRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(BearerAuthOperationResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler).credentialType(CredentialType.TOKEN) - .withMetricCollector(apiCallMetricCollector).withInput(bearerAuthOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the EventStreamOperation operation asynchronously. - * - * @param eventStreamOperationRequest - * @return A Java Future containing the result of the EventStreamOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.EventStreamOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture eventStreamOperation(EventStreamOperationRequest eventStreamOperationRequest, - EventStreamOperationResponseHandler asyncResponseHandler) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(eventStreamOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperation"); - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - EventStreamOperationResponse::builder, XmlOperationMetadata.builder().hasStreamingSuccessResponse(true) - .build()); - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - HttpResponseHandler eventResponseHandler = protocolFactory.createResponseHandler( - EventStreamTaggedUnionPojoSupplier.builder() - .putSdkPojoSupplier("EventPayloadEvent", EventStream::eventPayloadEventBuilder) - .putSdkPojoSupplier("NonEventPayloadEvent", EventStream::nonEventPayloadEventBuilder) - .putSdkPojoSupplier("SecondEventPayloadEvent", EventStream::secondEventPayloadEventBuilder) - .defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build(), XmlOperationMetadata - .builder().hasStreamingSuccessResponse(false).build()); - CompletableFuture eventStreamTransformFuture = new CompletableFuture<>(); - EventStreamAsyncResponseTransformer asyncResponseTransformer = EventStreamAsyncResponseTransformer - . builder().eventStreamResponseHandler(asyncResponseHandler) - .eventResponseHandler(eventResponseHandler).initialResponseHandler(responseHandler) - .exceptionResponseHandler(errorResponseHandler).future(eventStreamTransformFuture).executor(executor) - .serviceName(serviceName()).build(); - RestEventStreamAsyncResponseTransformer restAsyncResponseTransformer = RestEventStreamAsyncResponseTransformer - . builder() - .eventStreamAsyncResponseTransformer(asyncResponseTransformer) - .eventStreamResponseHandler(asyncResponseHandler).build(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("EventStreamOperation").withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationRequest), - restAsyncResponseTransformer); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(e)); - eventStreamTransformFuture.completeExceptionally(e); - } - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return CompletableFutureUtils.forwardExceptionTo(eventStreamTransformFuture, executeFuture); - } catch (Throwable t) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> asyncResponseHandler.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the GetOperationWithChecksum operation asynchronously. - * - * @param getOperationWithChecksumRequest - * @return A Java Future containing the result of the GetOperationWithChecksum operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(GetOperationWithChecksumResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withInput(getOperationWithChecksumRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation asynchronously. - * - * @param operationWithChecksumRequiredRequest - * @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithChecksumRequiredResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation asynchronously. - * - * @param operationWithNoneAuthTypeRequest - * @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithNoneAuthTypeResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withInput(operationWithNoneAuthTypeRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the OperationWithRequestCompression operation asynchronously. - * - * @param operationWithRequestCompressionRequest - * @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the - * service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public CompletableFuture operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithRequestCompressionResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory)) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withInput(operationWithRequestCompressionRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Invokes the PutOperationWithChecksum operation asynchronously. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows ' - *

- * Object data. - *

- * '. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public CompletableFuture putOperationWithChecksum( - PutOperationWithChecksumRequest putOperationWithChecksumRequest, AsyncRequestBody requestBody, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - if (!isSignerOverridden(clientConfiguration)) { - putOperationWithChecksumRequest = applySignerOverride(putOperationWithChecksumRequest, AsyncAws4Signer.create()); - } - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - PutOperationWithChecksumResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(true)); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withAsyncResponseTransformer(asyncResponseTransformer).withAsyncRequestBody(requestBody) - .withInput(putOperationWithChecksumRequest), asyncResponseTransformer); - CompletableFuture whenCompleteFuture = null; - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * Functional interface that can be implemented to produce the request content in a non-blocking manner. The - * size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on - * implementing this interface as well as links to precanned implementations for common scenarios like - * uploading from a file. The service documentation for the request content is as follows 'This be a stream' - * @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingInputOperation( - StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - if (!isSignerOverridden(clientConfiguration)) { - streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create()); - } - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(StreamingInputOperationResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - - CompletableFuture executeFuture = clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withRequestConfiguration(clientConfiguration) - .withProtocolMetadata(protocolMetadata) - .withMarshaller( - AsyncStreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .asyncRequestBody(requestBody).build()).withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody) - .withInput(streamingInputOperationRequest)); - CompletableFuture whenCompleteFuture = null; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - return whenCompleteFuture; - } catch (Throwable t) { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param asyncResponseTransformer - * The response transformer for processing the streaming response in a non-blocking manner. See - * {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to - * precanned implementations for common scenarios like downloading to a file. The service documentation for - * the response content is as follows 'This be a stream'. - * @return A future to the transformed result of the AsyncResponseTransformer.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. The exception returned is wrapped with CompletionException, so you need to invoke - * {@link Throwable#getCause} to retrieve the underlying exception. - *
    - *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). - * Can be used for catch all scenarios.
  • - *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get - * credentials, etc.
  • - *
  • XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance - * of this type.
  • - *
- * @sample XmlAsyncClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public CompletableFuture streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, - AsyncResponseTransformer asyncResponseTransformer) { - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - Pair, CompletableFuture> pair = AsyncResponseTransformerUtils - .wrapWithEndOfStreamFuture(asyncResponseTransformer); - asyncResponseTransformer = pair.left(); - CompletableFuture endOfStreamFuture = pair.right(); - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - StreamingOutputOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(true)); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - - CompletableFuture executeFuture = clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) - .withAsyncResponseTransformer(asyncResponseTransformer).withInput(streamingOutputOperationRequest), - asyncResponseTransformer); - CompletableFuture whenCompleteFuture = null; - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - whenCompleteFuture = executeFuture.whenComplete((r, e) -> { - if (e != null) { - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(e)); - } - endOfStreamFuture.whenComplete((r2, e2) -> { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - }); - }); - return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture); - } catch (Throwable t) { - AsyncResponseTransformer finalAsyncResponseTransformer = asyncResponseTransformer; - runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", - () -> finalAsyncResponseTransformer.exceptionOccurred(t)); - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - return CompletableFutureUtils.failedFuture(t); - } - } - - @Override - public final XmlServiceClientConfiguration serviceClientConfiguration() { - return new XmlServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private AwsXmlProtocolFactory init() { - return AwsXmlProtocolFactory - .builder() - .registerModeledException( - ExceptionMetadata.builder().errorCode("InvalidInput") - .exceptionBuilderSupplier(InvalidInputException::builder).httpStatusCode(400).build()) - .clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(XmlException::builder).build(); - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - private static boolean isSignerOverridden(SdkClientConfiguration clientConfiguration) { - return Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.SIGNER_OVERRIDDEN)); - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - XmlServiceClientConfigurationBuilder serviceConfigBuilder = new XmlServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-client-class.java deleted file mode 100644 index 5bdbf079888c..000000000000 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-client-class.java +++ /dev/null @@ -1,741 +0,0 @@ -package software.amazon.awssdk.services.xml; - -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import software.amazon.awssdk.annotations.Generated; -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner; -import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; -import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler; -import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata; -import software.amazon.awssdk.awscore.internal.AwsServiceProtocol; -import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; -import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm; -import software.amazon.awssdk.core.CredentialType; -import software.amazon.awssdk.core.RequestOverrideConfiguration; -import software.amazon.awssdk.core.Response; -import software.amazon.awssdk.core.SdkPlugin; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientConfiguration; -import software.amazon.awssdk.core.client.config.SdkClientOption; -import software.amazon.awssdk.core.client.handler.ClientExecutionParams; -import software.amazon.awssdk.core.client.handler.SyncClientHandler; -import software.amazon.awssdk.core.exception.SdkClientException; -import software.amazon.awssdk.core.http.HttpResponseHandler; -import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired; -import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression; -import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.core.runtime.transform.StreamingRequestMarshaller; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.sync.RequestBody; -import software.amazon.awssdk.core.sync.ResponseTransformer; -import software.amazon.awssdk.metrics.MetricCollector; -import software.amazon.awssdk.metrics.MetricPublisher; -import software.amazon.awssdk.metrics.NoOpMetricCollector; -import software.amazon.awssdk.protocols.core.ExceptionMetadata; -import software.amazon.awssdk.protocols.xml.AwsXmlProtocolFactory; -import software.amazon.awssdk.protocols.xml.XmlOperationMetadata; -import software.amazon.awssdk.retries.api.RetryStrategy; -import software.amazon.awssdk.services.xml.internal.ServiceVersionInfo; -import software.amazon.awssdk.services.xml.internal.XmlServiceClientConfigurationBuilder; -import software.amazon.awssdk.services.xml.model.APostOperationRequest; -import software.amazon.awssdk.services.xml.model.APostOperationResponse; -import software.amazon.awssdk.services.xml.model.APostOperationWithOutputRequest; -import software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse; -import software.amazon.awssdk.services.xml.model.BearerAuthOperationRequest; -import software.amazon.awssdk.services.xml.model.BearerAuthOperationResponse; -import software.amazon.awssdk.services.xml.model.GetOperationWithChecksumRequest; -import software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse; -import software.amazon.awssdk.services.xml.model.InvalidInputException; -import software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredRequest; -import software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse; -import software.amazon.awssdk.services.xml.model.OperationWithNoneAuthTypeRequest; -import software.amazon.awssdk.services.xml.model.OperationWithNoneAuthTypeResponse; -import software.amazon.awssdk.services.xml.model.OperationWithRequestCompressionRequest; -import software.amazon.awssdk.services.xml.model.OperationWithRequestCompressionResponse; -import software.amazon.awssdk.services.xml.model.PutOperationWithChecksumRequest; -import software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse; -import software.amazon.awssdk.services.xml.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse; -import software.amazon.awssdk.services.xml.model.StreamingOutputOperationRequest; -import software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse; -import software.amazon.awssdk.services.xml.model.XmlException; -import software.amazon.awssdk.services.xml.model.XmlRequest; -import software.amazon.awssdk.services.xml.transform.APostOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.APostOperationWithOutputRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.BearerAuthOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.GetOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithChecksumRequiredRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithNoneAuthTypeRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.OperationWithRequestCompressionRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.PutOperationWithChecksumRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.StreamingInputOperationRequestMarshaller; -import software.amazon.awssdk.services.xml.transform.StreamingOutputOperationRequestMarshaller; -import software.amazon.awssdk.utils.Logger; - -/** - * Internal implementation of {@link XmlClient}. - * - * @see XmlClient#builder() - */ -@Generated("software.amazon.awssdk:codegen") -@SdkInternalApi -final class DefaultXmlClient implements XmlClient { - private static final Logger log = Logger.loggerFor(DefaultXmlClient.class); - - private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder() - .serviceProtocol(AwsServiceProtocol.REST_XML).build(); - - private final SyncClientHandler clientHandler; - - private final AwsXmlProtocolFactory protocolFactory; - - private final SdkClientConfiguration clientConfiguration; - - protected DefaultXmlClient(SdkClientConfiguration clientConfiguration) { - this.clientHandler = new AwsSyncClientHandler(clientConfiguration); - this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this) - .option(SdkClientOption.API_METADATA, "Xml_Service" + "#" + ServiceVersionInfo.VERSION).build(); - this.protocolFactory = init(); - } - - /** - *

- * Performs a post operation to the xml service and has no output - *

- * - * @param aPostOperationRequest - * @return Result of the APostOperation operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.APostOperation - * @see AWS - * API Documentation - */ - @Override - public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, - AwsServiceException, SdkClientException, XmlException { - - HttpResponseHandler> responseHandler = protocolFactory.createCombinedResponseHandler( - APostOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationRequest, this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation"); - String hostPrefix = "foo-"; - String resolvedHostExpression = "foo-"; - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("APostOperation").withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .hostPrefixExpression(resolvedHostExpression).withRequestConfiguration(clientConfiguration) - .withInput(aPostOperationRequest).withMarshaller(new APostOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - *

- * Performs a post operation to the xml service and has modelled output - *

- * - * @param aPostOperationWithOutputRequest - * @return Result of the APostOperationWithOutput operation returned by the service. - * @throws InvalidInputException - * The request was rejected because an invalid or out-of-range value was supplied for an input parameter. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.APostOperationWithOutput - * @see AWS API Documentation - */ - @Override - public APostOperationWithOutputResponse aPostOperationWithOutput( - APostOperationWithOutputRequest aPostOperationWithOutputRequest) throws InvalidInputException, AwsServiceException, - SdkClientException, XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(APostOperationWithOutputResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(aPostOperationWithOutputRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("APostOperationWithOutput").withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration).withInput(aPostOperationWithOutputRequest) - .withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the BearerAuthOperation operation. - * - * @param bearerAuthOperationRequest - * @return Result of the BearerAuthOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.BearerAuthOperation - * @see AWS API Documentation - */ - @Override - public BearerAuthOperationResponse bearerAuthOperation(BearerAuthOperationRequest bearerAuthOperationRequest) - throws AwsServiceException, SdkClientException, XmlException { - bearerAuthOperationRequest = applySignerOverride(bearerAuthOperationRequest, BearerTokenSigner.create()); - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(BearerAuthOperationResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(bearerAuthOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, bearerAuthOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BearerAuthOperation"); - - return clientHandler.execute(new ClientExecutionParams() - .withOperationName("BearerAuthOperation").withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .credentialType(CredentialType.TOKEN).withRequestConfiguration(clientConfiguration) - .withInput(bearerAuthOperationRequest) - .withMarshaller(new BearerAuthOperationRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the GetOperationWithChecksum operation. - * - * @param getOperationWithChecksumRequest - * @return Result of the GetOperationWithChecksum operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.GetOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public GetOperationWithChecksumResponse getOperationWithChecksum( - GetOperationWithChecksumRequest getOperationWithChecksumRequest) throws AwsServiceException, SdkClientException, - XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(GetOperationWithChecksumResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("GetOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration) - .withInput(getOperationWithChecksumRequest) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum.builder().requestChecksumRequired(true).isRequestStreaming(false) - .requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()) - .requestAlgorithmHeader("x-amz-sdk-checksum-algorithm").build()) - .withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithChecksumRequired operation. - * - * @param operationWithChecksumRequiredRequest - * @return Result of the OperationWithChecksumRequired operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.OperationWithChecksumRequired - * @see AWS API Documentation - */ - @Override - public OperationWithChecksumRequiredResponse operationWithChecksumRequired( - OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) throws AwsServiceException, - SdkClientException, XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithChecksumRequiredResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithChecksumRequiredRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithChecksumRequired") - .withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithChecksumRequiredRequest) - .putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, - HttpChecksumRequired.create()) - .withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithNoneAuthType operation. - * - * @param operationWithNoneAuthTypeRequest - * @return Result of the OperationWithNoneAuthType operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.OperationWithNoneAuthType - * @see AWS API Documentation - */ - @Override - public OperationWithNoneAuthTypeResponse operationWithNoneAuthType( - OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) throws AwsServiceException, SdkClientException, - XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithNoneAuthTypeResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithNoneAuthTypeRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithNoneAuthType").withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration).withInput(operationWithNoneAuthTypeRequest) - .putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false) - .withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the OperationWithRequestCompression operation. - * - * @param operationWithRequestCompressionRequest - * @return Result of the OperationWithRequestCompression operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.OperationWithRequestCompression - * @see AWS API Documentation - */ - @Override - public OperationWithRequestCompressionResponse operationWithRequestCompression( - OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) throws AwsServiceException, - SdkClientException, XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(OperationWithRequestCompressionResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(operationWithRequestCompressionRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, - operationWithRequestCompressionRequest.overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithRequestCompression"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("OperationWithRequestCompression") - .withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration) - .withInput(operationWithRequestCompressionRequest) - .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION, - RequestCompression.builder().encodings("gzip").isStreaming(false).build()) - .withMarshaller(new OperationWithRequestCompressionRequestMarshaller(protocolFactory))); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Invokes the PutOperationWithChecksum operation. - * - * @param putOperationWithChecksumRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows ' - *

- * Object data. - *

- * ' - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * PutOperationWithChecksumResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows ' - *

- * Object data. - *

- * '. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.PutOperationWithChecksum - * @see AWS API Documentation - */ - @Override - public ReturnT putOperationWithChecksum(PutOperationWithChecksumRequest putOperationWithChecksumRequest, - RequestBody requestBody, ResponseTransformer responseTransformer) - throws AwsServiceException, SdkClientException, XmlException { - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - PutOperationWithChecksumResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(true)); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(putOperationWithChecksumRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("PutOperationWithChecksum") - .withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler) - .withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration) - .withInput(putOperationWithChecksumRequest) - .withMetricCollector(apiCallMetricCollector) - .putExecutionAttribute( - SdkInternalExecutionAttribute.HTTP_CHECKSUM, - HttpChecksum - .builder() - .requestChecksumRequired(false) - .isRequestStreaming(true) - .requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()) - .responseAlgorithmsV2(DefaultChecksumAlgorithm.CRC32C, - DefaultChecksumAlgorithm.CRC32, DefaultChecksumAlgorithm.SHA1, - DefaultChecksumAlgorithm.SHA256).build()) - .withResponseTransformer(responseTransformer) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build())); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param requestBody - * The content to send to the service. A {@link RequestBody} can be created using one of several factory - * methods for various sources of data. For example, to create a request body from a file you can do the - * following. - * - *
-     * {@code RequestBody.fromFile(new File("myfile.txt"))}
-     * 
- * - * See documentation in {@link RequestBody} for additional details and which sources of data are supported. - * The service documentation for the request content is as follows 'This be a stream' - * @return Result of the StreamingInputOperation operation returned by the service. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.StreamingInputOperation - * @see AWS API Documentation - */ - @Override - public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, - RequestBody requestBody) throws AwsServiceException, SdkClientException, XmlException { - - HttpResponseHandler> responseHandler = protocolFactory - .createCombinedResponseHandler(StreamingInputOperationResponse::builder, - new XmlOperationMetadata().withHasStreamingSuccessResponse(false)); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingInputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation"); - - return clientHandler - .execute(new ClientExecutionParams() - .withOperationName("StreamingInputOperation") - .withProtocolMetadata(protocolMetadata) - .withCombinedResponseHandler(responseHandler) - .withMetricCollector(apiCallMetricCollector) - .withRequestConfiguration(clientConfiguration) - .withInput(streamingInputOperationRequest) - .withRequestBody(requestBody) - .withMarshaller( - StreamingRequestMarshaller.builder() - .delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)) - .requestBody(requestBody).build())); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param responseTransformer - * Functional interface for processing the streamed response content. The unmarshalled - * StreamingOutputOperationResponse and an InputStream to the response content are provided as parameters to - * the callback. The callback may return a transformed type which will be the return value of this method. - * See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this - * interface and for links to pre-canned implementations for common scenarios like downloading to a file. The - * service documentation for the response content is as follows 'This be a stream'. - * @return The transformed result of the ResponseTransformer. - * @throws SdkException - * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for - * catch all scenarios. - * @throws SdkClientException - * If any client side error occurs such as an IO related failure, failure to get credentials, etc. - * @throws XmlException - * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. - * @sample XmlClient.StreamingOutputOperation - * @see AWS API Documentation - */ - @Override - public ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, - ResponseTransformer responseTransformer) throws AwsServiceException, - SdkClientException, XmlException { - - HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( - StreamingOutputOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(true)); - - HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(); - SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(streamingOutputOperationRequest, - this.clientConfiguration); - List metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest - .overrideConfiguration().orElse(null)); - MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector - .create("ApiCall"); - try { - apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service"); - apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation"); - - return clientHandler.execute( - new ClientExecutionParams() - .withOperationName("StreamingOutputOperation").withProtocolMetadata(protocolMetadata) - .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) - .withRequestConfiguration(clientConfiguration).withInput(streamingOutputOperationRequest) - .withMetricCollector(apiCallMetricCollector).withResponseTransformer(responseTransformer) - .withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer); - } finally { - metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); - } - } - - private T applySignerOverride(T request, Signer signer) { - if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { - return request; - } - Consumer signerOverride = b -> b.signer(signer).build(); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(signerOverride).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - - @Override - public final String serviceName() { - return SERVICE_NAME; - } - - private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, - RequestOverrideConfiguration requestOverrideConfiguration) { - List publishers = null; - if (requestOverrideConfiguration != null) { - publishers = requestOverrideConfiguration.metricPublishers(); - } - if (publishers == null || publishers.isEmpty()) { - publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); - } - if (publishers == null) { - publishers = Collections.emptyList(); - } - return publishers; - } - - private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { - ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); - RetryMode retryMode = builder.retryMode(); - if (retryMode != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); - } else { - Consumer> configurator = builder.retryStrategyConfigurator(); - if (configurator != null) { - RetryStrategy.Builder defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); - configurator.accept(defaultBuilder); - configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); - } else { - RetryStrategy retryStrategy = builder.retryStrategy(); - if (retryStrategy != null) { - configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); - } - } - } - configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); - configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); - } - - private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) { - List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList()); - if (plugins.isEmpty()) { - return clientConfiguration; - } - SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder(); - XmlServiceClientConfigurationBuilder serviceConfigBuilder = new XmlServiceClientConfigurationBuilder(configuration); - for (SdkPlugin plugin : plugins) { - plugin.configureClient(serviceConfigBuilder); - } - updateRetryStrategyClientConfiguration(configuration); - return configuration.build(); - } - - private AwsXmlProtocolFactory init() { - return AwsXmlProtocolFactory - .builder() - .registerModeledException( - ExceptionMetadata.builder().errorCode("InvalidInput") - .exceptionBuilderSupplier(InvalidInputException::builder).httpStatusCode(400).build()) - .clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(XmlException::builder).build(); - } - - @Override - public final XmlServiceClientConfiguration serviceClientConfiguration() { - return new XmlServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); - } - - @Override - public void close() { - clientHandler.close(); - } -} diff --git a/test/codegen-generated-classes-test/src/main/resources/codegen-resources/customresponsemetadata/customization.config b/test/codegen-generated-classes-test/src/main/resources/codegen-resources/customresponsemetadata/customization.config index b23341dbf867..6e36494389ca 100644 --- a/test/codegen-generated-classes-test/src/main/resources/codegen-resources/customresponsemetadata/customization.config +++ b/test/codegen-generated-classes-test/src/main/resources/codegen-resources/customresponsemetadata/customization.config @@ -23,7 +23,6 @@ "requiredTraitValidationEnabled": true, "delegateAsyncClientClass": true, "delegateSyncClientClass": true, - "useSraAuth": true, "endpointParameters": { "Tables": { "required": false,