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/11/17 14:23:03 UTC

[camel] 04/07: CAMEL-15836 - Camel-AWS2-SES: enable autowire on the SES Client, fixed tests

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 933c06c80013e564d78eca7cffa922b75c39cbfe
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Nov 17 15:17:34 2020 +0100

    CAMEL-15836 - Camel-AWS2-SES: enable autowire on the SES Client, fixed tests
---
 .../apache/camel/component/aws2/ses/Ses2Component.java | 18 ++++++++++++++++++
 .../aws2/ses/SESComponentClientRegistryTest.java       |  4 +---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java
index a6fcc48..e7ce05b 100644
--- a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java
+++ b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java
@@ -17,14 +17,17 @@
 package org.apache.camel.component.aws2.ses;
 
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.camel.CamelContext;
 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.ses.SesClient;
 
 /**
  * For working with Amazon ECS SDK v2.
@@ -75,4 +78,19 @@ public class Ses2Component extends DefaultComponent {
     public void setConfiguration(Ses2Configuration configuration) {
         this.configuration = configuration;
     }
+
+    private void checkAndSetRegistryClient(Ses2Configuration configuration, Ses2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonSESClient())) {
+            LOG.debug("Looking for an SesClient instance in the registry");
+            Set<SesClient> clients = getCamelContext().getRegistry().findByType(SesClient.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one SesClient instance in the registry");
+                configuration.setAmazonSESClient(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No SesClient instance in the registry");
+            }
+        } else {
+            LOG.debug("SesClient instance is already set at endpoint level: skipping the check in the registry");
+        }
+    }
 }
diff --git a/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java b/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java
index 5b9fb37f..0e64724 100644
--- a/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java
+++ b/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java
@@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SESComponentClientRegistryTest extends CamelTestSupport {
 
@@ -31,10 +30,9 @@ public class SESComponentClientRegistryTest extends CamelTestSupport {
         AmazonSESClientMock awsSESClient = new AmazonSESClientMock();
         context.getRegistry().bind("awsSesClient", awsSESClient);
         Ses2Component component = new Ses2Component(context);
-        Ses2Endpoint endpoint = (Ses2Endpoint) component.createEndpoint("aws2-ses://from@example.com");
+        Ses2Endpoint endpoint = (Ses2Endpoint) component.createEndpoint("aws2-ses://from@example.com?accessKey=xxx&secretKey=yyy");
 
         assertNotNull(endpoint.getConfiguration().getAmazonSESClient());
-        component.close();
     }
 
     @Test