-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codegen customizations to skip ALPN for existing H2 services
- Loading branch information
Showing
14 changed files
with
497 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
...ces/software/amazon/awssdk/codegen/poet/builder/test-h2-service-client-builder-class.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package software.amazon.awssdk.services.h2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import software.amazon.awssdk.annotations.Generated; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.auth.signer.Aws4Signer; | ||
import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; | ||
import software.amazon.awssdk.awscore.client.config.AwsClientOption; | ||
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider; | ||
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; | ||
import software.amazon.awssdk.core.SdkPlugin; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; | ||
import software.amazon.awssdk.core.client.config.SdkClientConfiguration; | ||
import software.amazon.awssdk.core.client.config.SdkClientOption; | ||
import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; | ||
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; | ||
import software.amazon.awssdk.core.retry.RetryMode; | ||
import software.amazon.awssdk.core.signer.Signer; | ||
import software.amazon.awssdk.http.Protocol; | ||
import software.amazon.awssdk.http.ProtocolNegotiation; | ||
import software.amazon.awssdk.http.SdkHttpConfigurationOption; | ||
import software.amazon.awssdk.identity.spi.IdentityProvider; | ||
import software.amazon.awssdk.identity.spi.IdentityProviders; | ||
import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; | ||
import software.amazon.awssdk.retries.api.RetryStrategy; | ||
import software.amazon.awssdk.services.h2.endpoints.H2EndpointProvider; | ||
import software.amazon.awssdk.services.h2.endpoints.internal.H2RequestSetEndpointInterceptor; | ||
import software.amazon.awssdk.services.h2.endpoints.internal.H2ResolveEndpointInterceptor; | ||
import software.amazon.awssdk.services.h2.internal.H2ServiceClientConfigurationBuilder; | ||
import software.amazon.awssdk.utils.AttributeMap; | ||
import software.amazon.awssdk.utils.CollectionUtils; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
/** | ||
* Internal base class for {@link DefaultH2ClientBuilder} and {@link DefaultH2AsyncClientBuilder}. | ||
*/ | ||
@Generated("software.amazon.awssdk:codegen") | ||
@SdkInternalApi | ||
abstract class DefaultH2BaseClientBuilder<B extends H2BaseClientBuilder<B, C>, C> extends AwsDefaultClientBuilder<B, C> { | ||
@Override | ||
protected final String serviceEndpointPrefix() { | ||
return "h2-service"; | ||
} | ||
|
||
@Override | ||
protected final String serviceName() { | ||
return "H2"; | ||
} | ||
|
||
@Override | ||
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { | ||
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) | ||
.option(SdkAdvancedClientOption.SIGNER, defaultSigner()) | ||
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)); | ||
} | ||
|
||
@Override | ||
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { | ||
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>(); | ||
endpointInterceptors.add(new H2ResolveEndpointInterceptor()); | ||
endpointInterceptors.add(new H2RequestSetEndpointInterceptor()); | ||
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); | ||
List<ExecutionInterceptor> interceptors = interceptorFactory | ||
.getInterceptors("software/amazon/awssdk/services/h2/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)); | ||
SdkClientConfiguration.Builder builder = config.toBuilder(); | ||
builder.lazyOption(SdkClientOption.IDENTITY_PROVIDERS, c -> { | ||
IdentityProviders.Builder result = IdentityProviders.builder(); | ||
IdentityProvider<?> credentialsIdentityProvider = c.get(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); | ||
if (credentialsIdentityProvider != null) { | ||
result.putIdentityProvider(credentialsIdentityProvider); | ||
} | ||
return result.build(); | ||
}); | ||
builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); | ||
builder.lazyOptionIfAbsent( | ||
SdkClientOption.CLIENT_ENDPOINT_PROVIDER, | ||
c -> AwsClientEndpointProvider | ||
.builder() | ||
.serviceEndpointOverrideEnvironmentVariable("AWS_ENDPOINT_URL_H2_SERVICE") | ||
.serviceEndpointOverrideSystemProperty("aws.endpointUrlH2") | ||
.serviceProfileProperty("h2_service") | ||
.serviceEndpointPrefix(serviceEndpointPrefix()) | ||
.defaultProtocol("https") | ||
.region(c.get(AwsClientOption.AWS_REGION)) | ||
.profileFile(c.get(SdkClientOption.PROFILE_FILE_SUPPLIER)) | ||
.profileName(c.get(SdkClientOption.PROFILE_NAME)) | ||
.putAdvancedOption(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, | ||
c.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)) | ||
.dualstackEnabled(c.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)) | ||
.fipsEnabled(c.get(AwsClientOption.FIPS_ENDPOINT_ENABLED)).build()); | ||
return builder.build(); | ||
} | ||
|
||
private Signer defaultSigner() { | ||
return Aws4Signer.create(); | ||
} | ||
|
||
@Override | ||
protected final String signingName() { | ||
return "h2-service"; | ||
} | ||
|
||
private H2EndpointProvider defaultEndpointProvider() { | ||
return H2EndpointProvider.defaultProvider(); | ||
} | ||
|
||
@Override | ||
protected final AttributeMap serviceHttpConfig() { | ||
AttributeMap result = AttributeMap.empty(); | ||
return result.merge(AttributeMap.builder().put(SdkHttpConfigurationOption.PROTOCOL, Protocol.HTTP2) | ||
.put(SdkHttpConfigurationOption.PROTOCOL_NEGOTIATION, ProtocolNegotiation.ALPN).build()); | ||
} | ||
|
||
@Override | ||
protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) { | ||
List<SdkPlugin> internalPlugins = internalPlugins(config); | ||
List<SdkPlugin> externalPlugins = plugins(); | ||
if (internalPlugins.isEmpty() && externalPlugins.isEmpty()) { | ||
return config; | ||
} | ||
List<SdkPlugin> plugins = CollectionUtils.mergeLists(internalPlugins, externalPlugins); | ||
SdkClientConfiguration.Builder configuration = config.toBuilder(); | ||
H2ServiceClientConfigurationBuilder serviceConfigBuilder = new H2ServiceClientConfigurationBuilder(configuration); | ||
for (SdkPlugin plugin : plugins) { | ||
plugin.configureClient(serviceConfigBuilder); | ||
} | ||
updateRetryStrategyClientConfiguration(configuration); | ||
return configuration.build(); | ||
} | ||
|
||
private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) { | ||
ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder(); | ||
RetryMode retryMode = builder.retryMode(); | ||
if (retryMode != null) { | ||
configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode)); | ||
} else { | ||
Consumer<RetryStrategy.Builder<?, ?>> configurator = builder.retryStrategyConfigurator(); | ||
if (configurator != null) { | ||
RetryStrategy.Builder<?, ?> defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder(); | ||
configurator.accept(defaultBuilder); | ||
configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build()); | ||
} else { | ||
RetryStrategy retryStrategy = builder.retryStrategy(); | ||
if (retryStrategy != null) { | ||
configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy); | ||
} | ||
} | ||
} | ||
configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null); | ||
configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null); | ||
configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null); | ||
} | ||
|
||
private List<SdkPlugin> internalPlugins(SdkClientConfiguration config) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
protected static void validateClientOptions(SdkClientConfiguration c) { | ||
Validate.notNull(c.option(SdkAdvancedClientOption.SIGNER), | ||
"The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder."); | ||
} | ||
} |
Oops, something went wrong.