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

[camel] branch master updated (fc9ef81 -> 7b86d97)

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

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


    from fc9ef81  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - xchange
     new 6fb0ebf  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ddb
     new 7b86d97  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ddbstreams

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/aws/ddb/DdbComponent.java      | 33 ++++++++------------
 .../aws/ddbstream/DdbStreamComponent.java          | 35 ++++++++--------------
 .../aws/ddb/DdbComponentConfigurationTest.java     |  6 ++--
 .../aws/ddb/DdbComponentRegistryClientTest.java    |  4 +--
 .../camel/component/aws/ddb/DdbComponentTest.java  |  6 ++--
 .../DdbStreamComponentConfigurationTest.java       | 11 ++++---
 6 files changed, 37 insertions(+), 58 deletions(-)


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

Posted by ac...@apache.org.
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 6fb0ebf0e54cecf01c0e5c9d1807335a596f7da7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 11:28:30 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ddb
---
 .../camel/component/aws/ddb/DdbComponent.java      | 33 ++++++++--------------
 .../aws/ddb/DdbComponentConfigurationTest.java     |  6 ++--
 .../aws/ddb/DdbComponentRegistryClientTest.java    |  4 +--
 .../camel/component/aws/ddb/DdbComponentTest.java  |  6 ++--
 4 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java
index 7039f7a..b8ec016 100644
--- a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java
+++ b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.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-ddb")
 public class DdbComponent extends DefaultComponent {
@@ -46,35 +45,27 @@ public class DdbComponent extends DefaultComponent {
     public DdbComponent(CamelContext context) {
         super(context);
         
-        this.configuration = new DdbConfiguration();
         registerExtension(new DdbComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        DdbConfiguration configuration = this.configuration.copy();
-        setProperties(configuration, parameters);
 
         if (remaining == null || remaining.trim().length() == 0) {
             throw new IllegalArgumentException("Table name must be specified.");
         }
+        DdbConfiguration configuration = this.configuration != null ? this.configuration.copy() : new DdbConfiguration();
         configuration.setTableName(remaining);
-
-        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
-            setAccessKey(accessKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
-            setSecretKey(secretKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getRegion())) {
-            setRegion(region);
-        }
+        DdbEndpoint endpoint = new DdbEndpoint(uri, this, configuration);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
         if (configuration.getAmazonDDBClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonDDBClient or accessKey and secretKey must be specified");
         }
 
-        DdbEndpoint endpoint = new DdbEndpoint(uri, this, configuration);
         return endpoint;
     }
     
@@ -90,36 +81,36 @@ public class DdbComponent 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;
     }
     
     /**
      * The region in which DDB client needs to work
      */
     public String getRegion() {
-        return configuration.getRegion();
+        return region;
     }
 
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
     
     private void checkAndSetRegistryClient(DdbConfiguration configuration) {
diff --git a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurationTest.java b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurationTest.java
index 9d37410..ec82f03 100644
--- a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurationTest.java
+++ b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurationTest.java
@@ -25,7 +25,7 @@ public class DdbComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddb://myTable");
@@ -37,7 +37,7 @@ public class DdbComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -51,7 +51,7 @@ public class DdbComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
diff --git a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java
index 79ef2a0..73b6b06 100644
--- a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java
+++ b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java
@@ -25,7 +25,7 @@ public class DdbComponentRegistryClientTest extends CamelTestSupport {
     public void createEndpointWithRegistryClient() throws Exception {
         AmazonDDBClientMock ddbClient = new AmazonDDBClientMock();
         context.getRegistry().bind("ddbClient", ddbClient);
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddb://myTable");
         
         assertEquals("myTable", endpoint.getConfiguration().getTableName());
@@ -33,7 +33,7 @@ public class DdbComponentRegistryClientTest extends CamelTestSupport {
     
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithoutRegistryClient() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddb://myTable");
         
         assertEquals("myTable", endpoint.getConfiguration().getTableName());
diff --git a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java
index 6fe7af0..6d069f1 100644
--- a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java
+++ b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java
@@ -42,20 +42,20 @@ public class DdbComponentTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithOnlySecretKeyConfiguration() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.createEndpoint("aws-ddb://activeTable?secretKey=xxx");
     }
     
     @Test
     public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.createEndpoint("aws-ddb://activeTable?amazonDDBClient=#amazonDDBClient");
     }
 
 
     @Test
     public void createEndpointWithOnlyAccessKeyAndSecretKey() throws Exception {
-        DdbComponent component = new DdbComponent(context);
+        DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class);
         component.createEndpoint("aws-ddb://activeTable?accessKey=xxx&secretKey=yyy");
     }
 


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

Posted by ac...@apache.org.
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());