You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/11 10:14:41 UTC
[camel] branch master updated: CAMEL-14284: Configuring endpoint
should set properties on endpoint and not configuration object - aws-cw
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 9c09d3ba CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-cw
9c09d3ba is described below
commit 9c09d3ba40e24d9843498abc923fb073de88d257
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 11 11:13:59 2019 +0100
CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-cw
---
.../apache/camel/component/aws/cw/CwComponent.java | 47 +++++++++-------------
.../aws/cw/CwComponentConfigurationTest.java | 14 +++----
.../aws/cw/CwComponentRegistryClientTest.java | 5 +--
3 files changed, 29 insertions(+), 37 deletions(-)
diff --git a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
index bced4d9..08f9b75 100644
--- a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
+++ b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.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-cw")
public class CwComponent extends DefaultComponent {
@@ -45,39 +44,33 @@ public class CwComponent extends DefaultComponent {
public CwComponent(CamelContext context) {
super(context);
-
- this.configuration = new CwConfiguration();
registerExtension(new CwComponentVerifierExtension());
}
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- CwConfiguration configuration = this.configuration.copy();
- setProperties(configuration, parameters);
-
if (remaining == null || remaining.trim().length() == 0) {
throw new IllegalArgumentException("Metric namespace must be specified.");
}
+
+ CwConfiguration configuration = this.configuration != null ? this.configuration.copy() : new CwConfiguration();
configuration.setNamespace(remaining);
- if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
- setAccessKey(accessKey);
- }
- if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
- setSecretKey(secretKey);
- }
- if (ObjectHelper.isEmpty(configuration.getRegion())) {
- setRegion(region);
- }
+ CwEndpoint endpoint = new CwEndpoint(uri, this, configuration);
+ // set component level options before overriding from endpoint parameters
+ endpoint.getConfiguration().setAccessKey(accessKey);
+ endpoint.getConfiguration().setSecretKey(secretKey);
+ endpoint.getConfiguration().setRegion(region);
+ setProperties(endpoint, parameters);
+
checkAndSetRegistryClient(configuration);
if (configuration.getAmazonCwClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException("AmazonCwClient or accessKey and secretKey must be specified");
}
- CwEndpoint endpoint = new CwEndpoint(uri, this, configuration);
return endpoint;
}
-
+
public CwConfiguration getConfiguration() {
return configuration;
}
@@ -90,36 +83,36 @@ public class CwComponent 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 CW client needs to work
- */
+
public String getRegion() {
- return configuration.getRegion();
+ return region;
}
+ /**
+ * The region in which CW client needs to work
+ */
public void setRegion(String region) {
- configuration.setRegion(region);
+ this.region = region;
}
private void checkAndSetRegistryClient(CwConfiguration configuration) {
diff --git a/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
index 05a3ac1..b8959a5 100644
--- a/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
+++ b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
@@ -36,7 +36,7 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
public void createEndpointWithAllOptions() throws Exception {
AmazonCloudWatchClient cloudWatchClient = mock(AmazonCloudWatchClient.class);
context.getRegistry().bind("amazonCwClient", cloudWatchClient);
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
CwEndpoint endpoint = (CwEndpoint) component.createEndpoint("aws-cw://camel.apache.org/test?amazonCwClient=#amazonCwClient&name=testMetric&value=2&unit=Count×tamp=#now");
assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace());
@@ -48,25 +48,25 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutAccessKeyConfiguration() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.createEndpoint("aws-cw://camel.apache.org/test?secretKey=yyy");
}
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutSecretKeyConfiguration() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxx");
}
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxx");
}
@Test
public void createEndpointWithComponentElements() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.setAccessKey("XXX");
component.setSecretKey("YYY");
CwEndpoint endpoint = (CwEndpoint)component.createEndpoint("aws-cw://camel.apache.org/test");
@@ -78,7 +78,7 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithComponentAndEndpointElements() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.setAccessKey("XXX");
component.setSecretKey("YYY");
component.setRegion(Regions.US_WEST_1.toString());
@@ -92,7 +92,7 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithComponentEndpointOptionsAndProxy() throws Exception {
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
component.setAccessKey("XXX");
component.setSecretKey("YYY");
component.setRegion(Regions.US_WEST_1.toString());
diff --git a/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java
index 24754ea..51182eb 100644
--- a/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java
+++ b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java
@@ -34,7 +34,7 @@ public class CwComponentRegistryClientTest extends CamelTestSupport {
public void createEndpointWithAllOptions() throws Exception {
AmazonCloudWatchClient cloudWatchClient = mock(AmazonCloudWatchClient.class);
context.getRegistry().bind("amazonCwClient", cloudWatchClient);
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
CwEndpoint endpoint = (CwEndpoint) component.createEndpoint("aws-cw://camel.apache.org/test?name=testMetric&value=2&unit=Count×tamp=#now");
assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace());
@@ -46,8 +46,7 @@ public class CwComponentRegistryClientTest extends CamelTestSupport {
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithMinimalS3ClientMisconfiguration() throws Exception {
-
- CwComponent component = new CwComponent(context);
+ CwComponent component = context.getComponent("aws-cw", CwComponent.class);
CwEndpoint endpoint = (CwEndpoint)component.createEndpoint("aws-cw://camel.apache.org/test");
}
}