|
18 | 18 | import com.squareup.javapoet.ClassName;
|
19 | 19 | import com.squareup.javapoet.MethodSpec;
|
20 | 20 | import com.squareup.javapoet.ParameterizedTypeName;
|
21 |
| -import com.squareup.javapoet.TypeName; |
22 | 21 | import com.squareup.javapoet.TypeSpec;
|
23 | 22 | import java.net.URI;
|
24 |
| -import java.util.ArrayList; |
25 |
| -import java.util.Collections; |
26 |
| -import java.util.List; |
27 | 23 | import javax.lang.model.element.Modifier;
|
28 | 24 | import software.amazon.awssdk.annotations.SdkInternalApi;
|
29 | 25 | import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
|
|
36 | 32 | import software.amazon.awssdk.codegen.utils.AuthUtils;
|
37 | 33 | import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
|
38 | 34 | import software.amazon.awssdk.core.client.config.SdkClientOption;
|
39 |
| -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; |
40 |
| -import software.amazon.awssdk.protocols.query.interceptor.QueryParametersToBodyInterceptor; |
41 |
| -import software.amazon.awssdk.utils.CollectionUtils; |
42 | 35 |
|
43 | 36 | public class AsyncClientBuilderClass implements ClassSpec {
|
44 | 37 | private final IntermediateModel model;
|
@@ -126,53 +119,26 @@ private MethodSpec endpointProviderMethod() {
|
126 | 119 | }
|
127 | 120 |
|
128 | 121 | private MethodSpec buildClientMethod() {
|
129 |
| - MethodSpec.Builder b = MethodSpec.methodBuilder("buildClient") |
130 |
| - .addAnnotation(Override.class) |
131 |
| - .addModifiers(Modifier.PROTECTED, Modifier.FINAL) |
132 |
| - .returns(clientInterfaceName) |
133 |
| - .addStatement("$T clientConfiguration = super.asyncClientConfiguration()", |
134 |
| - SdkClientConfiguration.class); |
135 |
| - |
136 |
| - addQueryProtocolInterceptors(b); |
137 |
| - |
138 |
| - return b.addStatement("this.validateClientOptions(clientConfiguration)") |
139 |
| - .addStatement("$T endpointOverride = null", URI.class) |
140 |
| - .addCode("if (clientConfiguration.option($T.ENDPOINT_OVERRIDDEN) != null" |
141 |
| - + "&& $T.TRUE.equals(clientConfiguration.option($T.ENDPOINT_OVERRIDDEN))) {" |
142 |
| - + "endpointOverride = clientConfiguration.option($T.ENDPOINT);" |
143 |
| - + "}", |
144 |
| - SdkClientOption.class, Boolean.class, SdkClientOption.class, SdkClientOption.class) |
145 |
| - .addStatement("$T serviceClientConfiguration = $T.builder()" |
146 |
| - + ".overrideConfiguration(overrideConfiguration())" |
147 |
| - + ".region(clientConfiguration.option($T.AWS_REGION))" |
148 |
| - + ".endpointOverride(endpointOverride)" |
149 |
| - + ".build()", |
150 |
| - serviceConfigClassName, serviceConfigClassName, AwsClientOption.class) |
151 |
| - .addStatement("return new $T(serviceClientConfiguration, clientConfiguration)", clientClassName) |
152 |
| - .build(); |
153 |
| - } |
154 |
| - |
155 |
| - private MethodSpec.Builder addQueryProtocolInterceptors(MethodSpec.Builder b) { |
156 |
| - if (!model.getMetadata().isQueryProtocol()) { |
157 |
| - return b; |
158 |
| - } |
159 |
| - |
160 |
| - TypeName listType = ParameterizedTypeName.get(List.class, ExecutionInterceptor.class); |
161 |
| - |
162 |
| - b.addStatement("$T interceptors = clientConfiguration.option($T.EXECUTION_INTERCEPTORS)", |
163 |
| - listType, SdkClientOption.class) |
164 |
| - .addStatement("$T queryParamsToBodyInterceptor = $T.singletonList(new $T())", |
165 |
| - listType, Collections.class, QueryParametersToBodyInterceptor.class) |
166 |
| - .addStatement("$T customizationInterceptors = new $T<>()", listType, ArrayList.class); |
167 |
| - |
168 |
| - List<String> customInterceptors = model.getCustomizationConfig().getInterceptors(); |
169 |
| - customInterceptors.forEach(i -> b.addStatement("customizationInterceptors.add(new $T())", ClassName.bestGuess(i))); |
170 |
| - |
171 |
| - b.addStatement("interceptors = $T.mergeLists(queryParamsToBodyInterceptor, interceptors)", CollectionUtils.class) |
172 |
| - .addStatement("interceptors = $T.mergeLists(customizationInterceptors, interceptors)", CollectionUtils.class); |
173 |
| - |
174 |
| - return b.addStatement("clientConfiguration = clientConfiguration.toBuilder().option($T.EXECUTION_INTERCEPTORS, " |
175 |
| - + "interceptors).build()", SdkClientOption.class); |
| 122 | + return MethodSpec.methodBuilder("buildClient") |
| 123 | + .addAnnotation(Override.class) |
| 124 | + .addModifiers(Modifier.PROTECTED, Modifier.FINAL) |
| 125 | + .returns(clientInterfaceName) |
| 126 | + .addStatement("$T clientConfiguration = super.asyncClientConfiguration()", SdkClientConfiguration.class) |
| 127 | + .addStatement("this.validateClientOptions(clientConfiguration)") |
| 128 | + .addStatement("$T endpointOverride = null", URI.class) |
| 129 | + .addCode("if (clientConfiguration.option($T.ENDPOINT_OVERRIDDEN) != null" |
| 130 | + + "&& $T.TRUE.equals(clientConfiguration.option($T.ENDPOINT_OVERRIDDEN))) {" |
| 131 | + + "endpointOverride = clientConfiguration.option($T.ENDPOINT);" |
| 132 | + + "}", |
| 133 | + SdkClientOption.class, Boolean.class, SdkClientOption.class, SdkClientOption.class) |
| 134 | + .addStatement("$T serviceClientConfiguration = $T.builder()" |
| 135 | + + ".overrideConfiguration(overrideConfiguration())" |
| 136 | + + ".region(clientConfiguration.option($T.AWS_REGION))" |
| 137 | + + ".endpointOverride(endpointOverride)" |
| 138 | + + ".build()", |
| 139 | + serviceConfigClassName, serviceConfigClassName, AwsClientOption.class) |
| 140 | + .addStatement("return new $T(serviceClientConfiguration, clientConfiguration)", clientClassName) |
| 141 | + .build(); |
176 | 142 | }
|
177 | 143 |
|
178 | 144 | private MethodSpec bearerTokenProviderMethod() {
|
|
0 commit comments