Skip to content

Commit 601e4f2

Browse files
authored
Code generate execution interceptors into clients instead of relying on runtime discovery. (#3550)
This does not disable runtime discovery. It just stops using it for internal SDK purposes. This was a common source of errors when customers would shade the SDK.
1 parent a0c8a0a commit 601e4f2

File tree

43 files changed

+98
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+98
-389
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Stop using execution.interceptors reflective loading for internal interceptors. This will reduce the chance of shading errors."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ public class CustomizationConfig {
218218
*/
219219
private boolean useRuleBasedEndpoints = false;
220220

221+
private List<String> interceptors = new ArrayList<>();
222+
221223
private CustomizationConfig() {
222224
}
223225

@@ -562,4 +564,12 @@ public boolean useRuleBasedEndpoints() {
562564
public void setUseRuleBasedEndpoints(boolean useRuleBasedEndpoints) {
563565
this.useRuleBasedEndpoints = useRuleBasedEndpoints;
564566
}
567+
568+
public List<String> getInterceptors() {
569+
return interceptors;
570+
}
571+
572+
public void setInterceptors(List<String> interceptors) {
573+
this.interceptors = interceptors;
574+
}
565575
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,23 @@ private MethodSpec finalizeServiceConfigurationMethod() {
257257
ParameterizedTypeName.get(List.class, ExecutionInterceptor.class),
258258
ArrayList.class);
259259

260+
List<ClassName> builtInInterceptors = new ArrayList<>();
261+
260262
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
261-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.resolverInterceptorName());
262-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.authSchemesInterceptorName());
263-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.requestModifierInterceptorName());
263+
builtInInterceptors.add(endpointRulesSpecUtils.resolverInterceptorName());
264+
builtInInterceptors.add(endpointRulesSpecUtils.authSchemesInterceptorName());
265+
builtInInterceptors.add(endpointRulesSpecUtils.requestModifierInterceptorName());
266+
}
267+
268+
for (String interceptor : model.getCustomizationConfig().getInterceptors()) {
269+
builtInInterceptors.add(ClassName.bestGuess(interceptor));
264270
}
265271

272+
for (ClassName interceptor : builtInInterceptors) {
273+
builder.addStatement("endpointInterceptors.add(new $T())", interceptor);
274+
}
275+
276+
266277
builder.addCode("$1T interceptorFactory = new $1T();\n", ClasspathInterceptorChainFactory.class)
267278
.addCode("$T<$T> interceptors = interceptorFactory.getInterceptors($S);\n",
268279
List.class, ExecutionInterceptor.class, requestHandlerPath);

services/apigateway/src/main/resources/META-INF/native-image/software.amazon.awssdk/apigateway/reflect-config.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

services/apigateway/src/main/resources/codegen-resources/customization.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"getVpcLinks",
2121
"createApiKey",
2222
"generateClientCertificate"
23+
],
24+
"interceptors": [
25+
"software.amazon.awssdk.services.apigateway.internal.AcceptJsonInterceptor"
2326
]
2427
}

services/apigateway/src/main/resources/software/amazon/awssdk/services/apigateway/execution.interceptors

Lines changed: 0 additions & 1 deletion
This file was deleted.

services/cloudsearchdomain/src/main/resources/META-INF/native-image/software.amazon.awssdk/cloudsearchdomain/reflect-config.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

services/cloudsearchdomain/src/main/resources/codegen-resources/customization.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
}
2222
]
2323
}
24-
}
24+
},
25+
"interceptors": [
26+
"software.amazon.awssdk.services.cloudsearchdomain.internal.SwitchToPostInterceptor"
27+
]
2528
}

services/cloudsearchdomain/src/main/resources/software/amazon/awssdk/services/cloudsearchdomain/execution.interceptors

Lines changed: 0 additions & 1 deletion
This file was deleted.

services/docdb/src/main/resources/META-INF/native-image/software.amazon.awssdk/docdb/reflect-config.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)