This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new cfafc48b826d CAMEL-22786 - Camel-AWS: Extract common logic for clients
instantiation in a separated module - AWS S3 (#20434)
cfafc48b826d is described below
commit cfafc48b826d3772c3955b3f02fdf031e0e2e720
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Dec 15 14:13:19 2025 +0100
CAMEL-22786 - Camel-AWS: Extract common logic for clients instantiation in
a separated module - AWS S3 (#20434)
Signed-off-by: Andrea Cosentino <[email protected]>
---
bom/camel-bom/pom.xml | 5 +
catalog/camel-allcomponents/pom.xml | 5 +
.../{camel-aws2-s3 => camel-aws-common}/pom.xml | 45 ++---
.../services/org/apache/camel/other.properties | 7 +
.../src/generated/resources/aws-common.json | 15 ++
.../component/aws/common/AwsClientBuilderUtil.java | 207 +++++++++++++++++++++
.../aws/common/AwsCommonConfiguration.java | 112 +++++++++++
components/camel-aws/camel-aws2-s3/pom.xml | 4 +
.../component/aws2/s3/AWS2S3Configuration.java | 3 +-
.../camel/component/aws2/s3/AWS2S3Endpoint.java | 2 +-
.../aws2/s3/client/AWS2CamelS3InternalClient.java | 32 ----
.../aws2/s3/client/AWS2S3ClientFactory.java | 34 ++--
.../client/impl/AWS2S3ClientIAMOptimizedImpl.java | 96 ----------
.../impl/AWS2S3ClientIAMProfileOptimizedImpl.java | 111 -----------
.../client/impl/AWS2S3ClientSessionTokenImpl.java | 114 ------------
.../s3/client/impl/AWS2S3ClientStandardImpl.java | 112 -----------
.../component/aws2/s3/AWSS3ClientFactoryTest.java | 57 +++---
components/camel-aws/pom.xml | 1 +
.../modules/others/examples/json/aws-common.json | 1 +
parent/pom.xml | 5 +
.../camel/maven/packaging/PrepareCatalogMojo.java | 1 +
21 files changed, 425 insertions(+), 544 deletions(-)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 229266c9394e..643a971175b6 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -136,6 +136,11 @@
<artifactId>camel-aws-cloudtrail</artifactId>
<version>4.17.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-aws-common</artifactId>
+ <version>4.17.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws-config</artifactId>
diff --git a/catalog/camel-allcomponents/pom.xml
b/catalog/camel-allcomponents/pom.xml
index 073ce53c6698..6483ad8378df 100644
--- a/catalog/camel-allcomponents/pom.xml
+++ b/catalog/camel-allcomponents/pom.xml
@@ -136,6 +136,11 @@
<artifactId>camel-aws-cloudtrail</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-aws-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws-config</artifactId>
diff --git a/components/camel-aws/camel-aws2-s3/pom.xml
b/components/camel-aws/camel-aws-common/pom.xml
similarity index 67%
copy from components/camel-aws/camel-aws2-s3/pom.xml
copy to components/camel-aws/camel-aws-common/pom.xml
index 12364fdd7f6e..5b4c0e1d1b97 100644
--- a/components/camel-aws/camel-aws2-s3/pom.xml
+++ b/components/camel-aws/camel-aws-common/pom.xml
@@ -18,6 +18,7 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -26,13 +27,14 @@
<version>4.17.0-SNAPSHOT</version>
</parent>
- <artifactId>camel-aws2-s3</artifactId>
+ <artifactId>camel-aws-common</artifactId>
<packaging>jar</packaging>
-
- <name>Camel :: AWS2 S3</name>
- <description>Consume files and upload files through AWS S3
Service</description>
+ <name>Camel :: AWS :: Common</name>
+ <description>Camel AWS Common utilities for client
initialization</description>
<properties>
+ <firstVersion>4.17.0</firstVersion>
+ <label>cloud,aws</label>
</properties>
<dependencies>
@@ -42,48 +44,29 @@
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
- <artifactId>s3</artifactId>
+ <artifactId>apache-client</artifactId>
<version>${aws-java-sdk2-version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
- <artifactId>checksums</artifactId>
+ <artifactId>auth</artifactId>
<version>${aws-java-sdk2-version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
- <artifactId>sts</artifactId>
+ <artifactId>regions</artifactId>
<version>${aws-java-sdk2-version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
- <artifactId>apache-client</artifactId>
+ <artifactId>sdk-core</artifactId>
<version>${aws-java-sdk2-version}</version>
</dependency>
<dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-health</artifactId>
- </dependency>
-
- <!-- for testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring-junit5</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-zip-deflater</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- test infra -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-infra-aws-v2</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
+ <groupId>software.amazon.awssdk</groupId>
+ <artifactId>aws-core</artifactId>
+ <version>${aws-java-sdk2-version}</version>
</dependency>
</dependencies>
+
</project>
diff --git
a/components/camel-aws/camel-aws-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
b/components/camel-aws/camel-aws-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
new file mode 100644
index 000000000000..cac64086e8f1
--- /dev/null
+++
b/components/camel-aws/camel-aws-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+name=aws-common
+groupId=org.apache.camel
+artifactId=camel-aws-common
+version=4.17.0-SNAPSHOT
+projectName=Camel :: AWS :: Common
+projectDescription=Camel AWS Common utilities for client initialization
diff --git
a/components/camel-aws/camel-aws-common/src/generated/resources/aws-common.json
b/components/camel-aws/camel-aws-common/src/generated/resources/aws-common.json
new file mode 100644
index 000000000000..5355c49bf792
--- /dev/null
+++
b/components/camel-aws/camel-aws-common/src/generated/resources/aws-common.json
@@ -0,0 +1,15 @@
+{
+ "other": {
+ "kind": "other",
+ "name": "aws-common",
+ "title": "Aws Common",
+ "description": "Camel AWS Common utilities for client initialization",
+ "deprecated": false,
+ "firstVersion": "4.17.0",
+ "label": "cloud,aws",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-aws-common",
+ "version": "4.17.0-SNAPSHOT"
+ }
+}
diff --git
a/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsClientBuilderUtil.java
b/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsClientBuilderUtil.java
new file mode 100644
index 000000000000..00858a7ae496
--- /dev/null
+++
b/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsClientBuilderUtil.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.common;
+
+import java.net.URI;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
+import software.amazon.awssdk.core.SdkClient;
+import software.amazon.awssdk.core.client.builder.SdkSyncClientBuilder;
+import software.amazon.awssdk.http.SdkHttpClient;
+import software.amazon.awssdk.http.SdkHttpConfigurationOption;
+import software.amazon.awssdk.http.apache.ApacheHttpClient;
+import software.amazon.awssdk.http.apache.ProxyConfiguration;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.utils.AttributeMap;
+
+/**
+ * Utility class for building AWS SDK clients with common configuration.
+ * <p>
+ * This class eliminates code duplication across all AWS Camel components by
providing a centralized way to configure
+ * AWS clients with credentials, proxy, region, endpoint, and other common
settings.
+ * </p>
+ */
+public final class AwsClientBuilderUtil {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(AwsClientBuilderUtil.class);
+
+ private AwsClientBuilderUtil() {
+ }
+
+ /**
+ * Build an AWS client with the given configuration.
+ *
+ * @param config The common AWS configuration
+ * @param builderSupplier Supplier for the service-specific client
builder (e.g., S3Client::builder)
+ * @param serviceSpecificConfig Optional consumer for service-specific
configuration (e.g., S3's forcePathStyle)
+ * @param <B> The builder type (must extend both
AwsClientBuilder and SdkSyncClientBuilder)
+ * @param <C> The client type
+ * @return The configured AWS client
+ */
+ @SuppressWarnings("unchecked")
+ public static <B extends AwsClientBuilder<B, C> & SdkSyncClientBuilder<B,
C>, C extends SdkClient> C buildClient(
+ AwsCommonConfiguration config,
+ Supplier<B> builderSupplier,
+ Consumer<B> serviceSpecificConfig) {
+
+ B clientBuilder = builderSupplier.get();
+ ApacheHttpClient.Builder httpClientBuilder = null;
+ boolean httpClientConfigured = false;
+
+ // 1. Configure proxy
+ if (ObjectHelper.isNotEmpty(config.getProxyHost())
+ && ObjectHelper.isNotEmpty(config.getProxyPort())) {
+ LOG.trace("Configuring proxy: {}:{}", config.getProxyHost(),
config.getProxyPort());
+ URI proxyEndpoint = URI.create(
+ config.getProxyProtocol() + "://" + config.getProxyHost()
+ ":" + config.getProxyPort());
+ ProxyConfiguration proxyConfig = ProxyConfiguration.builder()
+ .endpoint(proxyEndpoint)
+ .build();
+ httpClientBuilder =
ApacheHttpClient.builder().proxyConfiguration(proxyConfig);
+ httpClientConfigured = true;
+ }
+
+ // 2. Configure credentials
+ AwsCredentialsProvider credentialsProvider =
resolveCredentialsProvider(config);
+ if (credentialsProvider != null) {
+ clientBuilder.credentialsProvider(credentialsProvider);
+ }
+
+ // 3. Apply HTTP client builder if configured (before trust all certs
check)
+ if (httpClientConfigured) {
+ clientBuilder.httpClientBuilder(httpClientBuilder);
+ }
+
+ // 4. Configure region
+ if (ObjectHelper.isNotEmpty(config.getRegion())) {
+ clientBuilder.region(Region.of(config.getRegion()));
+ }
+
+ // 5. Configure endpoint override
+ if (config.isOverrideEndpoint() &&
ObjectHelper.isNotEmpty(config.getUriEndpointOverride())) {
+
clientBuilder.endpointOverride(URI.create(config.getUriEndpointOverride()));
+ }
+
+ // 6. Configure trust all certificates
+ if (config.isTrustAllCertificates()) {
+ if (httpClientBuilder == null) {
+ httpClientBuilder = ApacheHttpClient.builder();
+ }
+ SdkHttpClient httpClient = httpClientBuilder.buildWithDefaults(
+ AttributeMap.builder()
+
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, Boolean.TRUE)
+ .build());
+ clientBuilder.httpClient(httpClient);
+ clientBuilder.httpClientBuilder(null);
+ }
+
+ // 7. Apply service-specific configuration
+ if (serviceSpecificConfig != null) {
+ serviceSpecificConfig.accept(clientBuilder);
+ }
+
+ return clientBuilder.build();
+ }
+
+ /**
+ * Build an AWS client with the given configuration, without
service-specific configuration.
+ *
+ * @param config The common AWS configuration
+ * @param builderSupplier Supplier for the service-specific client builder
+ * @param <B> The builder type
+ * @param <C> The client type
+ * @return The configured AWS client
+ */
+ public static <B extends AwsClientBuilder<B, C> & SdkSyncClientBuilder<B,
C>, C extends SdkClient> C buildClient(
+ AwsCommonConfiguration config,
+ Supplier<B> builderSupplier) {
+ return buildClient(config, builderSupplier, null);
+ }
+
+ /**
+ * Resolve the appropriate credentials provider based on configuration.
+ * <p>
+ * The priority order is:
+ * <ol>
+ * <li>Default credentials provider (IAM roles, environment variables,
etc.)</li>
+ * <li>Profile credentials provider</li>
+ * <li>Session credentials (temporary credentials with session token)</li>
+ * <li>Static credentials (access key + secret key)</li>
+ * </ol>
+ * </p>
+ *
+ * @param config The AWS configuration
+ * @return The resolved credentials provider, or null to use SDK
default chain
+ */
+ private static AwsCredentialsProvider
resolveCredentialsProvider(AwsCommonConfiguration config) {
+
+ // Priority 1: Default credentials provider (IAM roles, env vars, etc.)
+ if (Boolean.TRUE.equals(config.isUseDefaultCredentialsProvider())) {
+ LOG.trace("Using default credentials provider (IAM)");
+ return DefaultCredentialsProvider.create();
+ }
+
+ // Priority 2: Profile credentials provider
+ if (config.isUseProfileCredentialsProvider()) {
+ String profileName = config.getProfileCredentialsName();
+ LOG.trace("Using profile credentials provider: {}", profileName);
+ if (ObjectHelper.isNotEmpty(profileName)) {
+ return ProfileCredentialsProvider.create(profileName);
+ }
+ return ProfileCredentialsProvider.create();
+ }
+
+ // Priority 3: Session credentials (temporary credentials with session
token)
+ if (config.isUseSessionCredentials()) {
+ if (ObjectHelper.isNotEmpty(config.getAccessKey())
+ && ObjectHelper.isNotEmpty(config.getSecretKey())
+ && ObjectHelper.isNotEmpty(config.getSessionToken())) {
+ LOG.trace("Using session credentials");
+ AwsSessionCredentials sessionCredentials =
AwsSessionCredentials.create(
+ config.getAccessKey(),
+ config.getSecretKey(),
+ config.getSessionToken());
+ return StaticCredentialsProvider.create(sessionCredentials);
+ }
+ }
+
+ // Priority 4: Static credentials (access key + secret key)
+ if (ObjectHelper.isNotEmpty(config.getAccessKey())
+ && ObjectHelper.isNotEmpty(config.getSecretKey())) {
+ LOG.trace("Using static credentials");
+ AwsBasicCredentials basicCredentials = AwsBasicCredentials.create(
+ config.getAccessKey(),
+ config.getSecretKey());
+ return StaticCredentialsProvider.create(basicCredentials);
+ }
+
+ // No explicit credentials - let SDK use its default chain
+ LOG.trace("No explicit credentials configured, using SDK default
chain");
+ return null;
+ }
+}
diff --git
a/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsCommonConfiguration.java
b/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsCommonConfiguration.java
new file mode 100644
index 000000000000..61295244a9db
--- /dev/null
+++
b/components/camel-aws/camel-aws-common/src/main/java/org/apache/camel/component/aws/common/AwsCommonConfiguration.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.common;
+
+import software.amazon.awssdk.core.Protocol;
+
+/**
+ * Common configuration interface for all AWS components.
+ * <p>
+ * Each AWS component's Configuration class should implement this interface to
enable use of the common
+ * {@link AwsClientBuilderUtil} for client creation.
+ * </p>
+ */
+public interface AwsCommonConfiguration {
+
+ // ==================== Credentials - Static ====================
+
+ /**
+ * Amazon AWS Access Key.
+ */
+ String getAccessKey();
+
+ /**
+ * Amazon AWS Secret Key.
+ */
+ String getSecretKey();
+
+ /**
+ * Amazon AWS Session Token used when the user needs to assume an IAM role.
+ */
+ String getSessionToken();
+
+ // ==================== Credentials - Provider Selection
====================
+
+ /**
+ * Set whether the client should expect to load credentials through a
default credentials provider.
+ */
+ Boolean isUseDefaultCredentialsProvider();
+
+ /**
+ * Set whether the client should expect to load credentials through a
profile credentials provider.
+ */
+ boolean isUseProfileCredentialsProvider();
+
+ /**
+ * Set whether the client should expect to use Session Credentials. This
is useful in a situation in which the user
+ * needs to assume an IAM role.
+ */
+ boolean isUseSessionCredentials();
+
+ /**
+ * If using a profile credentials provider, this parameter specifies the
profile name.
+ */
+ String getProfileCredentialsName();
+
+ // ==================== Proxy Configuration ====================
+
+ /**
+ * To define a proxy protocol when instantiating the client.
+ */
+ Protocol getProxyProtocol();
+
+ /**
+ * To define a proxy host when instantiating the client.
+ */
+ String getProxyHost();
+
+ /**
+ * Specify a proxy port to be used inside the client definition.
+ */
+ Integer getProxyPort();
+
+ // ==================== Region and Endpoint ====================
+
+ /**
+ * The region in which the client needs to work. When using this
parameter, the configuration will expect the
+ * lowercase name of the region (for example, ap-east-1).
+ */
+ String getRegion();
+
+ /**
+ * Set the need for overriding the endpoint. This option needs to be used
in combination with the
+ * uriEndpointOverride option.
+ */
+ boolean isOverrideEndpoint();
+
+ /**
+ * Set the overriding URI endpoint. This option needs to be used in
combination with overrideEndpoint option.
+ */
+ String getUriEndpointOverride();
+
+ // ==================== Security ====================
+
+ /**
+ * If we want to trust all certificates in case of overriding the endpoint.
+ */
+ boolean isTrustAllCertificates();
+}
diff --git a/components/camel-aws/camel-aws2-s3/pom.xml
b/components/camel-aws/camel-aws2-s3/pom.xml
index 12364fdd7f6e..86a575c8857b 100644
--- a/components/camel-aws/camel-aws2-s3/pom.xml
+++ b/components/camel-aws/camel-aws2-s3/pom.xml
@@ -36,6 +36,10 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-aws-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Configuration.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Configuration.java
index 86a2adfa2753..039572e79f9f 100644
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Configuration.java
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Configuration.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws2.s3;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.component.aws2.s3.stream.AWSS3NamingStrategyEnum;
import org.apache.camel.component.aws2.s3.stream.AWSS3RestartingPolicyEnum;
import org.apache.camel.spi.Metadata;
@@ -28,7 +29,7 @@ import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
@UriParams
-public class AWS2S3Configuration implements Cloneable {
+public class AWS2S3Configuration implements Cloneable, AwsCommonConfiguration {
private String bucketName;
@UriParam(label = "advanced")
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
index 06c174ed3782..614d1143ea95 100644
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
@@ -132,7 +132,7 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint
implements EndpointSer
super.doStart();
s3Client = configuration.getAmazonS3Client() != null
- ? configuration.getAmazonS3Client() :
AWS2S3ClientFactory.getAWSS3Client(configuration).getS3Client();
+ ? configuration.getAmazonS3Client() :
AWS2S3ClientFactory.getS3Client(configuration);
String fileName = getConfiguration().getFileName();
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2CamelS3InternalClient.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2CamelS3InternalClient.java
deleted file mode 100644
index 3c45ce9dca3d..000000000000
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2CamelS3InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.s3.client;
-
-import software.amazon.awssdk.services.s3.S3Client;
-
-/**
- * Manage the required actions of an s3 client for either local or remote.
- */
-public interface AWS2CamelS3InternalClient {
-
- /**
- * Returns an s3 client after a factory method determines which one to
return.
- *
- * @return AmazonS3 AmazonS3
- */
- S3Client getS3Client();
-}
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2S3ClientFactory.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2S3ClientFactory.java
index 80c48033d0c3..a1e638cea303 100644
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2S3ClientFactory.java
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/AWS2S3ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.s3.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientIAMOptimizedImpl;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientIAMProfileOptimizedImpl;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientStandardImpl;
+import software.amazon.awssdk.services.s3.S3Client;
/**
- * Factory class to return the correct type of AWS S3 aws.
+ * Factory class to create AWS S3 clients using common configuration.
*/
public final class AWS2S3ClientFactory {
@@ -31,20 +29,20 @@ public final class AWS2S3ClientFactory {
}
/**
- * Return the correct aws s3 client (based on remote vs local).
+ * Create an S3 client based on configuration.
*
- * @param configuration configuration
- * @return AWSS3Client
+ * @param configuration The S3 configuration
+ * @return Configured S3Client
*/
- public static AWS2CamelS3InternalClient getAWSS3Client(AWS2S3Configuration
configuration) {
- if
(Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new AWS2S3ClientIAMOptimizedImpl(configuration);
- } else if
(Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new AWS2S3ClientIAMProfileOptimizedImpl(configuration);
- } else if
(Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new AWS2S3ClientSessionTokenImpl(configuration);
- } else {
- return new AWS2S3ClientStandardImpl(configuration);
- }
+ public static S3Client getS3Client(AWS2S3Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ S3Client::builder,
+ builder -> {
+ // S3-specific configuration
+ if (configuration.isForcePathStyle()) {
+ builder.forcePathStyle(true);
+ }
+ });
}
}
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMOptimizedImpl.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMOptimizedImpl.java
deleted file mode 100644
index fa3b4b68fb7a..000000000000
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.s3.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
-import org.apache.camel.component.aws2.s3.client.AWS2CamelS3InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.S3ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS s3 client for all users to use (enabling temporary creds).
This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class AWS2S3ClientIAMOptimizedImpl implements AWS2CamelS3InternalClient
{
- private static final Logger LOG =
LoggerFactory.getLogger(AWS2S3ClientIAMOptimizedImpl.class);
- private AWS2S3Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2S3ClientIAMOptimizedImpl(AWS2S3Configuration configuration) {
- LOG.trace("Creating an AWS S3 client for an ec2 instance with IAM
temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the s3 aws client that is used.
- *
- * @return Amazon S3 Client.
- */
- @Override
- public S3Client getS3Client() {
- S3Client client = null;
- S3ClientBuilder clientBuilder = S3Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) &&
ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- proxyConfig = ProxyConfiguration.builder();
- URI proxyEndpoint = URI.create(configuration.getProxyProtocol() +
"://" + configuration.getProxyHost() + ":"
- + configuration.getProxyPort());
- proxyConfig.endpoint(proxyEndpoint);
- httpClientBuilder =
ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder =
clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
-
clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isForcePathStyle()) {
- clientBuilder.forcePathStyle(true);
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc =
httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMProfileOptimizedImpl.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index 5047471c8b7b..000000000000
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.s3.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
-import org.apache.camel.component.aws2.s3.client.AWS2CamelS3InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.S3ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS s3 client for all users to use. This implementation is for
local instances to use a static and solid
- * credential set.
- */
-public class AWS2S3ClientIAMProfileOptimizedImpl implements
AWS2CamelS3InternalClient {
- private static final Logger LOG =
LoggerFactory.getLogger(AWS2S3ClientIAMProfileOptimizedImpl.class);
- private AWS2S3Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2S3ClientIAMProfileOptimizedImpl(AWS2S3Configuration
configuration) {
- LOG.trace("Creating an AWS S3 manager using profile credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the s3 aws client that is used.
- *
- * @return Amazon S3 Client.
- */
- @Override
- public S3Client getS3Client() {
- S3Client client = null;
- S3ClientBuilder clientBuilder = S3Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- boolean isClientConfigFound = false;
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) &&
ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- proxyConfig = ProxyConfiguration.builder();
- URI proxyEndpoint = URI.create(configuration.getProxyProtocol() +
"://" + configuration.getProxyHost() + ":"
- + configuration.getProxyPort());
- proxyConfig.endpoint(proxyEndpoint);
- httpClientBuilder =
ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
- isClientConfigFound = true;
- }
- if (configuration.getProfileCredentialsName() != null) {
- if (isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder)
-
.credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- } else {
- clientBuilder = clientBuilder
-
.credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- } else {
- if (!isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder =
clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
-
clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isForcePathStyle()) {
- clientBuilder.forcePathStyle(true);
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc =
httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientSessionTokenImpl.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientSessionTokenImpl.java
deleted file mode 100644
index 610231ef48ce..000000000000
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.s3.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
-import org.apache.camel.component.aws2.s3.client.AWS2CamelS3InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.S3ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS s3 client for all users to use. This implementation is for
local instances to use a static and solid
- * credential set.
- */
-public class AWS2S3ClientSessionTokenImpl implements AWS2CamelS3InternalClient
{
- private static final Logger LOG =
LoggerFactory.getLogger(AWS2S3ClientSessionTokenImpl.class);
- private AWS2S3Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2S3ClientSessionTokenImpl(AWS2S3Configuration configuration) {
- LOG.trace("Creating an AWS S3 manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the s3 aws client that is used.
- *
- * @return Amazon S3 Client.
- */
- @Override
- public S3Client getS3Client() {
- S3Client client = null;
- S3ClientBuilder clientBuilder = S3Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- boolean isClientConfigFound = false;
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) &&
ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- proxyConfig = ProxyConfiguration.builder();
- URI proxyEndpoint = URI.create(configuration.getProxyProtocol() +
"://" + configuration.getProxyHost() + ":"
- + configuration.getProxyPort());
- proxyConfig.endpoint(proxyEndpoint);
- httpClientBuilder =
ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
- isClientConfigFound = true;
- }
- if (configuration.getAccessKey() != null &&
configuration.getSecretKey() != null
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred =
AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(),
configuration.getSessionToken());
- if (isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder)
-
.credentialsProvider(StaticCredentialsProvider.create(cred));
- } else {
- clientBuilder =
clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
- }
- } else {
- if (!isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder =
clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
-
clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isForcePathStyle()) {
- clientBuilder.forcePathStyle(true);
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc =
httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientStandardImpl.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientStandardImpl.java
deleted file mode 100644
index 0b84db11c993..000000000000
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/client/impl/AWS2S3ClientStandardImpl.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.s3.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
-import org.apache.camel.component.aws2.s3.client.AWS2CamelS3InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.S3ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS s3 client for all users to use. This implementation is for
local instances to use a static and solid
- * credential set.
- */
-public class AWS2S3ClientStandardImpl implements AWS2CamelS3InternalClient {
- private static final Logger LOG =
LoggerFactory.getLogger(AWS2S3ClientStandardImpl.class);
- private AWS2S3Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2S3ClientStandardImpl(AWS2S3Configuration configuration) {
- LOG.trace("Creating an AWS S3 manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the s3 aws client that is used.
- *
- * @return Amazon S3 Client.
- */
- @Override
- public S3Client getS3Client() {
- S3Client client = null;
- S3ClientBuilder clientBuilder = S3Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- boolean isClientConfigFound = false;
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) &&
ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- proxyConfig = ProxyConfiguration.builder();
- URI proxyEndpoint = URI.create(configuration.getProxyProtocol() +
"://" + configuration.getProxyHost() + ":"
- + configuration.getProxyPort());
- proxyConfig.endpoint(proxyEndpoint);
- httpClientBuilder =
ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
- isClientConfigFound = true;
- }
- if (configuration.getAccessKey() != null &&
configuration.getSecretKey() != null) {
- AwsBasicCredentials cred =
AwsBasicCredentials.create(configuration.getAccessKey(),
configuration.getSecretKey());
- if (isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder)
-
.credentialsProvider(StaticCredentialsProvider.create(cred));
- } else {
- clientBuilder =
clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
- }
- } else {
- if (!isClientConfigFound) {
- clientBuilder =
clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder =
clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
-
clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isForcePathStyle()) {
- clientBuilder.forcePathStyle(true);
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc =
httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git
a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWSS3ClientFactoryTest.java
b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWSS3ClientFactoryTest.java
index 7a35a0282a78..c691286f7774 100644
---
a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWSS3ClientFactoryTest.java
+++
b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWSS3ClientFactoryTest.java
@@ -16,54 +16,55 @@
*/
package org.apache.camel.component.aws2.s3;
-import org.apache.camel.component.aws2.s3.client.AWS2CamelS3InternalClient;
import org.apache.camel.component.aws2.s3.client.AWS2S3ClientFactory;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientIAMOptimizedImpl;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientIAMProfileOptimizedImpl;
-import
org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.s3.client.impl.AWS2S3ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.s3.S3Client;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class AWSS3ClientFactoryTest {
@Test
- public void getStandardS3ClientDefault() {
+ public void getS3ClientWithDefaultCredentials() {
AWS2S3Configuration s3Configuration = new AWS2S3Configuration();
- AWS2CamelS3InternalClient awss3Client =
AWS2S3ClientFactory.getAWSS3Client(s3Configuration);
- assertTrue(awss3Client instanceof AWS2S3ClientStandardImpl);
+ s3Configuration.setUseDefaultCredentialsProvider(true);
+ s3Configuration.setRegion("eu-west-1");
+ S3Client s3Client = AWS2S3ClientFactory.getS3Client(s3Configuration);
+ assertNotNull(s3Client);
+ s3Client.close();
}
@Test
- public void getStandardS3Client() {
+ public void getS3ClientWithStaticCredentials() {
AWS2S3Configuration s3Configuration = new AWS2S3Configuration();
- s3Configuration.setUseDefaultCredentialsProvider(false);
- AWS2CamelS3InternalClient awss3Client =
AWS2S3ClientFactory.getAWSS3Client(s3Configuration);
- assertTrue(awss3Client instanceof AWS2S3ClientStandardImpl);
+ s3Configuration.setAccessKey("testAccessKey");
+ s3Configuration.setSecretKey("testSecretKey");
+ s3Configuration.setRegion("eu-west-1");
+ S3Client s3Client = AWS2S3ClientFactory.getS3Client(s3Configuration);
+ assertNotNull(s3Client);
+ s3Client.close();
}
@Test
- public void getIAMOptimizedS3Client() {
+ public void getS3ClientWithForcePathStyle() {
AWS2S3Configuration s3Configuration = new AWS2S3Configuration();
s3Configuration.setUseDefaultCredentialsProvider(true);
- AWS2CamelS3InternalClient awss3Client =
AWS2S3ClientFactory.getAWSS3Client(s3Configuration);
- assertTrue(awss3Client instanceof AWS2S3ClientIAMOptimizedImpl);
- }
-
- @Test
- public void getIAMProfileOptimizedS3Client() {
- AWS2S3Configuration s3Configuration = new AWS2S3Configuration();
- s3Configuration.setUseProfileCredentialsProvider(true);
- AWS2CamelS3InternalClient awss3Client =
AWS2S3ClientFactory.getAWSS3Client(s3Configuration);
- assertTrue(awss3Client instanceof AWS2S3ClientIAMProfileOptimizedImpl);
+ s3Configuration.setRegion("eu-west-1");
+ s3Configuration.setForcePathStyle(true);
+ S3Client s3Client = AWS2S3ClientFactory.getS3Client(s3Configuration);
+ assertNotNull(s3Client);
+ s3Client.close();
}
@Test
- public void getSessionTokenS3Client() {
+ public void getS3ClientWithEndpointOverride() {
AWS2S3Configuration s3Configuration = new AWS2S3Configuration();
- s3Configuration.setUseSessionCredentials(true);
- AWS2CamelS3InternalClient awss3Client =
AWS2S3ClientFactory.getAWSS3Client(s3Configuration);
- assertTrue(awss3Client instanceof AWS2S3ClientSessionTokenImpl);
+ s3Configuration.setUseDefaultCredentialsProvider(true);
+ s3Configuration.setRegion("eu-west-1");
+ s3Configuration.setOverrideEndpoint(true);
+ s3Configuration.setUriEndpointOverride("http://localhost:4566");
+ S3Client s3Client = AWS2S3ClientFactory.getS3Client(s3Configuration);
+ assertNotNull(s3Client);
+ s3Client.close();
}
}
diff --git a/components/camel-aws/pom.xml b/components/camel-aws/pom.xml
index 98fabd1b3a6d..78d66f363967 100644
--- a/components/camel-aws/pom.xml
+++ b/components/camel-aws/pom.xml
@@ -39,6 +39,7 @@
</properties>
<modules>
+ <module>camel-aws-common</module>
<module>camel-aws2-athena</module>
<module>camel-aws-bedrock</module>
<module>camel-aws-cloudtrail</module>
diff --git a/docs/components/modules/others/examples/json/aws-common.json
b/docs/components/modules/others/examples/json/aws-common.json
new file mode 120000
index 000000000000..5597b0618d3b
--- /dev/null
+++ b/docs/components/modules/others/examples/json/aws-common.json
@@ -0,0 +1 @@
+../../../../../../components/camel-aws/camel-aws-common/src/generated/resources/aws-common.json
\ No newline at end of file
diff --git a/parent/pom.xml b/parent/pom.xml
index b794e5f8dc67..927554a9f759 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -808,6 +808,11 @@
<artifactId>camel-aws-cloudtrail</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-aws-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws-config</artifactId>
diff --git
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
index f0c37ff217a9..d80e467c58b3 100644
---
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
+++
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
@@ -924,6 +924,7 @@ public class PrepareCatalogMojo extends AbstractMojo {
case "camel-as2":
case "camel-avro-rpc":
case "camel-aws":
+ case "camel-aws-common":
case "camel-azure":
case "camel-box":
case "camel-cxf":