You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/03/10 14:10:26 UTC

[camel] 01/03: CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, S3 component

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 85b7f35963914f36a63e6419ef3eccbf3b6db56e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 10 15:04:33 2020 +0100

    CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, S3 component
---
 .../camel/component/aws2/s3/AWS2S3Component.java   | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Component.java b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Component.java
index 87fb256..0f15d3b 100644
--- a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Component.java
+++ b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Component.java
@@ -24,10 +24,16 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import software.amazon.awssdk.services.s3.S3Client;
 
 @Component("aws2-s3")
 public class AWS2S3Component extends DefaultComponent {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(AWS2S3Component.class);
 
     @Metadata
     private AWS2S3Configuration configuration = new AWS2S3Configuration();
@@ -55,7 +61,7 @@ public class AWS2S3Component extends DefaultComponent {
         configuration.setBucketName(remaining);
         AWS2S3Endpoint endpoint = new AWS2S3Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (!configuration.isUseIAMCredentials() && configuration.getAmazonS3Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("useIAMCredentials is set to false, AmazonS3Client or accessKey and secretKey must be specified");
         }
@@ -74,10 +80,18 @@ public class AWS2S3Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(AWS2S3Configuration configuration) {
-        Set<S3Client> clients = getCamelContext().getRegistry().findByType(S3Client.class);
-        if (clients.size() == 1) {
-            configuration.setAmazonS3Client(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(AWS2S3Configuration configuration, AWS2S3Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonS3Client())) {
+            LOG.debug("Looking for an S3Client instance in the registry");
+            Set<S3Client> clients = getCamelContext().getRegistry().findByType(S3Client.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one S3Client instance in the registry");
+                configuration.setAmazonS3Client(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No S3Client instance in the registry");
+            }
+        } else {
+            LOG.debug("S3Client instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }