/
test-client-builder-class.java
154 lines (142 loc) · 8.81 KB
/
test-client-builder-class.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package software.amazon.awssdk.services.json;
import java.util.ArrayList;
import java.util.List;
import software.amazon.MyServiceHttpConfig;
import software.amazon.MyServiceRetryPolicy;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider;
import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner;
import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.services.json.endpoints.JsonClientContextParams;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.awssdk.utils.Validate;
/**
* Internal base class for {@link DefaultJsonClientBuilder} and {@link DefaultJsonAsyncClientBuilder}.
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
abstract class DefaultJsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends AwsDefaultClientBuilder<B, C> {
@Override
protected final String serviceEndpointPrefix() {
return "json-service-endpoint";
}
@Override
protected final String serviceName() {
return "Json";
}
@Override
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
.option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build())
.option(AwsClientOption.TOKEN_PROVIDER, defaultTokenProvider())
.option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()));
}
@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
List<ExecutionInterceptor> additionalInterceptors = new ArrayList<>();
interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors);
interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors);
interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS));
ServiceConfiguration.Builder serviceConfigBuilder = ((ServiceConfiguration) config
.option(SdkClientOption.SERVICE_CONFIGURATION)).toBuilder();
serviceConfigBuilder.profileFile(serviceConfigBuilder.profileFile() != null ? serviceConfigBuilder.profileFile() : config
.option(SdkClientOption.PROFILE_FILE));
serviceConfigBuilder.profileName(serviceConfigBuilder.profileName() != null ? serviceConfigBuilder.profileName() : config
.option(SdkClientOption.PROFILE_NAME));
if (serviceConfigBuilder.dualstackEnabled() != null) {
Validate.validState(
config.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED) == null,
"Dualstack has been configured on both ServiceConfiguration and the client/global level. Please limit dualstack configuration to one location.");
} else {
serviceConfigBuilder.dualstackEnabled(config.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED));
}
if (serviceConfigBuilder.fipsModeEnabled() != null) {
Validate.validState(
config.option(AwsClientOption.FIPS_ENDPOINT_ENABLED) == null,
"Fips has been configured on both ServiceConfiguration and the client/global level. Please limit fips configuration to one location.");
} else {
serviceConfigBuilder.fipsModeEnabled(config.option(AwsClientOption.FIPS_ENDPOINT_ENABLED));
}
if (serviceConfigBuilder.useArnRegionEnabled() != null) {
Validate.validState(
clientContextParams.get(JsonClientContextParams.USE_ARN_REGION) == null,
"UseArnRegion has been configured on both ServiceConfiguration and the client/global level. Please limit UseArnRegion configuration to one location.");
} else {
serviceConfigBuilder.useArnRegionEnabled(clientContextParams.get(JsonClientContextParams.USE_ARN_REGION));
}
if (serviceConfigBuilder.multiRegionEnabled() != null) {
Validate.validState(
clientContextParams.get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS) == null,
"DisableMultiRegionAccessPoints has been configured on both ServiceConfiguration and the client/global level. Please limit DisableMultiRegionAccessPoints configuration to one location.");
} else if (clientContextParams.get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS) != null) {
serviceConfigBuilder.multiRegionEnabled(!clientContextParams
.get(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS));
}
if (serviceConfigBuilder.pathStyleAccessEnabled() != null) {
Validate.validState(
clientContextParams.get(JsonClientContextParams.FORCE_PATH_STYLE) == null,
"ForcePathStyle has been configured on both ServiceConfiguration and the client/global level. Please limit ForcePathStyle configuration to one location.");
} else {
serviceConfigBuilder.pathStyleAccessEnabled(clientContextParams.get(JsonClientContextParams.FORCE_PATH_STYLE));
}
if (serviceConfigBuilder.accelerateModeEnabled() != null) {
Validate.validState(
clientContextParams.get(JsonClientContextParams.ACCELERATE) == null,
"Accelerate has been configured on both ServiceConfiguration and the client/global level. Please limit Accelerate configuration to one location.");
} else {
serviceConfigBuilder.accelerateModeEnabled(clientContextParams.get(JsonClientContextParams.ACCELERATE));
}
ServiceConfiguration finalServiceConfig = serviceConfigBuilder.build();
clientContextParams.put(JsonClientContextParams.USE_ARN_REGION, finalServiceConfig.useArnRegionEnabled());
clientContextParams.put(JsonClientContextParams.DISABLE_MULTI_REGION_ACCESS_POINTS,
!finalServiceConfig.multiRegionEnabled());
clientContextParams.put(JsonClientContextParams.FORCE_PATH_STYLE, finalServiceConfig.pathStyleAccessEnabled());
clientContextParams.put(JsonClientContextParams.ACCELERATE, finalServiceConfig.accelerateModeEnabled());
return config.toBuilder().option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED, finalServiceConfig.dualstackEnabled())
.option(AwsClientOption.FIPS_ENDPOINT_ENABLED, finalServiceConfig.fipsModeEnabled())
.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors)
.option(SdkClientOption.RETRY_POLICY, MyServiceRetryPolicy.resolveRetryPolicy(config))
.option(SdkClientOption.SERVICE_CONFIGURATION, finalServiceConfig).build();
}
private Signer defaultSigner() {
return Aws4Signer.create();
}
@Override
protected final String signingName() {
return "json-service";
}
public B serviceConfiguration(ServiceConfiguration serviceConfiguration) {
clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION, serviceConfiguration);
return thisBuilder();
}
public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) {
serviceConfiguration(serviceConfiguration);
}
private SdkTokenProvider defaultTokenProvider() {
return DefaultAwsTokenProvider.create();
}
private Signer defaultTokenSigner() {
return BearerTokenSigner.create();
}
@Override
protected final AttributeMap serviceHttpConfig() {
AttributeMap result = MyServiceHttpConfig.defaultHttpConfig();
return result;
}
}