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:12 UTC

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

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 b8bf160f909dbd2f955dc117cc5ffe517e6c3492
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 13:47:31 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-msk
---
 .../camel/component/aws/msk/MSKComponent.java      | 34 ++++++++--------------
 .../aws/msk/MSKComponentClientRegistryTest.java    |  4 +--
 .../aws/msk/MSKComponentConfigurationTest.java     |  6 ++--
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java
index a220477..a5b4285 100644
--- a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java
+++ b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.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 MSK.
@@ -49,30 +48,21 @@ public class MSKComponent extends DefaultComponent {
     public MSKComponent(CamelContext context) {
         super(context);
         
-        this.configuration = new MSKConfiguration();
         registerExtension(new MSKComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        MSKConfiguration 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);
-        }
+        MSKConfiguration configuration = this.configuration != null ? this.configuration.copy() : new MSKConfiguration();
+        MSKEndpoint endpoint = new MSKEndpoint(uri, this, configuration);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
         if (configuration.getMskClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("Amazon msk client or accessKey and secretKey must be specified");
         }
-        
-        MSKEndpoint endpoint = new MSKEndpoint(uri, this, configuration);
         return endpoint;
     }
     
@@ -88,36 +78,36 @@ public class MSKComponent 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 MSK client needs to work
      */
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
 
     private void checkAndSetRegistryClient(MSKConfiguration configuration) {
diff --git a/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java
index 85f04a8..c94a568 100644
--- a/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java
+++ b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java
@@ -26,7 +26,7 @@ public class MSKComponentClientRegistryTest extends CamelTestSupport {
 
         AmazonMSKClientMock awsMSKClient = new AmazonMSKClientMock();
         context.getRegistry().bind("awsMskClient", awsMSKClient);
-        MSKComponent component = new MSKComponent(context);
+        MSKComponent component = context.getComponent("aws-msk", MSKComponent.class);
         MSKEndpoint endpoint = (MSKEndpoint) component.createEndpoint("aws-msk://label");
 
         assertNotNull(endpoint.getConfiguration().getMskClient());
@@ -35,7 +35,7 @@ public class MSKComponentClientRegistryTest extends CamelTestSupport {
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithMinimalMSKClientMisconfiguration() throws Exception {
 
-        MSKComponent component = new MSKComponent(context);
+        MSKComponent component = context.getComponent("aws-msk", MSKComponent.class);
         MSKEndpoint endpoint = (MSKEndpoint) component.createEndpoint("aws-msk://label");
     }
 }
diff --git a/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentConfigurationTest.java b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentConfigurationTest.java
index 1e06de3..9f68f72 100644
--- a/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentConfigurationTest.java
+++ b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentConfigurationTest.java
@@ -25,7 +25,7 @@ public class MSKComponentConfigurationTest extends CamelTestSupport {
 
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        MSKComponent component = new MSKComponent(context);
+        MSKComponent component = context.getComponent("aws-msk", MSKComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         MSKEndpoint endpoint = (MSKEndpoint)component.createEndpoint("aws-msk://label");
@@ -36,7 +36,7 @@ public class MSKComponentConfigurationTest extends CamelTestSupport {
 
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        MSKComponent component = new MSKComponent(context);
+        MSKComponent component = context.getComponent("aws-msk", MSKComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -49,7 +49,7 @@ public class MSKComponentConfigurationTest extends CamelTestSupport {
 
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        MSKComponent component = new MSKComponent(context);
+        MSKComponent component = context.getComponent("aws-msk", MSKComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());