diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonGeneratorTasks.java b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonGeneratorTasks.java index a6f32ea9fae..42a06f58254 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonGeneratorTasks.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonGeneratorTasks.java @@ -28,6 +28,6 @@ class CommonGeneratorTasks extends CompositeGeneratorTask { new ModelClassGeneratorTasks(params), new PackageInfoGeneratorTasks(params), new BaseExceptionClassGeneratorTasks(params), - new ClientOptionsClassGeneratorTasks(params)); + new CommonInternalGeneratorTasks(params)); } } diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/ClientOptionsClassGeneratorTasks.java b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonInternalGeneratorTasks.java similarity index 61% rename from codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/ClientOptionsClassGeneratorTasks.java rename to codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonInternalGeneratorTasks.java index cfb067a10ff..7d407f582f7 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/ClientOptionsClassGeneratorTasks.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/CommonInternalGeneratorTasks.java @@ -15,26 +15,35 @@ package software.amazon.awssdk.codegen.emitters.tasks; -import java.util.Collections; +import java.util.Arrays; import java.util.List; import software.amazon.awssdk.codegen.emitters.GeneratorTask; import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams; import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask; import software.amazon.awssdk.codegen.poet.client.SdkClientOptions; +import software.amazon.awssdk.codegen.poet.common.UserAgentUtilsSpec; -public class ClientOptionsClassGeneratorTasks extends BaseGeneratorTasks { +public class CommonInternalGeneratorTasks extends BaseGeneratorTasks { private final GeneratorTaskParams params; - public ClientOptionsClassGeneratorTasks(GeneratorTaskParams params) { + public CommonInternalGeneratorTasks(GeneratorTaskParams params) { super(params); this.params = params; } @Override protected List createTasks() throws Exception { - return Collections.singletonList( - new PoetGeneratorTask(clientOptionsDir(), params.getModel().getFileHeader(), new SdkClientOptions(params.getModel())) - ); + return Arrays.asList(createClientOptionTask(), createUserAgentTask()); + } + + private PoetGeneratorTask createClientOptionTask() { + return new PoetGeneratorTask(clientOptionsDir(), params.getModel().getFileHeader(), + new SdkClientOptions(params.getModel())); + } + + private PoetGeneratorTask createUserAgentTask() { + return new PoetGeneratorTask(clientOptionsDir(), params.getModel().getFileHeader(), + new UserAgentUtilsSpec(params.getModel())); } private String clientOptionsDir() { diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/PoetExtension.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/PoetExtension.java index ba37f496c4c..5061de08894 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/PoetExtension.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/PoetExtension.java @@ -73,6 +73,10 @@ public ClassName getServiceConfigClass() { + model.getMetadata().getServiceName() + "ServiceClientConfiguration"); } + public ClassName getUserAgentClass() { + return ClassName.get(model.getMetadata().getFullClientInternalPackageName(), "UserAgentUtils"); + } + /** * @param operationName Name of the operation * @return A Poet {@link ClassName} for the response type of a paginated operation in the base service package. 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 207befab007..9b66f9a2825 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 @@ -24,7 +24,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.applyPaginatorUserAgentMethod; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.applySignerOverrideMethod; import static software.amazon.awssdk.codegen.poet.client.SyncClientClass.getProtocolSpecs; @@ -155,10 +154,6 @@ protected void addAdditionalMethods(TypeSpec.Builder type) { .addMethod(protocolSpec.initProtocolFactory(model)) .addMethod(resolveMetricPublishersMethod()); - if (model.hasPaginators()) { - type.addMethod(applyPaginatorUserAgentMethod(poetExtensions, model)); - } - if (model.containsRequestSigners() || model.containsRequestEventStreams() || hasStreamingV4AuthOperations()) { type.addMethod(applySignerOverrideMethod(poetExtensions, model)); type.addMethod(isSignerOverriddenOnClientMethod()); @@ -196,9 +191,6 @@ protected List operations() { private Stream operations(OperationModel opModel) { List methods = new ArrayList<>(); methods.add(traditionalMethod(opModel)); - if (opModel.isPaginated()) { - methods.add(paginatedTraditionalMethod(opModel)); - } return methods.stream(); } @@ -420,14 +412,6 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation return builder; } - @Override - protected MethodSpec.Builder paginatedMethodBody(MethodSpec.Builder builder, OperationModel opModel) { - return builder.addModifiers(PUBLIC) - .addStatement("return new $T(this, applyPaginatorUserAgent($L))", - poetExtensions.getResponseClassForPaginatedAsyncOperation(opModel.getOperationName()), - opModel.getInput().getVariableName()); - } - @Override public ClassName className() { return className; diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java index 3b06ba325db..04f64c1b128 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java @@ -201,21 +201,34 @@ private MethodSpec builder() { */ protected Iterable operations() { return model.getOperations().values().stream() - .flatMap(this::operationsAndSimpleMethods) + .flatMap(this::operationsWithVariants) .sorted(Comparator.comparing(m -> m.name)) .collect(toList()); } - private Stream operationsAndSimpleMethods(OperationModel operationModel) { + private Stream operationsWithVariants(OperationModel operationModel) { List methods = new ArrayList<>(); - methods.addAll(traditionalMethods(operationModel)); - methods.addAll(overloadMethods(operationModel)); + methods.addAll(traditionalMethodWithConsumerVariant(operationModel)); + methods.addAll(overloadedMethods(operationModel)); methods.addAll(paginatedMethods(operationModel)); return methods.stream() // Add Deprecated annotation if needed to all overloads .map(m -> DeprecationUtils.checkDeprecated(operationModel, m)); } + /** + * Generates the traditional method for an operation (i.e. one that takes a request and returns a response). + */ + private List traditionalMethodWithConsumerVariant(OperationModel opModel) { + List methods = new ArrayList<>(); + String consumerBuilderJavadoc = consumerBuilderJavadoc(opModel, SimpleMethodOverload.NORMAL); + + methods.add(traditionalMethod(opModel)); + methods.add(ClientClassUtils.consumerBuilderVariant(methods.get(0), consumerBuilderJavadoc)); + + return methods; + } + private List paginatedMethods(OperationModel opModel) { List methods = new ArrayList<>(); @@ -251,7 +264,9 @@ protected MethodSpec paginatedTraditionalMethod(OperationModel opModel) { protected MethodSpec.Builder paginatedMethodBody(MethodSpec.Builder builder, OperationModel operationModel) { return builder.addModifiers(DEFAULT, PUBLIC) - .addStatement("throw new $T()", UnsupportedOperationException.class); + .addStatement("return new $T(this, $L)", + poetExtensions.getResponseClassForPaginatedAsyncOperation(operationModel.getOperationName()), + operationModel.getInput().getVariableName()); } private MethodSpec paginatedSimpleMethod(OperationModel opModel) { @@ -274,7 +289,7 @@ private MethodSpec paginatedSimpleMethod(OperationModel opModel) { * @param opModel Operation to generate simple methods for. * @return All simple method overloads for a given operation. */ - private List overloadMethods(OperationModel opModel) { + private List overloadedMethods(OperationModel opModel) { String consumerBuilderFileJavadoc = consumerBuilderJavadoc(opModel, SimpleMethodOverload.FILE); List methodOverloads = new ArrayList<>(); @@ -312,20 +327,6 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation .addStatement("throw new $T()", UnsupportedOperationException.class); } - /** - * Generates the traditional method for an operation (i.e. one that takes a request and returns a response). - */ - private List traditionalMethods(OperationModel opModel) { - List methods = new ArrayList<>(); - - methods.add(traditionalMethod(opModel)); - - String consumerBuilderJavadoc = consumerBuilderJavadoc(opModel, SimpleMethodOverload.NORMAL); - methods.add(ClientClassUtils.consumerBuilderVariant(methods.get(0), consumerBuilderJavadoc)); - - return methods; - } - protected MethodSpec traditionalMethod(OperationModel opModel) { ClassName responsePojoType = getPojoResponseType(opModel); ClassName requestType = ClassName.get(modelPackage, opModel.getInput().getVariableType()); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/ClientClassUtils.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/ClientClassUtils.java index 046c9bacfc0..c31d4ab0345 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/ClientClassUtils.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/ClientClassUtils.java @@ -40,15 +40,12 @@ import software.amazon.awssdk.codegen.model.service.HostPrefixProcessor; import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.PoetUtils; -import software.amazon.awssdk.core.ApiName; import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.util.VersionInfo; import software.amazon.awssdk.utils.HostnameValidator; import software.amazon.awssdk.utils.StringUtils; import software.amazon.awssdk.utils.Validate; final class ClientClassUtils { - private static final String PAGINATOR_USER_AGENT = "PAGINATED"; private ClientClassUtils() { } @@ -85,40 +82,6 @@ static MethodSpec consumerBuilderVariant(MethodSpec spec, String javadoc) { return result.build(); } - static MethodSpec applyPaginatorUserAgentMethod(PoetExtension poetExtensions, IntermediateModel model) { - - TypeVariableName typeVariableName = - TypeVariableName.get("T", poetExtensions.getModelClass(model.getSdkRequestBaseClassName())); - - ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName - .get(ClassName.get(Consumer.class), ClassName.get(AwsRequestOverrideConfiguration.Builder.class)); - - CodeBlock codeBlock = CodeBlock.builder() - .addStatement("$T userAgentApplier = b -> b.addApiName($T.builder().version" - + "($T.SDK_VERSION).name($S).build())", - parameterizedTypeName, ApiName.class, - VersionInfo.class, - PAGINATOR_USER_AGENT) - .addStatement("$T overrideConfiguration =\n" - + " request.overrideConfiguration().map(c -> c.toBuilder()" - + ".applyMutation" - + "(userAgentApplier).build())\n" - + " .orElse((AwsRequestOverrideConfiguration.builder()" - + ".applyMutation" - + "(userAgentApplier).build()))", AwsRequestOverrideConfiguration.class) - .addStatement("return (T) request.toBuilder().overrideConfiguration" - + "(overrideConfiguration).build()") - .build(); - - return MethodSpec.methodBuilder("applyPaginatorUserAgent") - .addModifiers(Modifier.PRIVATE) - .addParameter(typeVariableName, "request") - .addTypeVariable(typeVariableName) - .addCode(codeBlock) - .returns(typeVariableName) - .build(); - } - static MethodSpec applySignerOverrideMethod(PoetExtension poetExtensions, IntermediateModel model) { String signerOverrideVariable = "signerOverride"; diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingAsyncClientClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingAsyncClientClass.java index 33e41d291c9..a6c2f32cf51 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingAsyncClientClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingAsyncClientClass.java @@ -42,7 +42,6 @@ import software.amazon.awssdk.codegen.model.intermediate.OperationModel; import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.PoetUtils; -import software.amazon.awssdk.codegen.utils.PaginatorUtils; import software.amazon.awssdk.core.SdkClient; import software.amazon.awssdk.utils.Validate; @@ -171,9 +170,6 @@ protected List operations() { private Stream operations(OperationModel opModel) { List methods = new ArrayList<>(); methods.add(traditionalMethod(opModel)); - if (opModel.isPaginated()) { - methods.add(paginatedTraditionalMethod(opModel)); - } return methods.stream(); } @@ -212,14 +208,6 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation return builder; } - @Override - protected MethodSpec.Builder paginatedMethodBody(MethodSpec.Builder builder, OperationModel opModel) { - String methodName = PaginatorUtils.getPaginatedMethodName(opModel.getMethodName()); - return builder.addModifiers(PUBLIC) - .addAnnotation(Override.class) - .addStatement("return delegate.$N($N)", methodName, opModel.getInput().getVariableName()); - } - @Override protected MethodSpec.Builder utilitiesOperationBody(MethodSpec.Builder builder) { return builder.addAnnotation(Override.class).addStatement("return delegate.$N()", UtilitiesMethod.METHOD_NAME); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingSyncClientClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingSyncClientClass.java index 3deaf682c53..2bed53ac28b 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingSyncClientClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/DelegatingSyncClientClass.java @@ -16,6 +16,7 @@ package software.amazon.awssdk.codegen.poet.client; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; import static javax.lang.model.element.Modifier.ABSTRACT; import static javax.lang.model.element.Modifier.FINAL; import static javax.lang.model.element.Modifier.PRIVATE; @@ -31,8 +32,10 @@ import com.squareup.javapoet.TypeSpec; import com.squareup.javapoet.TypeVariableName; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.function.Function; +import java.util.stream.Stream; import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.codegen.docs.SimpleMethodOverload; import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod; @@ -40,7 +43,6 @@ import software.amazon.awssdk.codegen.model.intermediate.OperationModel; import software.amazon.awssdk.codegen.poet.PoetExtension; import software.amazon.awssdk.codegen.poet.PoetUtils; -import software.amazon.awssdk.codegen.utils.PaginatorUtils; import software.amazon.awssdk.core.SdkClient; import software.amazon.awssdk.utils.Validate; @@ -112,6 +114,23 @@ protected void addCloseMethod(TypeSpec.Builder type) { type.addMethod(method); } + @Override + protected List operations() { + return model.getOperations().values().stream() + // TODO Sync not supported for event streaming yet. Revisit after sync/async merge + .filter(o -> !o.hasEventStreamInput()) + .filter(o -> !o.hasEventStreamOutput()) + .flatMap(this::operations) + .sorted(Comparator.comparing(m -> m.name)) + .collect(toList()); + } + + private Stream operations(OperationModel opModel) { + List methods = new ArrayList<>(); + methods.add(traditionalMethod(opModel)); + return methods.stream(); + } + @Override public ClassName className() { return className; @@ -122,6 +141,11 @@ protected MethodSpec.Builder simpleMethodModifier(MethodSpec.Builder builder) { return builder.addAnnotation(Override.class); } + protected MethodSpec traditionalMethod(OperationModel opModel) { + MethodSpec.Builder builder = operationMethodSignature(model, opModel); + return operationBody(builder, opModel).build(); + } + @Override protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, OperationModel opModel) { builder.addModifiers(PUBLIC) @@ -143,14 +167,6 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation return builder; } - @Override - protected MethodSpec.Builder paginatedMethodBody(MethodSpec.Builder builder, OperationModel opModel) { - String methodName = PaginatorUtils.getPaginatedMethodName(opModel.getMethodName()); - return builder.addModifiers(PUBLIC) - .addAnnotation(Override.class) - .addStatement("return delegate.$N($N)", methodName, opModel.getInput().getVariableName()); - } - @Override protected MethodSpec.Builder utilitiesOperationBody(MethodSpec.Builder builder) { return builder.addAnnotation(Override.class).addStatement("return delegate.$N()", UtilitiesMethod.METHOD_NAME); 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 d664792b865..310170284bf 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 @@ -21,7 +21,6 @@ import static javax.lang.model.element.Modifier.PUBLIC; import static javax.lang.model.element.Modifier.STATIC; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.addS3ArnableFieldCode; -import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.applyPaginatorUserAgentMethod; import static software.amazon.awssdk.codegen.poet.client.ClientClassUtils.applySignerOverrideMethod; import com.squareup.javapoet.ClassName; @@ -34,10 +33,10 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; import software.amazon.awssdk.awscore.client.config.AwsClientOption; -import software.amazon.awssdk.codegen.docs.SimpleMethodOverload; import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams; import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod; import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; @@ -50,7 +49,6 @@ import software.amazon.awssdk.codegen.poet.client.specs.ProtocolSpec; import software.amazon.awssdk.codegen.poet.client.specs.QueryProtocolSpec; import software.amazon.awssdk.codegen.poet.client.specs.XmlProtocolSpec; -import software.amazon.awssdk.codegen.utils.PaginatorUtils; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; @@ -114,10 +112,6 @@ protected void addFields(TypeSpec.Builder type) { @Override protected void addAdditionalMethods(TypeSpec.Builder type) { - if (model.hasPaginators()) { - type.addMethod(applyPaginatorUserAgentMethod(poetExtensions, model)); - } - if (model.containsRequestSigners()) { type.addMethod(applySignerOverrideMethod(poetExtensions, model)); } @@ -210,14 +204,17 @@ protected List operations() { return model.getOperations().values().stream() .filter(o -> !o.hasEventStreamInput()) .filter(o -> !o.hasEventStreamOutput()) - .map(this::operationMethodSpecs) - .flatMap(List::stream) + .flatMap(this::operations) .collect(Collectors.toList()); } - private List operationMethodSpecs(OperationModel opModel) { + private Stream operations(OperationModel opModel) { List methods = new ArrayList<>(); + methods.add(traditionalMethod(opModel)); + return methods.stream(); + } + private MethodSpec traditionalMethod(OperationModel opModel) { MethodSpec.Builder method = SyncClientInterface.operationMethodSignature(model, opModel) .addAnnotation(Override.class) .addCode(ClientClassUtils.callApplySignerOverrideMethod(opModel)) @@ -297,34 +294,7 @@ private List operationMethodSpecs(OperationModel opModel) { .addStatement("metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()))") .endControlFlow(); - methods.add(method.build()); - - methods.addAll(paginatedMethods(opModel)); - - return methods; - } - - @Override - protected List paginatedMethods(OperationModel opModel) { - List paginatedMethodSpecs = new ArrayList<>(); - - if (opModel.isPaginated()) { - paginatedMethodSpecs.add(SyncClientInterface.operationMethodSignature(model, - opModel, - SimpleMethodOverload.PAGINATED, - PaginatorUtils.getPaginatedMethodName( - opModel.getMethodName())) - .addAnnotation(Override.class) - .returns(poetExtensions.getResponseClassForPaginatedSyncOperation( - opModel.getOperationName())) - .addStatement("return new $T(this, applyPaginatorUserAgent($L))", - poetExtensions.getResponseClassForPaginatedSyncOperation( - opModel.getOperationName()), - opModel.getInput().getVariableName()) - .build()); - } - - return paginatedMethodSpecs; + return method.build(); } @Override diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java index 8c64f213eae..5037d5eda1f 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import java.util.stream.Stream; import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; @@ -176,16 +177,6 @@ private MethodSpec builder() { .build(); } - protected Iterable operations() { - return model.getOperations().values().stream() - // TODO Sync not supported for event streaming yet. Revisit after sync/async merge - .filter(o -> !o.hasEventStreamInput()) - .filter(o -> !o.hasEventStreamOutput()) - .map(this::operationMethodSpec) - .flatMap(List::stream) - .collect(toList()); - } - private MethodSpec serviceMetadata() { return MethodSpec.methodBuilder("serviceMetadata") .returns(ServiceMetadata.class) @@ -194,31 +185,36 @@ private MethodSpec serviceMetadata() { .build(); } - private List operationMethodSpec(OperationModel opModel) { - List methods = new ArrayList<>(); - - if (opModel.getInputShape().isSimpleMethod()) { - methods.add(simpleMethod(opModel)); - } - - methods.addAll(operation(opModel)); + protected Iterable operations() { + return model.getOperations().values().stream() + // TODO Sync not supported for event streaming yet. Revisit after sync/async merge + .filter(o -> !o.hasEventStreamInput()) + .filter(o -> !o.hasEventStreamOutput()) + .flatMap(this::operationsWithVariants) + .collect(toList()); + } - methods.addAll(streamingSimpleMethods(opModel)); + private Stream operationsWithVariants(OperationModel opModel) { + List methods = new ArrayList<>(); + methods.addAll(traditionalMethodWithConsumerVariant(opModel)); + methods.addAll(overloadedMethods(opModel)); methods.addAll(paginatedMethods(opModel)); return methods.stream() // Add Deprecated annotation if needed to all overloads - .map(m -> DeprecationUtils.checkDeprecated(opModel, m)) - .collect(toList()); + .map(m -> DeprecationUtils.checkDeprecated(opModel, m)); } - private MethodSpec simpleMethod(OperationModel opModel) { - ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(), - opModel.getInput().getVariableType()); - return operationSimpleMethodSignature(model, opModel, opModel.getMethodName()) - .addStatement("return $L($T.builder().build())", opModel.getMethodName(), requestType) - .addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.NO_ARG)) - .build(); + private List traditionalMethodWithConsumerVariant(OperationModel opModel) { + List methods = new ArrayList<>(); + + MethodSpec.Builder builder = operationMethodSignature(model, opModel); + MethodSpec method = operationBody(builder, opModel).build(); + methods.add(method); + + addConsumerMethod(methods, method, SimpleMethodOverload.NORMAL, opModel); + + return methods; } private static MethodSpec.Builder operationBaseSignature(IntermediateModel model, @@ -244,18 +240,6 @@ private static MethodSpec.Builder operationBaseSignature(IntermediateModel model return methodBuilder; } - private List operation(OperationModel opModel) { - List methods = new ArrayList<>(); - - MethodSpec.Builder builder = operationMethodSignature(model, opModel); - MethodSpec method = operationBody(builder, opModel).build(); - methods.add(method); - - addConsumerMethod(methods, method, SimpleMethodOverload.NORMAL, opModel); - - return methods; - } - protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, OperationModel opModel) { return builder.addModifiers(DEFAULT) .addStatement("throw new $T()", UnsupportedOperationException.class); @@ -328,8 +312,10 @@ private MethodSpec paginatedSimpleMethod(OperationModel opModel) { } protected MethodSpec.Builder paginatedMethodBody(MethodSpec.Builder builder, OperationModel operationModel) { - return builder.addModifiers(DEFAULT) - .addStatement("throw new $T()", UnsupportedOperationException.class); + return builder.addModifiers(DEFAULT, PUBLIC) + .addStatement("return new $T(this, $L)", + poetExtensions.getResponseClassForPaginatedSyncOperation(operationModel.getOperationName()), + operationModel.getInput().getVariableName()); } private static void streamingMethod(MethodSpec.Builder methodBuilder, OperationModel opModel, TypeName responseType) { @@ -344,14 +330,20 @@ private static void streamingMethod(MethodSpec.Builder methodBuilder, OperationM } } - private List streamingSimpleMethods(OperationModel opModel) { + /** + * @param opModel Operation to generate simple methods for. + * @return All simple method overloads for a given operation. + */ + private List overloadedMethods(OperationModel opModel) { TypeName responseType = ClassName.get(model.getMetadata().getFullModelPackageName(), opModel.getReturnType().getReturnType()); ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(), opModel.getInput().getVariableType()); List simpleMethods = new ArrayList<>(); - + if (opModel.getInputShape().isSimpleMethod()) { + simpleMethods.add(simpleMethodWithNoArgs(opModel)); + } if (opModel.hasStreamingInput() && opModel.hasStreamingOutput()) { MethodSpec simpleMethod = streamingInputOutputFileSimpleMethod(opModel, responseType, requestType); simpleMethods.add(simpleMethod); @@ -378,6 +370,15 @@ private List streamingSimpleMethods(OperationModel opModel) { return simpleMethods; } + private MethodSpec simpleMethodWithNoArgs(OperationModel opModel) { + ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(), + opModel.getInput().getVariableType()); + return operationSimpleMethodSignature(model, opModel, opModel.getMethodName()) + .addStatement("return $L($T.builder().build())", opModel.getMethodName(), requestType) + .addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.NO_ARG)) + .build(); + } + protected void addConsumerMethod(List specs, MethodSpec spec, SimpleMethodOverload overload, OperationModel opModel) { String fileConsumerBuilderJavadoc = consumerBuilderJavadoc(opModel, overload); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/common/UserAgentUtilsSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/common/UserAgentUtilsSpec.java new file mode 100644 index 00000000000..006c6592d09 --- /dev/null +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/common/UserAgentUtilsSpec.java @@ -0,0 +1,118 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.codegen.poet.common; + +import com.squareup.javapoet.ClassName; +import com.squareup.javapoet.CodeBlock; +import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.ParameterizedTypeName; +import com.squareup.javapoet.TypeSpec; +import com.squareup.javapoet.TypeVariableName; +import java.util.function.Consumer; +import javax.lang.model.element.Modifier; +import software.amazon.awssdk.annotations.SdkInternalApi; +import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; +import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; +import software.amazon.awssdk.codegen.poet.ClassSpec; +import software.amazon.awssdk.codegen.poet.PoetExtension; +import software.amazon.awssdk.codegen.poet.PoetUtils; +import software.amazon.awssdk.core.ApiName; +import software.amazon.awssdk.core.util.VersionInfo; + +public class UserAgentUtilsSpec implements ClassSpec { + + private static final String PAGINATOR_USER_AGENT = "PAGINATED"; + + protected final IntermediateModel model; + protected final PoetExtension poetExtensions; + + public UserAgentUtilsSpec(IntermediateModel model) { + this.model = model; + this.poetExtensions = new PoetExtension(model); + } + + @Override + public TypeSpec poetSpec() { + return TypeSpec.classBuilder(className()) + .addModifiers(Modifier.PUBLIC) + .addAnnotation(PoetUtils.generatedAnnotation()) + .addAnnotation(SdkInternalApi.class) + .addMethod(privateConstructor()) + .addMethod(applyUserAgentInfoMethod()) + .addMethod(applyPaginatorUserAgentMethod()) + .build(); + } + + @Override + public ClassName className() { + return poetExtensions.getUserAgentClass(); + } + + protected MethodSpec privateConstructor() { + return MethodSpec.constructorBuilder() + .addModifiers(Modifier.PRIVATE) + .build(); + } + + private MethodSpec applyUserAgentInfoMethod() { + + TypeVariableName typeVariableName = + TypeVariableName.get("T", poetExtensions.getModelClass(model.getSdkRequestBaseClassName())); + + ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName + .get(ClassName.get(Consumer.class), ClassName.get(AwsRequestOverrideConfiguration.Builder.class)); + + CodeBlock codeBlock = CodeBlock.builder() + .addStatement("$T overrideConfiguration =\n" + + " request.overrideConfiguration().map(c -> c.toBuilder()" + + ".applyMutation" + + "(userAgentApplier).build())\n" + + " .orElse((AwsRequestOverrideConfiguration.builder()" + + ".applyMutation" + + "(userAgentApplier).build()))", AwsRequestOverrideConfiguration.class) + .addStatement("return (T) request.toBuilder().overrideConfiguration" + + "(overrideConfiguration).build()") + .build(); + + return MethodSpec.methodBuilder("applyUserAgentInfo") + .addModifiers(Modifier.PUBLIC, Modifier.STATIC) + .addParameter(typeVariableName, "request") + .addParameter(parameterizedTypeName, "userAgentApplier") + .addTypeVariable(typeVariableName) + .addCode(codeBlock) + .returns(typeVariableName) + .build(); + } + + private MethodSpec applyPaginatorUserAgentMethod() { + TypeVariableName typeVariableName = + TypeVariableName.get("T", poetExtensions.getModelClass(model.getSdkRequestBaseClassName())); + + return MethodSpec.methodBuilder("applyPaginatorUserAgent") + .addModifiers(Modifier.PUBLIC, Modifier.STATIC) + .addParameter(typeVariableName, "request") + .addTypeVariable(typeVariableName) + .addStatement("return applyUserAgentInfo(request, b -> b.addApiName($T.builder()" + + ".version($T.SDK_VERSION)" + + ".name($S)" + + ".build()))", + ApiName.class, + VersionInfo.class, + PAGINATOR_USER_AGENT) + .returns(typeVariableName) + .build(); + } +} diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/AsyncResponseClassSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/AsyncResponseClassSpec.java index b6396e5581a..9ef71caa559 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/AsyncResponseClassSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/AsyncResponseClassSpec.java @@ -128,7 +128,10 @@ protected MethodSpec privateConstructor() { .addParameter(requestType(), REQUEST_MEMBER) .addParameter(boolean.class, LAST_PAGE_FIELD) .addStatement("this.$L = $L", CLIENT_MEMBER, CLIENT_MEMBER) - .addStatement("this.$L = $L", REQUEST_MEMBER, REQUEST_MEMBER) + .addStatement("this.$L = $T.applyPaginatorUserAgent($L)", + REQUEST_MEMBER, + poetExtensions.getUserAgentClass(), + REQUEST_MEMBER) .addStatement("this.$L = $L", LAST_PAGE_FIELD, LAST_PAGE_FIELD) .addStatement("this.$L = new $L()", NEXT_PAGE_FETCHER_MEMBER, nextPageFetcherClassName()) .build(); @@ -246,4 +249,5 @@ protected TypeSpec.Builder nextPageFetcherClass() { .addCode(nextPageMethodBody()) .build()); } + } diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/SyncResponseClassSpec.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/SyncResponseClassSpec.java index 5718ed479c8..847eb6e8034 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/SyncResponseClassSpec.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/SyncResponseClassSpec.java @@ -104,7 +104,10 @@ protected MethodSpec constructor() { .addParameter(getClientInterfaceName(), CLIENT_MEMBER) .addParameter(requestType(), REQUEST_MEMBER) .addStatement("this.$L = $L", CLIENT_MEMBER, CLIENT_MEMBER) - .addStatement("this.$L = $L", REQUEST_MEMBER, REQUEST_MEMBER) + .addStatement("this.$L = $T.applyPaginatorUserAgent($L)", + REQUEST_MEMBER, + poetExtensions.getUserAgentClass(), + REQUEST_MEMBER) .addStatement("this.$L = new $L()", NEXT_PAGE_FETCHER_MEMBER, nextPageFetcherClassName()) .build(); } diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/common/UserAgentClassSpecTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/common/UserAgentClassSpecTest.java new file mode 100644 index 00000000000..2119d2ea585 --- /dev/null +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/common/UserAgentClassSpecTest.java @@ -0,0 +1,34 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.codegen.poet.common; + +import static org.hamcrest.MatcherAssert.assertThat; +import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo; + +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.codegen.poet.ClassSpec; +import software.amazon.awssdk.codegen.poet.ClientTestModels; +import software.amazon.awssdk.codegen.poet.common.UserAgentUtilsSpec; + +public class UserAgentClassSpecTest { + + @Test + public void testGeneratedResponseForSyncOperations() { + ClassSpec useragentspec = new UserAgentUtilsSpec(ClientTestModels.restJsonServiceModels()); + assertThat(useragentspec, generatesTo("test-user-agent-class.java")); + } + +} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-async-client-class.java index 3b2b9e81263..783d45793ec 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-async-client-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-async-client-class.java @@ -41,8 +41,6 @@ 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.paginators.PaginatedOperationWithResultKeyPublisher; -import software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher; import software.amazon.awssdk.utils.Validate; @Generated("software.amazon.awssdk:codegen") @@ -334,84 +332,6 @@ public CompletableFuture paginatedOpera request -> delegate.paginatedOperationWithResultKey(request)); } - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 PaginatedOperationWithResultKeyPublisher paginatedOperationWithResultKeyPaginator( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - return delegate.paginatedOperationWithResultKeyPaginator(paginatedOperationWithResultKeyRequest); - } - /** * Some paginated operation without result_key in paginators.json file * @@ -439,84 +359,6 @@ public CompletableFuture paginatedOp request -> delegate.paginatedOperationWithoutResultKey(request)); } - /** - * Some paginated operation without result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithoutResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 PaginatedOperationWithoutResultKeyPublisher paginatedOperationWithoutResultKeyPaginator( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - return delegate.paginatedOperationWithoutResultKeyPaginator(paginatedOperationWithoutResultKeyRequest); - } - /** * Invokes the PutOperationWithChecksum operation asynchronously. * diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-sync-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-sync-client-class.java index f5c548ce2d7..cc067f5eab5 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-sync-client-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-abstract-sync-client-class.java @@ -1,12 +1,9 @@ package software.amazon.awssdk.services.json; -import java.nio.file.Path; import java.util.function.Function; import software.amazon.awssdk.annotations.Generated; import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.core.ResponseBytes; -import software.amazon.awssdk.core.ResponseInputStream; import software.amazon.awssdk.core.SdkClient; import software.amazon.awssdk.core.exception.SdkClientException; import software.amazon.awssdk.core.sync.RequestBody; @@ -38,8 +35,6 @@ 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.paginators.PaginatedOperationWithResultKeyIterable; -import software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable; import software.amazon.awssdk.utils.Validate; @Generated("software.amazon.awssdk:codegen") @@ -71,11 +66,8 @@ public DelegatingJsonClient(JsonClient delegate) { * @sample JsonClient.APostOperation * @see AWS * API Documentation - * - * @deprecated This API is deprecated, use something else */ @Override - @Deprecated public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, AwsServiceException, SdkClientException, JsonException { return invokeOperation(aPostOperationRequest, request -> delegate.aPostOperation(request)); @@ -203,28 +195,6 @@ public OperationWithChecksumRequiredResponse operationWithChecksumRequired( return invokeOperation(operationWithChecksumRequiredRequest, request -> delegate.operationWithChecksumRequired(request)); } - /** - * Some paginated operation with result_key in paginators.json file - * - * @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 #paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest) - * @see AWS API Documentation - */ - @Override - public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey() throws AwsServiceException, - SdkClientException, JsonException { - return paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest.builder().build()); - } - /** * Some paginated operation with result_key in paginators.json file * @@ -249,161 +219,6 @@ public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey( request -> delegate.paginatedOperationWithResultKey(request)); } - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will - * internally handle making service calls for you. - *

- *

- * When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no - * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response - * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your - * request, you will see the failures only after you start iterating through the iterable. - *

- * - *

- * The following are few ways to iterate through the response pages: - *

- * 1) Using a Stream - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.stream().forEach(....);
-     * }
-     * 
- * - * 2) Using For loop - * - *
-     * {
-     *     @code
-     *     software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client
-     *             .paginatedOperationWithResultKeyPaginator(request);
-     *     for (software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response : responses) {
-     *         // do something;
-     *     }
-     * }
-     * 
- * - * 3) Use iterator directly - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.iterator().forEachRemaining(....);
-     * }
-     * 
- *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @return A custom iterable that can be used to iterate through all the response pages. - * @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 #paginatedOperationWithResultKeyPaginator(PaginatedOperationWithResultKeyRequest) - * @see AWS API Documentation - */ - @Override - public PaginatedOperationWithResultKeyIterable paginatedOperationWithResultKeyPaginator() throws AwsServiceException, - SdkClientException, JsonException { - return paginatedOperationWithResultKeyPaginator(PaginatedOperationWithResultKeyRequest.builder().build()); - } - - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will - * internally handle making service calls for you. - *

