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 10:35:55 UTC

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

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 7b86d977b449d963f663c78a6606779adc4c0114
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 11:34:56 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ddbstreams
---
 .../aws/ddbstream/DdbStreamComponent.java          | 35 ++++++++--------------
 .../DdbStreamComponentConfigurationTest.java       | 11 ++++---
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java
index 39ac7c5..a60ba39 100644
--- a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java
+++ b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.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;
 
 @Component("aws-ddbstream")
 public class DdbStreamComponent extends DefaultComponent {
@@ -46,36 +45,26 @@ public class DdbStreamComponent extends DefaultComponent {
     public DdbStreamComponent(CamelContext context) {
         super(context);
         
-        this.configuration = new DdbStreamConfiguration();
         registerExtension(new DdbStreamComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        DdbStreamConfiguration configuration = this.configuration.copy();
-        configuration.setTableName(remaining);
-        setProperties(configuration, parameters);
         
         if (remaining == null || remaining.trim().length() == 0) {
             throw new IllegalArgumentException("Table name must be specified.");
         }
+        DdbStreamConfiguration configuration = this.configuration != null ? this.configuration.copy() : new DdbStreamConfiguration();
         configuration.setTableName(remaining);
-        
-        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
-            setAccessKey(accessKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
-            setSecretKey(secretKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getRegion())) {
-            setRegion(region);
-        }
+        DdbStreamEndpoint endpoint = new DdbStreamEndpoint(uri, configuration, this);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
         if (configuration.getAmazonDynamoDbStreamsClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonDDBStreamsClient or accessKey and secretKey must be specified");
         }
-        DdbStreamEndpoint endpoint = new DdbStreamEndpoint(uri, configuration, this);
-        setProperties(endpoint, parameters);
         return endpoint;
     }
     
@@ -91,36 +80,36 @@ public class DdbStreamComponent 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;
     }
 
     /**
      * Amazon AWS Region
      */
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
     
     private void checkAndSetRegistryClient(DdbStreamConfiguration configuration) {
diff --git a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java
index 17074aa..92b45b5 100644
--- a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java
+++ b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java
@@ -18,7 +18,6 @@ package org.apache.camel.component.aws.ddbstream;
 
 import com.amazonaws.Protocol;
 import com.amazonaws.regions.Regions;
-import org.apache.camel.component.aws.ddb.DdbComponent;
 import org.apache.camel.component.aws.ddb.DdbEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -27,7 +26,7 @@ public class DdbStreamComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithAccessAndSecretKey() throws Exception {
-        DdbStreamComponent component = new DdbStreamComponent(context);
+        DdbStreamComponent component = context.getComponent("aws-ddbstream", DdbStreamComponent.class);
         DdbStreamEndpoint endpoint = (DdbStreamEndpoint)component.createEndpoint("aws-ddbstreams://myTable?accessKey=xxxxx&secretKey=yyyyy");
         
         assertEquals("myTable", endpoint.getConfiguration().getTableName());
@@ -37,7 +36,7 @@ public class DdbStreamComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        DdbStreamComponent component = new DdbStreamComponent(context);
+        DdbStreamComponent component = context.getComponent("aws-ddbstream", DdbStreamComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         DdbStreamEndpoint endpoint = (DdbStreamEndpoint)component.createEndpoint("aws-ddbstreams://myTable");
@@ -49,7 +48,7 @@ public class DdbStreamComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        DdbStreamComponent component = new DdbStreamComponent(context);
+        DdbStreamComponent component = context.getComponent("aws-ddbstream", DdbStreamComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -63,11 +62,11 @@ public class DdbStreamComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbStreamComponent component = context.getComponent("aws-ddbstream", DdbStreamComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
-        DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddbstreams://myTable?accessKey=xxxxxx&secretKey=yyyyy&region=US_EAST_1&proxyHost=localhost&proxyPort=9000&proxyProtocol=HTTP");
+        DdbStreamEndpoint endpoint = (DdbStreamEndpoint)component.createEndpoint("aws-ddbstreams://myTable?accessKey=xxxxxx&secretKey=yyyyy&region=US_EAST_1&proxyHost=localhost&proxyPort=9000&proxyProtocol=HTTP");
         
         assertEquals("myTable", endpoint.getConfiguration().getTableName());
         assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());