From 04bab61bd77ff76552c5f3f792f3a157aaefeceb Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 15 Feb 2021 18:59:36 +0100 Subject: [PATCH] Amazon Services - Fix class loading issues by separating recorders Fixes #15014 --- .../AbstractAmazonServiceProcessor.java | 116 +++++--- .../AmazonClientAsyncTransportBuildItem.java | 34 +++ .../AmazonClientSyncTransportBuildItem.java | 34 +++ .../AmazonClientTransportsBuildItem.java | 51 ---- .../common/deployment/AmazonHttpClients.java | 46 +++ .../AmazonServicesClientsProcessor.java | 17 +- ...AbstractAmazonClientTransportRecorder.java | 115 ++++++++ .../AmazonClientApacheTransportRecorder.java | 59 ++++ .../AmazonClientNettyTransportRecorder.java | 108 ++++++++ .../AmazonClientTransportRecorder.java | 262 ------------------ ...nClientUrlConnectionTransportRecorder.java | 25 ++ .../deployment/DynamodbProcessor.java | 49 +++- .../amazon/iam/deployment/IamProcessor.java | 49 +++- .../amazon/kms/deployment/KmsProcessor.java | 49 +++- .../amazon/s3/deployment/S3Processor.java | 50 +++- .../amazon/ses/deployment/SesProcessor.java | 49 +++- .../amazon/sns/deployment/SnsProcessor.java | 49 +++- .../amazon/sqs/deployment/SqsProcessor.java | 49 +++- 18 files changed, 782 insertions(+), 429 deletions(-) create mode 100644 extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientAsyncTransportBuildItem.java create mode 100644 extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientSyncTransportBuildItem.java delete mode 100644 extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientTransportsBuildItem.java create mode 100644 extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonHttpClients.java create mode 100644 extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AbstractAmazonClientTransportRecorder.java create mode 100644 extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientApacheTransportRecorder.java create mode 100644 extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientNettyTransportRecorder.java delete mode 100644 extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java create mode 100644 extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientUrlConnectionTransportRecorder.java diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java index a678c2ecff1c2..7928a7617e82e 100644 --- a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java +++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java @@ -7,8 +7,10 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Type; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.common.runtime.AwsConfig; import io.quarkus.amazon.common.runtime.NettyHttpClientConfig; import io.quarkus.amazon.common.runtime.SdkBuildTimeConfig; @@ -72,61 +74,103 @@ protected void setupExtension(BeanRegistrationPhaseBuildItem beanRegistrationPha } } - public void createTransportBuilders(List amazonClients, - AmazonClientTransportRecorder recorder, + protected void createApacheSyncTransportBuilder(List amazonClients, + AmazonClientApacheTransportRecorder recorder, SyncHttpClientBuildTimeConfig buildSyncConfig, RuntimeValue syncConfig, - RuntimeValue asyncConfig, - BuildProducer clientTransports) { + BuildProducer clientSyncTransports) { Optional matchingClientBuildItem = amazonClients.stream() .filter(c -> c.getAwsClientName().equals(configName())) .findAny(); matchingClientBuildItem.ifPresent(client -> { - RuntimeValue syncTransport = null; - RuntimeValue asyncTransport = null; - - if (client.getSyncClassName().isPresent()) { - if (buildSyncConfig.type == SyncHttpClientBuildTimeConfig.SyncClientType.APACHE) { - syncTransport = recorder.configureSyncApacheHttpClient(configName(), syncConfig); - } else { - syncTransport = recorder.configureSyncUrlConnectionHttpClient(configName(), syncConfig); - } + if (!client.getSyncClassName().isPresent()) { + return; } + if (buildSyncConfig.type != SyncHttpClientBuildTimeConfig.SyncClientType.APACHE) { + return; + } + + clientSyncTransports.produce( + new AmazonClientSyncTransportBuildItem( + client.getAwsClientName(), + client.getSyncClassName().get(), + recorder.configureSync(configName(), syncConfig))); + }); + } + + protected void createUrlConnectionSyncTransportBuilder(List amazonClients, + AmazonClientUrlConnectionTransportRecorder recorder, + SyncHttpClientBuildTimeConfig buildSyncConfig, + RuntimeValue syncConfig, + BuildProducer clientSyncTransports) { + + Optional matchingClientBuildItem = amazonClients.stream() + .filter(c -> c.getAwsClientName().equals(configName())) + .findAny(); - if (client.getAsyncClassName().isPresent()) { - asyncTransport = recorder.configureAsync(configName(), asyncConfig); + matchingClientBuildItem.ifPresent(client -> { + if (!client.getSyncClassName().isPresent()) { + return; + } + if (buildSyncConfig.type != SyncHttpClientBuildTimeConfig.SyncClientType.URL) { + return; } - clientTransports.produce( - new AmazonClientTransportsBuildItem( - client.getSyncClassName(), client.getAsyncClassName(), - syncTransport, - asyncTransport, - client.getAwsClientName())); + clientSyncTransports.produce( + new AmazonClientSyncTransportBuildItem( + client.getAwsClientName(), + client.getSyncClassName().get(), + recorder.configureSync(configName(), syncConfig))); }); + } + protected void createNettyAsyncTransportBuilder(List amazonClients, + AmazonClientNettyTransportRecorder recorder, + RuntimeValue asyncConfig, + BuildProducer clientAsyncTransports) { + + Optional matchingClientBuildItem = amazonClients.stream() + .filter(c -> c.getAwsClientName().equals(configName())) + .findAny(); + + matchingClientBuildItem.ifPresent(client -> { + if (!client.getAsyncClassName().isPresent()) { + return; + } + + clientAsyncTransports.produce( + new AmazonClientAsyncTransportBuildItem( + client.getAwsClientName(), + client.getAsyncClassName().get(), + recorder.configureAsync(configName(), asyncConfig))); + }); } - protected void createClientBuilders(List clients, + protected void createClientBuilders(List syncClientBuilders, + List asyncClientBuilders, BuildProducer builderProducer, Function, RuntimeValue> syncFunc, Function, RuntimeValue> asyncFunc) { - - for (AmazonClientTransportsBuildItem client : clients) { - if (configName().equals(client.getAwsClientName())) { - RuntimeValue syncBuilder = null; - RuntimeValue asyncBuilder = null; - if (client.getSyncClassName().isPresent()) { - syncBuilder = syncFunc.apply(client.getSyncTransport()); - } - if (client.getAsyncClassName().isPresent()) { - asyncBuilder = asyncFunc.apply(client.getAsyncTransport()); - } - builderProducer.produce(new AmazonClientBuilderBuildItem(client.getAwsClientName(), syncBuilder, asyncBuilder)); - } + String configName = configName(); + + Optional> syncClientBuilder = syncClientBuilders.stream() + .filter(c -> configName.equals(c.getAwsClientName())) + .map(c -> c.getClientBuilder()) + .findFirst(); + Optional> asyncClientBuilder = asyncClientBuilders.stream() + .filter(c -> configName.equals(c.getAwsClientName())) + .map(c -> c.getClientBuilder()) + .findFirst(); + + if (!syncClientBuilder.isPresent() && !asyncClientBuilder.isPresent()) { + return; } + + builderProducer.produce(new AmazonClientBuilderBuildItem(configName, + syncClientBuilder.isPresent() ? syncFunc.apply(syncClientBuilder.get()) : null, + asyncClientBuilder.isPresent() ? asyncFunc.apply(asyncClientBuilder.get()) : null)); } protected void buildClients(List configuredClients, diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientAsyncTransportBuildItem.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientAsyncTransportBuildItem.java new file mode 100644 index 0000000000000..7c44981ab8395 --- /dev/null +++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientAsyncTransportBuildItem.java @@ -0,0 +1,34 @@ +package io.quarkus.amazon.common.deployment; + +import org.jboss.jandex.DotName; + +import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.runtime.RuntimeValue; +import software.amazon.awssdk.http.async.SdkAsyncHttpClient; + +public final class AmazonClientAsyncTransportBuildItem extends MultiBuildItem { + + private final String awsClientName; + private final DotName className; + private final RuntimeValue clientBuilder; + + public AmazonClientAsyncTransportBuildItem(String awsClientName, + DotName className, + RuntimeValue clientBuilder) { + this.awsClientName = awsClientName; + this.className = className; + this.clientBuilder = clientBuilder; + } + + public String getAwsClientName() { + return awsClientName; + } + + public DotName getClassName() { + return className; + } + + public RuntimeValue getClientBuilder() { + return clientBuilder; + } +} diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientSyncTransportBuildItem.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientSyncTransportBuildItem.java new file mode 100644 index 0000000000000..6501d3f62543e --- /dev/null +++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientSyncTransportBuildItem.java @@ -0,0 +1,34 @@ +package io.quarkus.amazon.common.deployment; + +import org.jboss.jandex.DotName; + +import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.runtime.RuntimeValue; +import software.amazon.awssdk.http.SdkHttpClient; + +public final class AmazonClientSyncTransportBuildItem extends MultiBuildItem { + + private final String awsClientName; + private final DotName className; + private final RuntimeValue clientBuilder; + + public AmazonClientSyncTransportBuildItem(String awsClientName, + DotName className, + RuntimeValue clientBuilder) { + this.awsClientName = awsClientName; + this.className = className; + this.clientBuilder = clientBuilder; + } + + public String getAwsClientName() { + return awsClientName; + } + + public DotName getClassName() { + return className; + } + + public RuntimeValue getClientBuilder() { + return clientBuilder; + } +} diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientTransportsBuildItem.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientTransportsBuildItem.java deleted file mode 100644 index 94b00bd12dc66..0000000000000 --- a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonClientTransportsBuildItem.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.quarkus.amazon.common.deployment; - -import java.util.Optional; - -import org.jboss.jandex.DotName; - -import io.quarkus.builder.item.MultiBuildItem; -import io.quarkus.runtime.RuntimeValue; -import software.amazon.awssdk.http.SdkHttpClient; -import software.amazon.awssdk.http.SdkHttpClient.Builder; -import software.amazon.awssdk.http.async.SdkAsyncHttpClient; - -public final class AmazonClientTransportsBuildItem extends MultiBuildItem { - private final Optional syncClassName; - private final Optional asyncClassName; - private final RuntimeValue syncTransport; - private final RuntimeValue asyncTransport; - - private final String awsClientName; - - public AmazonClientTransportsBuildItem(Optional syncClassName, Optional asyncClassName, - RuntimeValue syncTransport, - RuntimeValue asyncTransport, - String awsClientName) { - this.syncClassName = syncClassName; - this.asyncClassName = asyncClassName; - this.syncTransport = syncTransport; - this.asyncTransport = asyncTransport; - this.awsClientName = awsClientName; - } - - public Optional getSyncClassName() { - return syncClassName; - } - - public Optional getAsyncClassName() { - return asyncClassName; - } - - public RuntimeValue getSyncTransport() { - return syncTransport; - } - - public RuntimeValue getAsyncTransport() { - return asyncTransport; - } - - public String getAwsClientName() { - return awsClientName; - } -} diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonHttpClients.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonHttpClients.java new file mode 100644 index 0000000000000..7642ba22804db --- /dev/null +++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonHttpClients.java @@ -0,0 +1,46 @@ +package io.quarkus.amazon.common.deployment; + +import java.util.function.BooleanSupplier; + +public class AmazonHttpClients { + + public static final String APACHE_HTTP_SERVICE = "software.amazon.awssdk.http.apache.ApacheSdkHttpService"; + public static final String NETTY_HTTP_SERVICE = "software.amazon.awssdk.http.nio.netty.NettySdkAsyncHttpService"; + public static final String URL_CONNECTION_HTTP_SERVICE = "software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService"; + + public static class IsAmazonApacheHttpServicePresent implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + try { + Class.forName(APACHE_HTTP_SERVICE); + return true; + } catch (Exception e) { + return false; + } + } + }; + + public static class IsAmazonNettyHttpServicePresent implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + try { + Class.forName(NETTY_HTTP_SERVICE); + return true; + } catch (Exception e) { + return false; + } + } + }; + + public static class IsAmazonUrlConnectionHttpServicePresent implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + try { + Class.forName(URL_CONNECTION_HTTP_SERVICE); + return true; + } catch (Exception e) { + return false; + } + } + }; +} diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonServicesClientsProcessor.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonServicesClientsProcessor.java index 07a8bfc682157..204f2c50f0a9f 100644 --- a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonServicesClientsProcessor.java +++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AmazonServicesClientsProcessor.java @@ -29,10 +29,6 @@ public class AmazonServicesClientsProcessor { public static final String AWS_SDK_APPLICATION_ARCHIVE_MARKERS = "software/amazon/awssdk"; public static final String AWS_SDK_XRAY_ARCHIVE_MARKER = "com/amazonaws/xray"; - private static final String APACHE_HTTP_SERVICE = "software.amazon.awssdk.http.apache.ApacheSdkHttpService"; - private static final String NETTY_HTTP_SERVICE = "software.amazon.awssdk.http.nio.netty.NettySdkAsyncHttpService"; - private static final String URL_HTTP_SERVICE = "software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService"; - private static final DotName EXECUTION_INTERCEPTOR_NAME = DotName.createSimple(ExecutionInterceptor.class.getName()); @BuildStep @@ -98,9 +94,9 @@ void setup(CombinedIndexBuildItem combinedIndexBuildItem, // Register what's needed depending on the clients in the classpath and the configuration. // We use the configuration to guide us but if we don't have any clients configured, // we still register what's needed depending on what is in the classpath. - boolean isSyncApacheInClasspath = isInClasspath(APACHE_HTTP_SERVICE); - boolean isSyncUrlConnectionInClasspath = isInClasspath(URL_HTTP_SERVICE); - boolean isAsyncInClasspath = isInClasspath(NETTY_HTTP_SERVICE); + boolean isSyncApacheInClasspath = isInClasspath(AmazonHttpClients.APACHE_HTTP_SERVICE); + boolean isSyncUrlConnectionInClasspath = isInClasspath(AmazonHttpClients.URL_CONNECTION_HTTP_SERVICE); + boolean isAsyncInClasspath = isInClasspath(AmazonHttpClients.NETTY_HTTP_SERVICE); // Check that the clients required by the configuration are available if (syncTransportNeeded) { @@ -140,17 +136,18 @@ private static void registerSyncApacheClient(BuildProducer serviceProvider) { - serviceProvider.produce(new ServiceProviderBuildItem(SdkHttpService.class.getName(), URL_HTTP_SERVICE)); + serviceProvider.produce( + new ServiceProviderBuildItem(SdkHttpService.class.getName(), AmazonHttpClients.URL_CONNECTION_HTTP_SERVICE)); } private static void registerAsyncNettyClient(BuildProducer serviceProvider) { serviceProvider.produce( new ServiceProviderBuildItem(SdkAsyncHttpService.class.getName(), - NETTY_HTTP_SERVICE)); + AmazonHttpClients.NETTY_HTTP_SERVICE)); } private static boolean isInClasspath(String className) { diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AbstractAmazonClientTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AbstractAmazonClientTransportRecorder.java new file mode 100644 index 0000000000000..aa2682e0a9c1b --- /dev/null +++ b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AbstractAmazonClientTransportRecorder.java @@ -0,0 +1,115 @@ +package io.quarkus.amazon.common.runtime; + +import java.net.URI; +import java.util.Optional; + +import io.quarkus.runtime.RuntimeValue; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.TlsKeyManagersProvider; +import software.amazon.awssdk.http.TlsTrustManagersProvider; +import software.amazon.awssdk.http.async.SdkAsyncHttpClient; +import software.amazon.awssdk.utils.StringUtils; + +public abstract class AbstractAmazonClientTransportRecorder { + + @SuppressWarnings("rawtypes") + public RuntimeValue configureSync(String clientName, + RuntimeValue syncConfigRuntime) { + throw new IllegalStateException("Configuring a sync client is not supported by " + this.getClass().getName()); + } + + @SuppressWarnings("rawtypes") + public RuntimeValue configureAsync(String clientName, + RuntimeValue asyncConfigRuntime) { + throw new IllegalStateException("Configuring an async client is not supported by " + this.getClass().getName()); + } + + protected Optional getTlsKeyManagersProvider(TlsKeyManagersProviderConfig config) { + if (config.fileStore != null && config.fileStore.path.isPresent() && config.fileStore.type.isPresent()) { + return Optional.of(config.type.create(config)); + } + return Optional.empty(); + } + + protected Optional getTlsTrustManagersProvider(TlsTrustManagersProviderConfig config) { + if (config.fileStore != null && config.fileStore.path.isPresent() && config.fileStore.type.isPresent()) { + return Optional.of(config.type.create(config)); + } + return Optional.empty(); + } + + protected void validateProxyEndpoint(String extension, URI endpoint, String clientType) { + if (StringUtils.isBlank(endpoint.getScheme())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - scheme must be specified", + extension, clientType, endpoint.toString())); + } + if (StringUtils.isBlank(endpoint.getHost())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - host must be specified", + extension, clientType, endpoint.toString())); + } + if (StringUtils.isNotBlank(endpoint.getUserInfo())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - user info is not supported.", + extension, clientType, endpoint.toString())); + } + if (StringUtils.isNotBlank(endpoint.getPath())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - path is not supported.", + extension, clientType, endpoint.toString())); + } + if (StringUtils.isNotBlank(endpoint.getQuery())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - query is not supported.", + extension, clientType, endpoint.toString())); + } + if (StringUtils.isNotBlank(endpoint.getFragment())) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - fragment is not supported.", + extension, clientType, endpoint.toString())); + } + } + + protected void validateTlsKeyManagersProvider(String extension, TlsKeyManagersProviderConfig config, String clientType) { + if (config != null && config.type == TlsKeyManagersProviderType.FILE_STORE) { + validateFileStore(extension, clientType, "key", config.fileStore); + } + } + + protected void validateTlsTrustManagersProvider(String extension, TlsTrustManagersProviderConfig config, + String clientType) { + if (config != null && config.type == TlsTrustManagersProviderType.FILE_STORE) { + validateFileStore(extension, clientType, "trust", config.fileStore); + } + } + + protected void validateFileStore(String extension, String clientType, String storeType, + FileStoreTlsManagersProviderConfig fileStore) { + if (fileStore == null) { + throw new RuntimeConfigurationError( + String.format( + "quarkus.%s.%s-client.tls-%s-managers-provider.file-store must be specified if 'FILE_STORE' provider type is used", + extension, clientType, storeType)); + } else { + if (!fileStore.password.isPresent()) { + throw new RuntimeConfigurationError( + String.format( + "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.path should not be empty if 'FILE_STORE' provider is used.", + extension, clientType, storeType)); + } + if (!fileStore.type.isPresent()) { + throw new RuntimeConfigurationError( + String.format( + "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.type should not be empty if 'FILE_STORE' provider is used.", + extension, clientType, storeType)); + } + if (!fileStore.password.isPresent()) { + throw new RuntimeConfigurationError( + String.format( + "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.password should not be empty if 'FILE_STORE' provider is used.", + extension, clientType, storeType)); + } + } + } +} diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientApacheTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientApacheTransportRecorder.java new file mode 100644 index 0000000000000..cc1a0c7fffe7f --- /dev/null +++ b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientApacheTransportRecorder.java @@ -0,0 +1,59 @@ +package io.quarkus.amazon.common.runtime; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ApacheHttpClient.Builder; +import software.amazon.awssdk.http.apache.ProxyConfiguration; + +@Recorder +public class AmazonClientApacheTransportRecorder extends AbstractAmazonClientTransportRecorder { + + @SuppressWarnings("rawtypes") + @Override + public RuntimeValue configureSync(String clientName, + RuntimeValue syncConfigRuntime) { + SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue(); + validateTlsKeyManagersProvider(clientName, syncConfig.tlsKeyManagersProvider, "sync"); + validateTlsTrustManagersProvider(clientName, syncConfig.tlsTrustManagersProvider, "sync"); + Builder builder = ApacheHttpClient.builder(); + validateApacheClientConfig(clientName, syncConfig); + + builder.connectionTimeout(syncConfig.connectionTimeout); + builder.connectionAcquisitionTimeout(syncConfig.apache.connectionAcquisitionTimeout); + builder.connectionMaxIdleTime(syncConfig.apache.connectionMaxIdleTime); + syncConfig.apache.connectionTimeToLive.ifPresent(builder::connectionTimeToLive); + builder.expectContinueEnabled(syncConfig.apache.expectContinueEnabled); + builder.maxConnections(syncConfig.apache.maxConnections); + builder.socketTimeout(syncConfig.socketTimeout); + builder.useIdleConnectionReaper(syncConfig.apache.useIdleConnectionReaper); + + if (syncConfig.apache.proxy.enabled && syncConfig.apache.proxy.endpoint.isPresent()) { + ProxyConfiguration.Builder proxyBuilder = ProxyConfiguration.builder() + .endpoint(syncConfig.apache.proxy.endpoint.get()); + syncConfig.apache.proxy.username.ifPresent(proxyBuilder::username); + syncConfig.apache.proxy.password.ifPresent(proxyBuilder::password); + syncConfig.apache.proxy.nonProxyHosts.ifPresent(c -> c.forEach(proxyBuilder::addNonProxyHost)); + syncConfig.apache.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain); + syncConfig.apache.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation); + syncConfig.apache.proxy.preemptiveBasicAuthenticationEnabled + .ifPresent(proxyBuilder::preemptiveBasicAuthenticationEnabled); + + builder.proxyConfiguration(proxyBuilder.build()); + } + getTlsKeyManagersProvider(syncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); + getTlsTrustManagersProvider(syncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); + return new RuntimeValue<>(builder); + } + + private void validateApacheClientConfig(String extension, SyncHttpClientConfig config) { + if (config.apache.maxConnections <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.sync-client.max-connections may not be negative or zero.", extension)); + } + if (config.apache.proxy.enabled) { + config.apache.proxy.endpoint.ifPresent(uri -> validateProxyEndpoint(extension, uri, "sync")); + } + } +} diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientNettyTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientNettyTransportRecorder.java new file mode 100644 index 0000000000000..7cd4691b7e2a1 --- /dev/null +++ b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientNettyTransportRecorder.java @@ -0,0 +1,108 @@ +package io.quarkus.amazon.common.runtime; + +import java.util.Collections; +import java.util.HashSet; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import software.amazon.awssdk.http.async.SdkAsyncHttpClient; +import software.amazon.awssdk.http.nio.netty.Http2Configuration; +import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; +import software.amazon.awssdk.http.nio.netty.SdkEventLoopGroup; +import software.amazon.awssdk.utils.ThreadFactoryBuilder; + +@Recorder +public class AmazonClientNettyTransportRecorder extends AbstractAmazonClientTransportRecorder { + + @SuppressWarnings("rawtypes") + @Override + public RuntimeValue configureAsync(String clientName, + RuntimeValue asyncConfigRuntime) { + NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder(); + NettyHttpClientConfig asyncConfig = asyncConfigRuntime.getValue(); + validateNettyClientConfig(clientName, asyncConfig); + + builder.connectionAcquisitionTimeout(asyncConfig.connectionAcquisitionTimeout); + builder.connectionMaxIdleTime(asyncConfig.connectionMaxIdleTime); + builder.connectionTimeout(asyncConfig.connectionTimeout); + asyncConfig.connectionTimeToLive.ifPresent(builder::connectionTimeToLive); + builder.maxConcurrency(asyncConfig.maxConcurrency); + builder.maxPendingConnectionAcquires(asyncConfig.maxPendingConnectionAcquires); + builder.protocol(asyncConfig.protocol); + builder.readTimeout(asyncConfig.readTimeout); + builder.writeTimeout(asyncConfig.writeTimeout); + asyncConfig.sslProvider.ifPresent(builder::sslProvider); + builder.useIdleConnectionReaper(asyncConfig.useIdleConnectionReaper); + + if (asyncConfig.http2.initialWindowSize.isPresent() || asyncConfig.http2.maxStreams.isPresent()) { + Http2Configuration.Builder http2Builder = Http2Configuration.builder(); + asyncConfig.http2.initialWindowSize.ifPresent(http2Builder::initialWindowSize); + asyncConfig.http2.maxStreams.ifPresent(http2Builder::maxStreams); + asyncConfig.http2.healthCheckPingPeriod.ifPresent(http2Builder::healthCheckPingPeriod); + builder.http2Configuration(http2Builder.build()); + } + + if (asyncConfig.proxy.enabled && asyncConfig.proxy.endpoint.isPresent()) { + software.amazon.awssdk.http.nio.netty.ProxyConfiguration.Builder proxyBuilder = software.amazon.awssdk.http.nio.netty.ProxyConfiguration + .builder().scheme(asyncConfig.proxy.endpoint.get().getScheme()) + .host(asyncConfig.proxy.endpoint.get().getHost()) + .nonProxyHosts(new HashSet<>(asyncConfig.proxy.nonProxyHosts.orElse(Collections.emptyList()))); + + if (asyncConfig.proxy.endpoint.get().getPort() != -1) { + proxyBuilder.port(asyncConfig.proxy.endpoint.get().getPort()); + } + builder.proxyConfiguration(proxyBuilder.build()); + } + + getTlsKeyManagersProvider(asyncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); + getTlsTrustManagersProvider(asyncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); + + if (asyncConfig.eventLoop.override) { + SdkEventLoopGroup.Builder eventLoopBuilder = SdkEventLoopGroup.builder(); + asyncConfig.eventLoop.numberOfThreads.ifPresent(eventLoopBuilder::numberOfThreads); + if (asyncConfig.eventLoop.threadNamePrefix.isPresent()) { + eventLoopBuilder.threadFactory( + new ThreadFactoryBuilder().threadNamePrefix(asyncConfig.eventLoop.threadNamePrefix.get()).build()); + } + builder.eventLoopGroupBuilder(eventLoopBuilder); + } + + return new RuntimeValue<>(builder); + } + + private void validateNettyClientConfig(String extension, NettyHttpClientConfig config) { + if (config.maxConcurrency <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.async-client.max-concurrency may not be negative or zero.", extension)); + } + + if (config.http2.maxStreams.isPresent() && config.http2.maxStreams.get() <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.async-client.http2.max-streams may not be negative.", extension)); + } + + if (config.http2.initialWindowSize.isPresent() && config.http2.initialWindowSize.getAsInt() <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.async-client.http2.initial-window-size may not be negative.", extension)); + } + + if (config.maxPendingConnectionAcquires <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.async-client.max-pending-connection-acquires may not be negative or zero.", + extension)); + } + if (config.eventLoop.override) { + if (config.eventLoop.numberOfThreads.isPresent() && config.eventLoop.numberOfThreads.getAsInt() <= 0) { + throw new RuntimeConfigurationError( + String.format("quarkus.%s.async-client.event-loop.number-of-threads may not be negative or zero.", + extension)); + } + } + if (config.proxy.enabled) { + config.proxy.endpoint.ifPresent(uri -> validateProxyEndpoint(extension, uri, "async")); + } + + validateTlsKeyManagersProvider(extension, config.tlsKeyManagersProvider, "async"); + validateTlsTrustManagersProvider(extension, config.tlsTrustManagersProvider, "async"); + } +} diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java deleted file mode 100644 index 50ddd8cdfd997..0000000000000 --- a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java +++ /dev/null @@ -1,262 +0,0 @@ -package io.quarkus.amazon.common.runtime; - -import java.net.URI; -import java.util.Collections; -import java.util.HashSet; -import java.util.Optional; - -import io.quarkus.runtime.RuntimeValue; -import io.quarkus.runtime.annotations.Recorder; -import software.amazon.awssdk.http.SdkHttpClient; -import software.amazon.awssdk.http.TlsKeyManagersProvider; -import software.amazon.awssdk.http.TlsTrustManagersProvider; -import software.amazon.awssdk.http.apache.ApacheHttpClient; -import software.amazon.awssdk.http.apache.ApacheHttpClient.Builder; -import software.amazon.awssdk.http.apache.ProxyConfiguration; -import software.amazon.awssdk.http.async.SdkAsyncHttpClient; -import software.amazon.awssdk.http.nio.netty.Http2Configuration; -import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; -import software.amazon.awssdk.http.nio.netty.SdkEventLoopGroup; -import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; -import software.amazon.awssdk.utils.StringUtils; -import software.amazon.awssdk.utils.ThreadFactoryBuilder; - -@Recorder -public class AmazonClientTransportRecorder { - - public RuntimeValue configureAsync(String clientName, - RuntimeValue asyncConfigRuntime) { - NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder(); - NettyHttpClientConfig asyncConfig = asyncConfigRuntime.getValue(); - validateNettyClientConfig(clientName, asyncConfig); - - builder.connectionAcquisitionTimeout(asyncConfig.connectionAcquisitionTimeout); - builder.connectionMaxIdleTime(asyncConfig.connectionMaxIdleTime); - builder.connectionTimeout(asyncConfig.connectionTimeout); - asyncConfig.connectionTimeToLive.ifPresent(builder::connectionTimeToLive); - builder.maxConcurrency(asyncConfig.maxConcurrency); - builder.maxPendingConnectionAcquires(asyncConfig.maxPendingConnectionAcquires); - builder.protocol(asyncConfig.protocol); - builder.readTimeout(asyncConfig.readTimeout); - builder.writeTimeout(asyncConfig.writeTimeout); - asyncConfig.sslProvider.ifPresent(builder::sslProvider); - builder.useIdleConnectionReaper(asyncConfig.useIdleConnectionReaper); - - if (asyncConfig.http2.initialWindowSize.isPresent() || asyncConfig.http2.maxStreams.isPresent()) { - Http2Configuration.Builder http2Builder = Http2Configuration.builder(); - asyncConfig.http2.initialWindowSize.ifPresent(http2Builder::initialWindowSize); - asyncConfig.http2.maxStreams.ifPresent(http2Builder::maxStreams); - asyncConfig.http2.healthCheckPingPeriod.ifPresent(http2Builder::healthCheckPingPeriod); - builder.http2Configuration(http2Builder.build()); - } - - if (asyncConfig.proxy.enabled && asyncConfig.proxy.endpoint.isPresent()) { - software.amazon.awssdk.http.nio.netty.ProxyConfiguration.Builder proxyBuilder = software.amazon.awssdk.http.nio.netty.ProxyConfiguration - .builder().scheme(asyncConfig.proxy.endpoint.get().getScheme()) - .host(asyncConfig.proxy.endpoint.get().getHost()) - .nonProxyHosts(new HashSet<>(asyncConfig.proxy.nonProxyHosts.orElse(Collections.emptyList()))); - - if (asyncConfig.proxy.endpoint.get().getPort() != -1) { - proxyBuilder.port(asyncConfig.proxy.endpoint.get().getPort()); - } - builder.proxyConfiguration(proxyBuilder.build()); - } - - getTlsKeyManagersProvider(asyncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); - getTlsTrustManagersProvider(asyncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); - - if (asyncConfig.eventLoop.override) { - SdkEventLoopGroup.Builder eventLoopBuilder = SdkEventLoopGroup.builder(); - asyncConfig.eventLoop.numberOfThreads.ifPresent(eventLoopBuilder::numberOfThreads); - if (asyncConfig.eventLoop.threadNamePrefix.isPresent()) { - eventLoopBuilder.threadFactory( - new ThreadFactoryBuilder().threadNamePrefix(asyncConfig.eventLoop.threadNamePrefix.get()).build()); - } - builder.eventLoopGroupBuilder(eventLoopBuilder); - } - - return new RuntimeValue<>(builder); - } - - public RuntimeValue configureSyncUrlConnectionHttpClient(String clientName, - RuntimeValue syncConfigRuntime) { - SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue(); - validateTlsKeyManagersProvider(clientName, syncConfig.tlsKeyManagersProvider, "sync"); - validateTlsTrustManagersProvider(clientName, syncConfig.tlsTrustManagersProvider, "sync"); - UrlConnectionHttpClient.Builder builder = UrlConnectionHttpClient.builder(); - builder.connectionTimeout(syncConfig.connectionTimeout); - builder.socketTimeout(syncConfig.socketTimeout); - getTlsKeyManagersProvider(syncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); - getTlsTrustManagersProvider(syncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); - return new RuntimeValue<>(builder); - } - - public RuntimeValue configureSyncApacheHttpClient(String clientName, - RuntimeValue syncConfigRuntime) { - SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue(); - validateTlsKeyManagersProvider(clientName, syncConfig.tlsKeyManagersProvider, "sync"); - validateTlsTrustManagersProvider(clientName, syncConfig.tlsTrustManagersProvider, "sync"); - Builder builder = ApacheHttpClient.builder(); - validateApacheClientConfig(clientName, syncConfig); - - builder.connectionTimeout(syncConfig.connectionTimeout); - builder.connectionAcquisitionTimeout(syncConfig.apache.connectionAcquisitionTimeout); - builder.connectionMaxIdleTime(syncConfig.apache.connectionMaxIdleTime); - syncConfig.apache.connectionTimeToLive.ifPresent(builder::connectionTimeToLive); - builder.expectContinueEnabled(syncConfig.apache.expectContinueEnabled); - builder.maxConnections(syncConfig.apache.maxConnections); - builder.socketTimeout(syncConfig.socketTimeout); - builder.useIdleConnectionReaper(syncConfig.apache.useIdleConnectionReaper); - - if (syncConfig.apache.proxy.enabled && syncConfig.apache.proxy.endpoint.isPresent()) { - ProxyConfiguration.Builder proxyBuilder = ProxyConfiguration.builder() - .endpoint(syncConfig.apache.proxy.endpoint.get()); - syncConfig.apache.proxy.username.ifPresent(proxyBuilder::username); - syncConfig.apache.proxy.password.ifPresent(proxyBuilder::password); - syncConfig.apache.proxy.nonProxyHosts.ifPresent(c -> c.forEach(proxyBuilder::addNonProxyHost)); - syncConfig.apache.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain); - syncConfig.apache.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation); - syncConfig.apache.proxy.preemptiveBasicAuthenticationEnabled - .ifPresent(proxyBuilder::preemptiveBasicAuthenticationEnabled); - - builder.proxyConfiguration(proxyBuilder.build()); - } - getTlsKeyManagersProvider(syncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); - getTlsTrustManagersProvider(syncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); - return new RuntimeValue<>(builder); - } - - private Optional getTlsKeyManagersProvider(TlsKeyManagersProviderConfig config) { - if (config.fileStore != null && config.fileStore.path.isPresent() && config.fileStore.type.isPresent()) { - return Optional.of(config.type.create(config)); - } - return Optional.empty(); - } - - private Optional getTlsTrustManagersProvider(TlsTrustManagersProviderConfig config) { - if (config.fileStore != null && config.fileStore.path.isPresent() && config.fileStore.type.isPresent()) { - return Optional.of(config.type.create(config)); - } - return Optional.empty(); - } - - private void validateApacheClientConfig(String extension, SyncHttpClientConfig config) { - if (config.apache.maxConnections <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.sync-client.max-connections may not be negative or zero.", extension)); - } - if (config.apache.proxy.enabled) { - config.apache.proxy.endpoint.ifPresent(uri -> validateProxyEndpoint(extension, uri, "sync")); - } - } - - private void validateNettyClientConfig(String extension, NettyHttpClientConfig config) { - if (config.maxConcurrency <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.async-client.max-concurrency may not be negative or zero.", extension)); - } - - if (config.http2.maxStreams.isPresent() && config.http2.maxStreams.get() <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.async-client.http2.max-streams may not be negative.", extension)); - } - - if (config.http2.initialWindowSize.isPresent() && config.http2.initialWindowSize.getAsInt() <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.async-client.http2.initial-window-size may not be negative.", extension)); - } - - if (config.maxPendingConnectionAcquires <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.async-client.max-pending-connection-acquires may not be negative or zero.", - extension)); - } - if (config.eventLoop.override) { - if (config.eventLoop.numberOfThreads.isPresent() && config.eventLoop.numberOfThreads.getAsInt() <= 0) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.async-client.event-loop.number-of-threads may not be negative or zero.", - extension)); - } - } - if (config.proxy.enabled) { - config.proxy.endpoint.ifPresent(uri -> validateProxyEndpoint(extension, uri, "async")); - } - - validateTlsKeyManagersProvider(extension, config.tlsKeyManagersProvider, "async"); - validateTlsTrustManagersProvider(extension, config.tlsTrustManagersProvider, "async"); - } - - private void validateProxyEndpoint(String extension, URI endpoint, String clientType) { - if (StringUtils.isBlank(endpoint.getScheme())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - scheme must be specified", - extension, clientType, endpoint.toString())); - } - if (StringUtils.isBlank(endpoint.getHost())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - host must be specified", - extension, clientType, endpoint.toString())); - } - if (StringUtils.isNotBlank(endpoint.getUserInfo())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - user info is not supported.", - extension, clientType, endpoint.toString())); - } - if (StringUtils.isNotBlank(endpoint.getPath())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - path is not supported.", - extension, clientType, endpoint.toString())); - } - if (StringUtils.isNotBlank(endpoint.getQuery())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - query is not supported.", - extension, clientType, endpoint.toString())); - } - if (StringUtils.isNotBlank(endpoint.getFragment())) { - throw new RuntimeConfigurationError( - String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - fragment is not supported.", - extension, clientType, endpoint.toString())); - } - } - - private void validateTlsKeyManagersProvider(String extension, TlsKeyManagersProviderConfig config, String clientType) { - if (config != null && config.type == TlsKeyManagersProviderType.FILE_STORE) { - validateFileStore(extension, clientType, "key", config.fileStore); - } - } - - private void validateTlsTrustManagersProvider(String extension, TlsTrustManagersProviderConfig config, String clientType) { - if (config != null && config.type == TlsTrustManagersProviderType.FILE_STORE) { - validateFileStore(extension, clientType, "trust", config.fileStore); - } - } - - private void validateFileStore(String extension, String clientType, String storeType, - FileStoreTlsManagersProviderConfig fileStore) { - if (fileStore == null) { - throw new RuntimeConfigurationError( - String.format( - "quarkus.%s.%s-client.tls-%s-managers-provider.file-store must be specified if 'FILE_STORE' provider type is used", - extension, clientType, storeType)); - } else { - if (!fileStore.password.isPresent()) { - throw new RuntimeConfigurationError( - String.format( - "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.path should not be empty if 'FILE_STORE' provider is used.", - extension, clientType, storeType)); - } - if (!fileStore.type.isPresent()) { - throw new RuntimeConfigurationError( - String.format( - "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.type should not be empty if 'FILE_STORE' provider is used.", - extension, clientType, storeType)); - } - if (!fileStore.password.isPresent()) { - throw new RuntimeConfigurationError( - String.format( - "quarkus.%s.%s-client.tls-%s-managers-provider.file-store.password should not be empty if 'FILE_STORE' provider is used.", - extension, clientType, storeType)); - } - } - } -} diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientUrlConnectionTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientUrlConnectionTransportRecorder.java new file mode 100644 index 0000000000000..591eaa08ceb96 --- /dev/null +++ b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientUrlConnectionTransportRecorder.java @@ -0,0 +1,25 @@ +package io.quarkus.amazon.common.runtime; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; + +@Recorder +public class AmazonClientUrlConnectionTransportRecorder extends AbstractAmazonClientTransportRecorder { + + @SuppressWarnings("rawtypes") + @Override + public RuntimeValue configureSync(String clientName, + RuntimeValue syncConfigRuntime) { + SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue(); + validateTlsKeyManagersProvider(clientName, syncConfig.tlsKeyManagersProvider, "sync"); + validateTlsTrustManagersProvider(clientName, syncConfig.tlsTrustManagersProvider, "sync"); + UrlConnectionHttpClient.Builder builder = UrlConnectionHttpClient.builder(); + builder.connectionTimeout(syncConfig.connectionTimeout); + builder.socketTimeout(syncConfig.socketTimeout); + getTlsKeyManagersProvider(syncConfig.tlsKeyManagersProvider).ifPresent(builder::tlsKeyManagersProvider); + getTlsTrustManagersProvider(syncConfig.tlsTrustManagersProvider).ifPresent(builder::tlsTrustManagersProvider); + return new RuntimeValue<>(builder); + } +} diff --git a/extensions/amazon-services/dynamodb/deployment/src/main/java/io/quarkus/amazon/dynamodb/deployment/DynamodbProcessor.java b/extensions/amazon-services/dynamodb/deployment/src/main/java/io/quarkus/amazon/dynamodb/deployment/DynamodbProcessor.java index ee98f3ee319e5..6a2e0d57d33c0 100644 --- a/extensions/amazon-services/dynamodb/deployment/src/main/java/io/quarkus/amazon/dynamodb/deployment/DynamodbProcessor.java +++ b/extensions/amazon-services/dynamodb/deployment/src/main/java/io/quarkus/amazon/dynamodb/deployment/DynamodbProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.dynamodb.runtime.DynamodbBuildTimeConfig; import io.quarkus.amazon.dynamodb.runtime.DynamodbClientProducer; import io.quarkus.amazon.dynamodb.runtime.DynamodbConfig; @@ -75,26 +79,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.sdk, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, DynamodbRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - DynamodbConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, DynamodbRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + DynamodbConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, DynamodbRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + DynamodbConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, DynamodbRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + DynamodbConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, DynamodbRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, DynamodbRecorder recorder, DynamodbConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/iam/deployment/src/main/java/io/quarkus/amazon/iam/deployment/IamProcessor.java b/extensions/amazon-services/iam/deployment/src/main/java/io/quarkus/amazon/iam/deployment/IamProcessor.java index 28c588cab779b..54016a4c4cabe 100644 --- a/extensions/amazon-services/iam/deployment/src/main/java/io/quarkus/amazon/iam/deployment/IamProcessor.java +++ b/extensions/amazon-services/iam/deployment/src/main/java/io/quarkus/amazon/iam/deployment/IamProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.iam.runtime.IamBuildTimeConfig; import io.quarkus.amazon.iam.runtime.IamClientProducer; import io.quarkus.amazon.iam.runtime.IamConfig; @@ -75,26 +79,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.sdk, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, IamRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - IamConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, IamRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + IamConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, IamRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + IamConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, IamRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + IamConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, IamRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, IamRecorder recorder, IamConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/kms/deployment/src/main/java/io/quarkus/amazon/kms/deployment/KmsProcessor.java b/extensions/amazon-services/kms/deployment/src/main/java/io/quarkus/amazon/kms/deployment/KmsProcessor.java index 4c97d707ae865..64d256bd147be 100644 --- a/extensions/amazon-services/kms/deployment/src/main/java/io/quarkus/amazon/kms/deployment/KmsProcessor.java +++ b/extensions/amazon-services/kms/deployment/src/main/java/io/quarkus/amazon/kms/deployment/KmsProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.kms.runtime.KmsBuildTimeConfig; import io.quarkus.amazon.kms.runtime.KmsClientProducer; import io.quarkus.amazon.kms.runtime.KmsConfig; @@ -75,26 +79,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.sdk, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, KmsRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - KmsConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, KmsRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + KmsConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, KmsRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + KmsConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, KmsRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + KmsConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, KmsRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, KmsRecorder recorder, KmsConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/s3/deployment/src/main/java/io/quarkus/amazon/s3/deployment/S3Processor.java b/extensions/amazon-services/s3/deployment/src/main/java/io/quarkus/amazon/s3/deployment/S3Processor.java index 57c0b4aaabfa9..b8b128ef98555 100644 --- a/extensions/amazon-services/s3/deployment/src/main/java/io/quarkus/amazon/s3/deployment/S3Processor.java +++ b/extensions/amazon-services/s3/deployment/src/main/java/io/quarkus/amazon/s3/deployment/S3Processor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.s3.runtime.S3BuildTimeConfig; import io.quarkus.amazon.s3.runtime.S3ClientProducer; import io.quarkus.amazon.s3.runtime.S3Config; @@ -76,26 +80,52 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, S3Recorder recorder, - AmazonClientTransportRecorder transportRecorder, - S3Config runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, S3Recorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + S3Config runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, S3Recorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + S3Config runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, S3Recorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + S3Config runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, S3Recorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, + S3Recorder recorder, S3Config runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/ses/deployment/src/main/java/io/quarkus/amazon/ses/deployment/SesProcessor.java b/extensions/amazon-services/ses/deployment/src/main/java/io/quarkus/amazon/ses/deployment/SesProcessor.java index 5811f5e3a5306..198924ee1ae45 100644 --- a/extensions/amazon-services/ses/deployment/src/main/java/io/quarkus/amazon/ses/deployment/SesProcessor.java +++ b/extensions/amazon-services/ses/deployment/src/main/java/io/quarkus/amazon/ses/deployment/SesProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.ses.runtime.SesBuildTimeConfig; import io.quarkus.amazon.ses.runtime.SesClientProducer; import io.quarkus.amazon.ses.runtime.SesConfig; @@ -75,26 +79,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.sdk, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, SesRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - SesConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, SesRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + SesConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, SesRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + SesConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, SesRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + SesConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, SesRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, SesRecorder recorder, SesConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/sns/deployment/src/main/java/io/quarkus/amazon/sns/deployment/SnsProcessor.java b/extensions/amazon-services/sns/deployment/src/main/java/io/quarkus/amazon/sns/deployment/SnsProcessor.java index 00e237cb8b657..b4240b44c288d 100644 --- a/extensions/amazon-services/sns/deployment/src/main/java/io/quarkus/amazon/sns/deployment/SnsProcessor.java +++ b/extensions/amazon-services/sns/deployment/src/main/java/io/quarkus/amazon/sns/deployment/SnsProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.sns.runtime.SnsBuildTimeConfig; import io.quarkus.amazon.sns.runtime.SnsClientProducer; import io.quarkus.amazon.sns.runtime.SnsConfig; @@ -76,26 +80,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, SnsRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - SnsConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, SnsRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + SnsConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, SnsRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + SnsConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, SnsRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + SnsConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, SnsRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, SnsRecorder recorder, SnsConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); } diff --git a/extensions/amazon-services/sqs/deployment/src/main/java/io/quarkus/amazon/sqs/deployment/SqsProcessor.java b/extensions/amazon-services/sqs/deployment/src/main/java/io/quarkus/amazon/sqs/deployment/SqsProcessor.java index 6ba7663a0400b..b718a9239f458 100644 --- a/extensions/amazon-services/sqs/deployment/src/main/java/io/quarkus/amazon/sqs/deployment/SqsProcessor.java +++ b/extensions/amazon-services/sqs/deployment/src/main/java/io/quarkus/amazon/sqs/deployment/SqsProcessor.java @@ -5,13 +5,17 @@ import org.jboss.jandex.DotName; import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor; +import io.quarkus.amazon.common.deployment.AmazonClientAsyncTransportBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientBuilderConfiguredBuildItem; import io.quarkus.amazon.common.deployment.AmazonClientInterceptorsPathBuildItem; -import io.quarkus.amazon.common.deployment.AmazonClientTransportsBuildItem; +import io.quarkus.amazon.common.deployment.AmazonClientSyncTransportBuildItem; +import io.quarkus.amazon.common.deployment.AmazonHttpClients; +import io.quarkus.amazon.common.runtime.AmazonClientApacheTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder; import io.quarkus.amazon.common.runtime.AmazonClientRecorder; -import io.quarkus.amazon.common.runtime.AmazonClientTransportRecorder; +import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder; import io.quarkus.amazon.sqs.runtime.SqsBuildTimeConfig; import io.quarkus.amazon.sqs.runtime.SqsClientProducer; import io.quarkus.amazon.sqs.runtime.SqsConfig; @@ -76,26 +80,51 @@ void setup(BeanRegistrationPhaseBuildItem beanRegistrationPhase, buildTimeConfig.syncClient); } - @BuildStep + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonApacheHttpServicePresent.class) @Record(ExecutionTime.RUNTIME_INIT) - void setupTransport(List amazonClients, SqsRecorder recorder, - AmazonClientTransportRecorder transportRecorder, - SqsConfig runtimeConfig, BuildProducer clientTransportBuildProducer) { + void setupApacheSyncTransport(List amazonClients, SqsRecorder recorder, + AmazonClientApacheTransportRecorder transportRecorder, + SqsConfig runtimeConfig, BuildProducer syncTransports) { - createTransportBuilders(amazonClients, + createApacheSyncTransportBuilder(amazonClients, transportRecorder, buildTimeConfig.syncClient, recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonUrlConnectionHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupUrlConnectionSyncTransport(List amazonClients, SqsRecorder recorder, + AmazonClientUrlConnectionTransportRecorder transportRecorder, + SqsConfig runtimeConfig, BuildProducer syncTransports) { + + createUrlConnectionSyncTransportBuilder(amazonClients, + transportRecorder, + buildTimeConfig.syncClient, + recorder.getSyncConfig(runtimeConfig), + syncTransports); + } + + @BuildStep(onlyIf = AmazonHttpClients.IsAmazonNettyHttpServicePresent.class) + @Record(ExecutionTime.RUNTIME_INIT) + void setupNettyAsyncTransport(List amazonClients, SqsRecorder recorder, + AmazonClientNettyTransportRecorder transportRecorder, + SqsConfig runtimeConfig, BuildProducer asyncTransports) { + + createNettyAsyncTransportBuilder(amazonClients, + transportRecorder, recorder.getAsyncConfig(runtimeConfig), - clientTransportBuildProducer); + asyncTransports); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void createClientBuilders(List transportBuildItems, SqsRecorder recorder, + void createClientBuilders(List syncTransports, + List asyncTransports, SqsRecorder recorder, SqsConfig runtimeConfig, BuildProducer builderProducer) { - createClientBuilders(transportBuildItems, builderProducer, + createClientBuilders(syncTransports, asyncTransports, builderProducer, (syncTransport) -> recorder.createSyncBuilder(runtimeConfig, syncTransport), (asyncTransport) -> recorder.createAsyncBuilder(runtimeConfig, asyncTransport)); }