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 2019/12/11 12:49:11 UTC

[camel] 01/02: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-mq

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 54a694e4522772d9d3ca5ad568bbec8ab4b9251e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 13:42:20 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-mq
---
 .../apache/camel/component/aws/mq/MQComponent.java | 33 ++++++++--------------
 .../aws/mq/MQComponentClientRegistryTest.java      |  4 +--
 .../aws/mq/MQComponentConfigurationTest.java       |  6 ++--
 3 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java
index 868806e..a6b07d8 100644
--- a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java
+++ b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java
@@ -25,7 +25,6 @@ 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;
 
 /**
  * For working with Amazon MQ.
@@ -49,30 +48,22 @@ public class MQComponent extends DefaultComponent {
     public MQComponent(CamelContext context) {
         super(context);
         
-        this.configuration = new MQConfiguration();
         registerExtension(new MQComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        MQConfiguration configuration = this.configuration.copy();
-        setProperties(configuration, parameters);
-
-        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
-            setAccessKey(accessKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
-            setSecretKey(secretKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getRegion())) {
-            setRegion(region);
-        }
+        MQConfiguration configuration = this.configuration != null ? this.configuration.copy() : new MQConfiguration();
+        MQEndpoint endpoint = new MQEndpoint(uri, this, configuration);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
         if (configuration.getAmazonMqClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonMQClient or accessKey and secretKey must be specified");
         }
         
-        MQEndpoint endpoint = new MQEndpoint(uri, this, configuration);
         return endpoint;
     }
     
@@ -88,36 +79,36 @@ public class MQComponent extends DefaultComponent {
     }
 
     public String getAccessKey() {
-        return configuration.getAccessKey();
+        return accessKey;
     }
 
     /**
      * Amazon AWS Access Key
      */
     public void setAccessKey(String accessKey) {
-        configuration.setAccessKey(accessKey);
+        this.accessKey = accessKey;
     }
 
     public String getSecretKey() {
-        return configuration.getSecretKey();
+        return secretKey;
     }
 
     /**
      * Amazon AWS Secret Key
      */
     public void setSecretKey(String secretKey) {
-        configuration.setSecretKey(secretKey);
+        this.secretKey = secretKey;
     }
     
     public String getRegion() {
-        return configuration.getRegion();
+        return region;
     }
 
     /**
      * The region in which MQ client needs to work
      */
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
 
     private void checkAndSetRegistryClient(MQConfiguration configuration) {
diff --git a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java
index 9734e8b..80fcafd 100644
--- a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java
+++ b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java
@@ -26,7 +26,7 @@ public class MQComponentClientRegistryTest extends CamelTestSupport {
 
         AmazonMQClientMock awsMQClient = new AmazonMQClientMock();
         context.getRegistry().bind("awsMQClient", awsMQClient);
-        MQComponent component = new MQComponent(context);
+        MQComponent component = context.getComponent("aws-mq", MQComponent.class);
         MQEndpoint endpoint = (MQEndpoint) component.createEndpoint("aws-mq://MyQueue");
 
         assertNotNull(endpoint.getConfiguration().getAmazonMqClient());
@@ -35,7 +35,7 @@ public class MQComponentClientRegistryTest extends CamelTestSupport {
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithMinimalMQClientMisconfiguration() throws Exception {
 
-        MQComponent component = new MQComponent(context);
+        MQComponent component = context.getComponent("aws-mq", MQComponent.class);
         MQEndpoint endpoint = (MQEndpoint) component.createEndpoint("aws-mq://MyQueue");
     }
 }
diff --git a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentConfigurationTest.java b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentConfigurationTest.java
index 0617832..5f4560f 100644
--- a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentConfigurationTest.java
+++ b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentConfigurationTest.java
@@ -26,7 +26,7 @@ public class MQComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        MQComponent component = new MQComponent(context);
+        MQComponent component = context.getComponent("aws-mq", MQComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         MQEndpoint endpoint = (MQEndpoint)component.createEndpoint("aws-mq://MyQueue");
@@ -37,7 +37,7 @@ public class MQComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        MQComponent component = new MQComponent(context);
+        MQComponent component = context.getComponent("aws-mq", MQComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -50,7 +50,7 @@ public class MQComponentConfigurationTest extends CamelTestSupport {
 
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        MQComponent component = new MQComponent(context);
+        MQComponent component = context.getComponent("aws-mq", MQComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());