- *

- * When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no - * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response - * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your - * request, you will see the failures only after you start iterating through the iterable. - *

- * - *

- * The following are few ways to iterate through the response pages: - *

- * 1) Using a Stream - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.stream().forEach(....);
-     * }
-     * 
- * - * 2) Using For loop - * - *
-     * {
-     *     @code
-     *     software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client
-     *             .paginatedOperationWithResultKeyPaginator(request);
-     *     for (software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response : responses) {
-     *         // do something;
-     *     }
-     * }
-     * 
- * - * 3) Use iterator directly - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.iterator().forEachRemaining(....);
-     * }
-     * 
- *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithResultKeyRequest - * @return A custom iterable that can be used to iterate through all the response pages. - * @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 PaginatedOperationWithResultKeyIterable paginatedOperationWithResultKeyPaginator( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - return delegate.paginatedOperationWithResultKeyPaginator(paginatedOperationWithResultKeyRequest); - } - /** * Some paginated operation without result_key in paginators.json file * @@ -428,84 +243,6 @@ public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResul request -> delegate.paginatedOperationWithoutResultKey(request)); } - /** - * Some paginated operation without result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will - * internally handle making service calls for you. - *

- *

- * When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no - * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response - * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your - * request, you will see the failures only after you start iterating through the iterable. - *

- * - *

- * The following are few ways to iterate through the response pages: - *

- * 1) Using a Stream - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * responses.stream().forEach(....);
-     * }
-     * 
- * - * 2) Using For loop - * - *
-     * {
-     *     @code
-     *     software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client
-     *             .paginatedOperationWithoutResultKeyPaginator(request);
-     *     for (software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse response : responses) {
-     *         // do something;
-     *     }
-     * }
-     * 
- * - * 3) Use iterator directly - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * responses.iterator().forEachRemaining(....);
-     * }
-     * 
- *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithoutResultKeyRequest - * @return A custom iterable that can be used to iterate through all the response pages. - * @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 PaginatedOperationWithoutResultKeyIterable paginatedOperationWithoutResultKeyPaginator( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - return delegate.paginatedOperationWithoutResultKeyPaginator(paginatedOperationWithoutResultKeyRequest); - } - /** * Invokes the PutOperationWithChecksum operation. * @@ -556,49 +293,6 @@ public ReturnT putOperationWithChecksum(PutOperationWithChecksumReques request -> delegate.putOperationWithChecksum(request, requestBody, responseTransformer)); } - /** - * Invokes the PutOperationWithChecksum operation. - * - * @param putOperationWithChecksumRequest - * @param sourcePath - * {@link Path} to file containing data to send to the service. File will be read entirely and may be read - * multiple times in the event of a retry. If the file does not exist or the current user does not have - * access to read it then an exception will be thrown. The service documentation for the request content is - * as follows ' - *

- * Object data. - *

- * ' - * @param destinationPath - * {@link Path} to file that response contents will be written to. The file must not exist or this method - * will throw an exception. If the file is not writable by the current user then an exception will be thrown. - * 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 #putOperationWithChecksum(PutOperationWithChecksumRequest, RequestBody) - * @see #putOperationWithChecksum(PutOperationWithChecksumRequest, ResponseTransformer) - * @see AWS API Documentation - */ - @Override - public PutOperationWithChecksumResponse putOperationWithChecksum( - PutOperationWithChecksumRequest putOperationWithChecksumRequest, Path sourcePath, Path destinationPath) - throws AwsServiceException, SdkClientException, JsonException { - return putOperationWithChecksum(putOperationWithChecksumRequest, RequestBody.fromFile(sourcePath), - ResponseTransformer.toFile(destinationPath)); - } - /** * Some operation with a streaming input * @@ -632,34 +326,6 @@ public StreamingInputOperationResponse streamingInputOperation(StreamingInputOpe return invokeOperation(streamingInputOperationRequest, request -> delegate.streamingInputOperation(request, requestBody)); } - /** - * Some operation with a streaming input - * - * @param streamingInputOperationRequest - * @param sourcePath - * {@link Path} to file containing data to send to the service. File will be read entirely and may be read - * multiple times in the event of a retry. If the file does not exist or the current user does not have - * access to read it then an exception will be thrown. 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 #streamingInputOperation(StreamingInputOperationRequest, RequestBody) - * @see AWS API Documentation - */ - @Override - public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, - Path sourcePath) throws AwsServiceException, SdkClientException, JsonException { - return streamingInputOperation(streamingInputOperationRequest, RequestBody.fromFile(sourcePath)); - } - /** * Some operation with streaming input and streaming output * @@ -703,41 +369,6 @@ public ReturnT streamingInputOutputOperation( request -> delegate.streamingInputOutputOperation(request, requestBody, responseTransformer)); } - /** - * Some operation with streaming input and streaming output - * - * @param streamingInputOutputOperationRequest - * @param sourcePath - * {@link Path} to file containing data to send to the service. File will be read entirely and may be read - * multiple times in the event of a retry. If the file does not exist or the current user does not have - * access to read it then an exception will be thrown. The service documentation for the request content is - * as follows 'This be a stream' - * @param destinationPath - * {@link Path} to file that response contents will be written to. The file must not exist or this method - * will throw an exception. If the file is not writable by the current user then an exception will be thrown. - * 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 #streamingInputOutputOperation(StreamingInputOutputOperationRequest, RequestBody) - * @see #streamingInputOutputOperation(StreamingInputOutputOperationRequest, ResponseTransformer) - * @see AWS API Documentation - */ - @Override - public StreamingInputOutputOperationResponse streamingInputOutputOperation( - StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, Path sourcePath, Path destinationPath) - throws AwsServiceException, SdkClientException, JsonException { - return streamingInputOutputOperation(streamingInputOutputOperationRequest, RequestBody.fromFile(sourcePath), - ResponseTransformer.toFile(destinationPath)); - } - /** * Some operation with a streaming output * @@ -769,89 +400,6 @@ public ReturnT streamingOutputOperation(StreamingOutputOperationReques request -> delegate.streamingOutputOperation(request, responseTransformer)); } - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @param destinationPath - * {@link Path} to file that response contents will be written to. The file must not exist or this method - * will throw an exception. If the file is not writable by the current user then an exception will be thrown. - * 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 #streamingOutputOperation(StreamingOutputOperationRequest, ResponseTransformer) - * @see AWS API Documentation - */ - @Override - public StreamingOutputOperationResponse streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest, Path destinationPath) throws AwsServiceException, - SdkClientException, JsonException { - return streamingOutputOperation(streamingOutputOperationRequest, ResponseTransformer.toFile(destinationPath)); - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @return A {@link ResponseInputStream} containing data streamed from service. Note that this is an unmanaged - * reference to the underlying HTTP connection so great care must be taken to ensure all data if fully read - * from the input stream and that it is properly closed. Failure to do so may result in sub-optimal behavior - * and exhausting connections in the connection pool. The unmarshalled response object can be obtained via - * {@link ResponseInputStream#response()}. The service documentation for the response content is as follows - * 'This be a stream'. - * @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 #getObject(streamingOutputOperation, ResponseTransformer) - * @see AWS API Documentation - */ - @Override - public ResponseInputStream streamingOutputOperation( - StreamingOutputOperationRequest streamingOutputOperationRequest) throws AwsServiceException, SdkClientException, - JsonException { - return streamingOutputOperation(streamingOutputOperationRequest, ResponseTransformer.toInputStream()); - } - - /** - * Some operation with a streaming output - * - * @param streamingOutputOperationRequest - * @return A {@link ResponseBytes} that loads the data streamed from the service into memory and exposes it in - * convenient in-memory representations like a byte buffer or string. The unmarshalled response object can - * be obtained via {@link ResponseBytes#response()}. The service documentation for the response content is - * as follows 'This be a stream'. - * @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 #getObject(streamingOutputOperation, ResponseTransformer) - * @see AWS API Documentation - */ - @Override - public ResponseBytes streamingOutputOperationAsBytes( - StreamingOutputOperationRequest streamingOutputOperationRequest) throws AwsServiceException, SdkClientException, - JsonException { - return streamingOutputOperation(streamingOutputOperationRequest, ResponseTransformer.toBytes()); - } /** * Creates an instance of {@link JsonUtilities} object with the configuration set on this client. 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 index e0ecd250b7c..b03bc8eb84d 100644 --- 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 @@ -23,7 +23,6 @@ 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.core.ApiName; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.SdkPojoBuilder; import software.amazon.awssdk.core.SdkResponse; @@ -44,7 +43,6 @@ import software.amazon.awssdk.core.protocol.VoidSdkResponse; import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.util.VersionInfo; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -91,8 +89,6 @@ 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.paginators.PaginatedOperationWithResultKeyPublisher; -import software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher; import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; import software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller; @@ -739,83 +735,6 @@ public CompletableFuture paginatedOpera } } - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 - */ - public PaginatedOperationWithResultKeyPublisher paginatedOperationWithResultKeyPaginator( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - return new PaginatedOperationWithResultKeyPublisher(this, applyPaginatorUserAgent(paginatedOperationWithResultKeyRequest)); - } - /** * Some paginated operation without result_key in paginators.json file * @@ -872,84 +791,6 @@ public CompletableFuture paginatedOp } } - /** - * Some paginated operation without result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithoutResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 - */ - public PaginatedOperationWithoutResultKeyPublisher paginatedOperationWithoutResultKeyPaginator( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - return new PaginatedOperationWithoutResultKeyPublisher(this, - applyPaginatorUserAgent(paginatedOperationWithoutResultKeyRequest)); - } - /** * Some operation with a streaming input * @@ -1219,15 +1060,6 @@ private static List resolveMetricPublishers(SdkClientConfigurat return publishers; } - private T applyPaginatorUserAgent(T request) { - Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() - .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - private T applySignerOverride(T request, Signer signer) { if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { return request; diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-async-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-async-client-class.java index e33761735db..38fab697c39 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-async-client-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-async-client-class.java @@ -5,15 +5,12 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; -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.awscore.AwsRequestOverrideConfiguration; import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler; import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.core.ApiName; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; @@ -21,7 +18,6 @@ import software.amazon.awssdk.core.client.handler.ClientExecutionParams; import software.amazon.awssdk.core.http.HttpResponseHandler; import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.util.VersionInfo; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -34,7 +30,6 @@ import software.amazon.awssdk.services.querytojsoncompatible.model.APostOperationResponse; import software.amazon.awssdk.services.querytojsoncompatible.model.InvalidInputException; import software.amazon.awssdk.services.querytojsoncompatible.model.QueryToJsonCompatibleException; -import software.amazon.awssdk.services.querytojsoncompatible.model.QueryToJsonCompatibleRequest; import software.amazon.awssdk.services.querytojsoncompatible.transform.APostOperationRequestMarshaller; import software.amazon.awssdk.utils.CompletableFutureUtils; import software.amazon.awssdk.utils.HostnameValidator; @@ -165,15 +160,6 @@ private static List resolveMetricPublishers(SdkClientConfigurat return publishers; } - private T applyPaginatorUserAgent(T request) { - Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() - .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, JsonOperationMetadata operationMetadata) { return protocolFactory.createErrorResponseHandler(operationMetadata); diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-sync-client-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-sync-client-class.java index 65123e1e4c5..42c98a423c7 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-sync-client-class.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-query-compatible-json-sync-client-class.java @@ -2,13 +2,10 @@ 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.AwsRequestOverrideConfiguration; import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler; import software.amazon.awssdk.awscore.exception.AwsServiceException; -import software.amazon.awssdk.core.ApiName; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; @@ -17,7 +14,6 @@ import software.amazon.awssdk.core.exception.SdkClientException; import software.amazon.awssdk.core.http.HttpResponseHandler; import software.amazon.awssdk.core.metrics.CoreMetric; -import software.amazon.awssdk.core.util.VersionInfo; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -30,7 +26,6 @@ import software.amazon.awssdk.services.querytojsoncompatible.model.APostOperationResponse; import software.amazon.awssdk.services.querytojsoncompatible.model.InvalidInputException; import software.amazon.awssdk.services.querytojsoncompatible.model.QueryToJsonCompatibleException; -import software.amazon.awssdk.services.querytojsoncompatible.model.QueryToJsonCompatibleRequest; import software.amazon.awssdk.services.querytojsoncompatible.transform.APostOperationRequestMarshaller; import software.amazon.awssdk.utils.HostnameValidator; import software.amazon.awssdk.utils.Logger; @@ -114,15 +109,6 @@ public APostOperationResponse aPostOperation(APostOperationRequest aPostOperatio } } - private T applyPaginatorUserAgent(T request) { - Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() - .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - @Override public final String serviceName() { return SERVICE_NAME; 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 index a232ac78b4e..4c480ea950e 100644 --- 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 @@ -25,7 +25,6 @@ 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.core.ApiName; import software.amazon.awssdk.core.CredentialType; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.SdkPojoBuilder; @@ -48,7 +47,6 @@ import software.amazon.awssdk.core.protocol.VoidSdkResponse; import software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller; import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.util.VersionInfo; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -98,8 +96,6 @@ 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.paginators.PaginatedOperationWithResultKeyPublisher; -import software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher; import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; import software.amazon.awssdk.services.json.transform.BearerAuthOperationRequestMarshaller; @@ -817,83 +813,6 @@ public CompletableFuture paginatedOpera } } - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher publisher = client.paginatedOperationWithResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 - */ - public PaginatedOperationWithResultKeyPublisher paginatedOperationWithResultKeyPaginator( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - return new PaginatedOperationWithResultKeyPublisher(this, applyPaginatorUserAgent(paginatedOperationWithResultKeyRequest)); - } - /** * Some paginated operation without result_key in paginators.json file * @@ -950,84 +869,6 @@ public CompletableFuture paginatedOp } } - /** - * Some paginated operation without result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. - * SDK will internally handle making service calls for you. - *

- *

- * When the operation is called, an instance of this class is returned. At this point, no service calls are made yet - * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the - * failures only after you start streaming the data. The subscribe method should be called as a request to start - * streaming data. For more info, see - * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe - * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the - * starting request. - *

- * - *

- * The following are few ways to use the response class: - *

- * 1) Using the subscribe helper method - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
-     * future.get();
-     * }
-     * 
- * - * 2) Using a custom subscriber - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher publisher = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * publisher.subscribe(new Subscriber() {
-     *
-     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
-     *
-     *
-     * public void onNext(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse response) { //... };
-     * });}
-     * 
- * - * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. - *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithoutResultKeyRequest - * @return A custom publisher that can be subscribed to request a stream of response pages.
- * The CompletableFuture returned by this method can be completed exceptionally with the following - * exceptions. - *
    - *
  • 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 - */ - public PaginatedOperationWithoutResultKeyPublisher paginatedOperationWithoutResultKeyPaginator( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - return new PaginatedOperationWithoutResultKeyPublisher(this, - applyPaginatorUserAgent(paginatedOperationWithoutResultKeyRequest)); - } - /** * Invokes the PutOperationWithChecksum operation asynchronously. * @@ -1396,15 +1237,6 @@ private static List resolveMetricPublishers(SdkClientConfigurat return publishers; } - private T applyPaginatorUserAgent(T request) { - Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() - .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - private T applySignerOverride(T request, Signer signer) { if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { return request; diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java index ad8845778eb..3ec88bc9ca0 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java @@ -838,7 +838,7 @@ default PaginatedOperationWithResultKeyPublisher paginatedOperationWithResultKey */ default PaginatedOperationWithResultKeyPublisher paginatedOperationWithResultKeyPaginator( PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) { - throw new UnsupportedOperationException(); + return new PaginatedOperationWithResultKeyPublisher(this, paginatedOperationWithResultKeyRequest); } /** @@ -1056,7 +1056,7 @@ default CompletableFuture paginatedO */ default PaginatedOperationWithoutResultKeyPublisher paginatedOperationWithoutResultKeyPaginator( PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) { - throw new UnsupportedOperationException(); + return new PaginatedOperationWithoutResultKeyPublisher(this, paginatedOperationWithoutResultKeyRequest); } /** 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 index 544fe2e977a..54019ade037 100644 --- 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 @@ -10,7 +10,6 @@ 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.core.ApiName; import software.amazon.awssdk.core.CredentialType; import software.amazon.awssdk.core.RequestOverrideConfiguration; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; @@ -27,7 +26,6 @@ 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.core.util.VersionInfo; import software.amazon.awssdk.metrics.MetricCollector; import software.amazon.awssdk.metrics.MetricPublisher; import software.amazon.awssdk.metrics.NoOpMetricCollector; @@ -63,8 +61,6 @@ 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.paginators.PaginatedOperationWithResultKeyIterable; -import software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable; import software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller; import software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller; import software.amazon.awssdk.services.json.transform.BearerAuthOperationRequestMarshaller; @@ -459,84 +455,6 @@ public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey( } } - /** - * Some paginated operation with result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will - * internally handle making service calls for you. - *

- *

- * When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no - * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response - * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your - * request, you will see the failures only after you start iterating through the iterable. - *

- * - *

- * The following are few ways to iterate through the response pages: - *

- * 1) Using a Stream - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.stream().forEach(....);
-     * }
-     * 
- * - * 2) Using For loop - * - *
-     * {
-     *     @code
-     *     software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client
-     *             .paginatedOperationWithResultKeyPaginator(request);
-     *     for (software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse response : responses) {
-     *         // do something;
-     *     }
-     * }
-     * 
- * - * 3) Use iterator directly - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable responses = client.paginatedOperationWithResultKeyPaginator(request);
-     * responses.iterator().forEachRemaining(....);
-     * }
-     * 
- *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithResultKeyRequest - * @return A custom iterable that can be used to iterate through all the response pages. - * @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 PaginatedOperationWithResultKeyIterable paginatedOperationWithResultKeyPaginator( - PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - return new PaginatedOperationWithResultKeyIterable(this, applyPaginatorUserAgent(paginatedOperationWithResultKeyRequest)); - } - /** * Some paginated operation without result_key in paginators.json file * @@ -584,85 +502,6 @@ public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResul } } - /** - * Some paginated operation without result_key in paginators.json file
- *

- * This is a variant of - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will - * internally handle making service calls for you. - *

- *

- * When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no - * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response - * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your - * request, you will see the failures only after you start iterating through the iterable. - *

- * - *

- * The following are few ways to iterate through the response pages: - *

- * 1) Using a Stream - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * responses.stream().forEach(....);
-     * }
-     * 
- * - * 2) Using For loop - * - *
-     * {
-     *     @code
-     *     software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client
-     *             .paginatedOperationWithoutResultKeyPaginator(request);
-     *     for (software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse response : responses) {
-     *         // do something;
-     *     }
-     * }
-     * 
- * - * 3) Use iterator directly - * - *
-     * {@code
-     * software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable responses = client.paginatedOperationWithoutResultKeyPaginator(request);
-     * responses.iterator().forEachRemaining(....);
-     * }
-     * 
- *

- * Please notice that the configuration of MaxResults won't limit the number of results you get with the - * paginator. It only limits the number of results in each page. - *

- *

- * Note: If you prefer to have control on service calls, use the - * {@link #paginatedOperationWithoutResultKey(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest)} - * operation. - *

- * - * @param paginatedOperationWithoutResultKeyRequest - * @return A custom iterable that can be used to iterate through all the response pages. - * @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 PaginatedOperationWithoutResultKeyIterable paginatedOperationWithoutResultKeyPaginator( - PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) throws AwsServiceException, - SdkClientException, JsonException { - return new PaginatedOperationWithoutResultKeyIterable(this, - applyPaginatorUserAgent(paginatedOperationWithoutResultKeyRequest)); - } - /** * Invokes the PutOperationWithChecksum operation. * @@ -949,15 +788,6 @@ public JsonUtilities utilities() { return JsonUtilities.create(param1, param2, param3); } - private T applyPaginatorUserAgent(T request) { - Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() - .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); - AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() - .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) - .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); - return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); - } - private T applySignerOverride(T request, Signer signer) { if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) { return request; diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java index bf5cba1dce1..47d774dcfad 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java @@ -391,27 +391,6 @@ default OperationWithChecksumRequiredResponse operationWithChecksumRequired( .applyMutation(operationWithChecksumRequiredRequest).build()); } - /** - * Some paginated operation with result_key in paginators.json file - * - * @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 #paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest) - * @see AWS API Documentation - */ - default PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey() throws AwsServiceException, - SdkClientException, JsonException { - return paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest.builder().build()); - } - /** * Some paginated operation with result_key in paginators.json file * @@ -463,6 +442,27 @@ default PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey( .applyMutation(paginatedOperationWithResultKeyRequest).build()); } + /** + * Some paginated operation with result_key in paginators.json file + * + * @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 #paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest) + * @see AWS API Documentation + */ + default PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey() throws AwsServiceException, + SdkClientException, JsonException { + return paginatedOperationWithResultKey(PaginatedOperationWithResultKeyRequest.builder().build()); + } + /** * Some paginated operation with result_key in paginators.json file
*

@@ -613,7 +613,7 @@ default PaginatedOperationWithResultKeyIterable paginatedOperationWithResultKeyP default PaginatedOperationWithResultKeyIterable paginatedOperationWithResultKeyPaginator( PaginatedOperationWithResultKeyRequest paginatedOperationWithResultKeyRequest) throws AwsServiceException, SdkClientException, JsonException { - throw new UnsupportedOperationException(); + return new PaginatedOperationWithResultKeyIterable(this, paginatedOperationWithResultKeyRequest); } /** @@ -825,7 +825,7 @@ default PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResu default PaginatedOperationWithoutResultKeyIterable paginatedOperationWithoutResultKeyPaginator( PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) throws AwsServiceException, SdkClientException, JsonException { - throw new UnsupportedOperationException(); + return new PaginatedOperationWithoutResultKeyIterable(this, paginatedOperationWithoutResultKeyRequest); } /** diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/common/test-user-agent-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/common/test-user-agent-class.java new file mode 100644 index 00000000000..ab33e804e0f --- /dev/null +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/common/test-user-agent-class.java @@ -0,0 +1,27 @@ +package software.amazon.awssdk.services.json.internal; + +import java.util.function.Consumer; +import software.amazon.awssdk.annotations.Generated; +import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; +import software.amazon.awssdk.core.ApiName; +import software.amazon.awssdk.core.util.VersionInfo; +import software.amazon.awssdk.services.json.model.JsonRequest; + +@Generated("software.amazon.awssdk:codegen") +public class UserAgentUtils { + private UserAgentUtils() { + } + + public static T applyUserAgentInfo(T request, + Consumer userAgentApplier) { + AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() + .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) + .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); + return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); + } + + public static T applyPaginatorUserAgent(T request) { + return applyUserAgentInfo(request, + b -> b.addApiName(ApiName.builder().version(VersionInfo.SDK_VERSION).name("PAGINATED").build())); + } +} \ No newline at end of file diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/paginators/PaginatedOperationWithResultKeyIterable.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/paginators/PaginatedOperationWithResultKeyIterable.java index fcf33f2186d..23c08dd0a57 100644 --- a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/paginators/PaginatedOperationWithResultKeyIterable.java +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/paginators/PaginatedOperationWithResultKeyIterable.java @@ -10,6 +10,7 @@ import software.amazon.awssdk.core.pagination.sync.SyncPageFetcher; import software.amazon.awssdk.core.util.PaginatorUtils; import software.amazon.awssdk.services.jsonprotocoltests.JsonProtocolTestsClient; +import software.amazon.awssdk.services.jsonprotocoltests.internal.UserAgentUtils; import software.amazon.awssdk.services.jsonprotocoltests.model.PaginatedOperationWithResultKeyRequest; import software.amazon.awssdk.services.jsonprotocoltests.model.PaginatedOperationWithResultKeyResponse; import software.amazon.awssdk.services.jsonprotocoltests.model.SimpleStruct; @@ -83,7 +84,7 @@ public class PaginatedOperationWithResultKeyIterable implements SdkIterable future = publisher.subscribe(PaginatedOperationWithResultKeyResponse::items); future.get(); - assertThat(mockAsyncHttpClient.getLastRequest().headers().get(INTERCEPTED_HEADER)).isNull(); + validateIsDecorated(); } @Test @@ -103,7 +102,7 @@ public void paginatedOp_ConsumerRequest_publisherResponse_delegatingClient_DoesN decoratingClient.paginatedOperationWithResultKeyPaginator(r -> r.nextToken("token").build()); CompletableFuture future = publisher.subscribe(PaginatedOperationWithResultKeyResponse::items); future.get(); - assertThat(mockAsyncHttpClient.getLastRequest().headers().get(INTERCEPTED_HEADER)).isNull(); + validateIsDecorated(); } private void validateIsDecorated() { diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/delegatingclients/DelegatingSyncClientTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/delegatingclients/DelegatingSyncClientTest.java index f7aee6bef08..49c2cfca53b 100644 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/delegatingclients/DelegatingSyncClientTest.java +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/delegatingclients/DelegatingSyncClientTest.java @@ -89,23 +89,22 @@ public void paginatedOp_ConsumerRequest_standardFutureResponse_delegatingClient_ validateIsDecorated(); } - //TODO: handle paginated calls - the paginated publisher calls should also be decorated @Test - public void paginatedOp_Request_publisherResponse_delegatingClient_DoesNotIntercept() throws Exception { + public void paginatedOp_Request_publisherResponse_delegatingClient_SuccessfullyIntercepts() { PaginatedOperationWithResultKeyIterable iterable = decoratingClient.paginatedOperationWithResultKeyPaginator(PaginatedOperationWithResultKeyRequest.builder() .nextToken("token") .build()); iterable.forEach(PaginatedOperationWithResultKeyResponse::items); - assertThat(mockSyncHttpClient.getLastRequest().headers().get(INTERCEPTED_HEADER)).isNull(); + validateIsDecorated(); } @Test - public void paginatedOp_ConsumerRequest_publisherResponse_delegatingClient_DoesNotIntercept() throws Exception { + public void paginatedOp_ConsumerRequest_publisherResponse_delegatingClient_SuccessfullyIntercepts() { PaginatedOperationWithResultKeyIterable iterable = decoratingClient.paginatedOperationWithResultKeyPaginator(r -> r.nextToken("token").build()); iterable.forEach(PaginatedOperationWithResultKeyResponse::items); - assertThat(mockSyncHttpClient.getLastRequest().headers().get(INTERCEPTED_HEADER)).isNull(); + validateIsDecorated(); } private void validateIsDecorated() {