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
The following commit(s) were added to refs/heads/master by this push: new 926b206 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ecs 926b206 is described below commit 926b20646bddaefd0f68b2b1f9b91a678ff5671c Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Dec 11 11:59:02 2019 +0100 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ecs --- .../camel/component/aws/ecs/ECSComponent.java | 35 ++++++++-------------- .../aws/ecs/ECSComponentClientRegistryTest.java | 4 +-- .../aws/ecs/ECSComponentConfigurationTest.java | 6 ++-- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/components/camel-aws-ecs/src/main/java/org/apache/camel/component/aws/ecs/ECSComponent.java b/components/camel-aws-ecs/src/main/java/org/apache/camel/component/aws/ecs/ECSComponent.java index 2b457ae..349ef87 100644 --- a/components/camel-aws-ecs/src/main/java/org/apache/camel/component/aws/ecs/ECSComponent.java +++ b/components/camel-aws-ecs/src/main/java/org/apache/camel/component/aws/ecs/ECSComponent.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 ECS. @@ -49,30 +48,22 @@ public class ECSComponent extends DefaultComponent { public ECSComponent(CamelContext context) { super(context); - this.configuration = new ECSConfiguration(); registerExtension(new ECSComponentVerifierExtension()); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - ECSConfiguration 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); - } + ECSConfiguration configuration = this.configuration != null ? this.configuration.copy() : new ECSConfiguration(); + ECSEndpoint endpoint = new ECSEndpoint(uri, this, configuration); + endpoint.getConfiguration().setAccessKey(accessKey); + endpoint.getConfiguration().setSecretKey(secretKey); + endpoint.getConfiguration().setRegion(region); + setProperties(endpoint, parameters); checkAndSetRegistryClient(configuration); if (configuration.getEcsClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("Amazon ecs client or accessKey and secretKey must be specified"); } - - ECSEndpoint endpoint = new ECSEndpoint(uri, this, configuration); + return endpoint; } @@ -88,36 +79,36 @@ public class ECSComponent 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 ECS client needs to work */ public void setRegion(String region) { - configuration.setRegion(region); + this.region = region; } private void checkAndSetRegistryClient(ECSConfiguration configuration) { diff --git a/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentClientRegistryTest.java b/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentClientRegistryTest.java index 1fba43d..5de1ddf 100644 --- a/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentClientRegistryTest.java +++ b/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentClientRegistryTest.java @@ -26,7 +26,7 @@ public class ECSComponentClientRegistryTest extends CamelTestSupport { AmazonECSClientMock clientMock = new AmazonECSClientMock(); context.getRegistry().bind("amazonEcsClient", clientMock); - ECSComponent component = new ECSComponent(context); + ECSComponent component = context.getComponent("aws-ecs", ECSComponent.class); ECSEndpoint endpoint = (ECSEndpoint)component.createEndpoint("aws-ecs://TestDomain"); assertNotNull(endpoint.getConfiguration().getEcsClient()); @@ -35,7 +35,7 @@ public class ECSComponentClientRegistryTest extends CamelTestSupport { @Test(expected = IllegalArgumentException.class) public void createEndpointWithMinimalECSClientMisconfiguration() throws Exception { - ECSComponent component = new ECSComponent(context); + ECSComponent component = context.getComponent("aws-ecs", ECSComponent.class); ECSEndpoint endpoint = (ECSEndpoint)component.createEndpoint("aws-ecs://TestDomain"); } } diff --git a/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentConfigurationTest.java b/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentConfigurationTest.java index b596cd5..2a451ab 100644 --- a/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentConfigurationTest.java +++ b/components/camel-aws-ecs/src/test/java/org/apache/camel/component/aws/ecs/ECSComponentConfigurationTest.java @@ -26,7 +26,7 @@ public class ECSComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentElements() throws Exception { - ECSComponent component = new ECSComponent(context); + ECSComponent component = context.getComponent("aws-ecs", ECSComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); ECSEndpoint endpoint = (ECSEndpoint)component.createEndpoint("aws-ecs://label"); @@ -37,7 +37,7 @@ public class ECSComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentAndEndpointElements() throws Exception { - ECSComponent component = new ECSComponent(context); + ECSComponent component = context.getComponent("aws-ecs", ECSComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); @@ -50,7 +50,7 @@ public class ECSComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception { - ECSComponent component = new ECSComponent(context); + ECSComponent component = context.getComponent("aws-ecs", ECSComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString());