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 14:14:32 UTC
[camel] branch master updated: CAMEL-14284: Configuring endpoint
should set properties on endpoint and not configuration object - aws-s3
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 ab61fc7 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-s3
ab61fc7 is described below
commit ab61fc72120d32402173702a05393445947bda6a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 15:11:42 2019 +0100
CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-s3
---
.../apache/camel/component/aws/s3/S3Component.java | 34 ++++++++--------------
.../aws/s3/S3ComponentClientRegistryTest.java | 4 +--
.../aws/s3/S3ComponentConfigurationTest.java | 34 +++++++++++-----------
3 files changed, 31 insertions(+), 41 deletions(-)
diff --git a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Component.java b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
index abf249f..4e2bdfb 100644
--- a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
+++ b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Component.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-s3")
public class S3Component extends DefaultComponent {
@@ -46,14 +45,11 @@ public class S3Component extends DefaultComponent {
public S3Component(CamelContext context) {
super(context);
- this.configuration = new S3Configuration();
registerExtension(new S3ComponentVerifierExtension());
}
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- final S3Configuration configuration = this.configuration.copy();
- setProperties(configuration, parameters);
if (remaining == null || remaining.trim().length() == 0) {
throw new IllegalArgumentException("Bucket name must be specified.");
@@ -61,24 +57,18 @@ public class S3Component extends DefaultComponent {
if (remaining.startsWith("arn:")) {
remaining = remaining.substring(remaining.lastIndexOf(":") + 1, remaining.length());
}
+ final S3Configuration configuration = this.configuration != null ? this.configuration.copy() : new S3Configuration();
configuration.setBucketName(remaining);
-
- if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
- setAccessKey(accessKey);
- }
- if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
- setSecretKey(secretKey);
- }
- if (ObjectHelper.isEmpty(configuration.getRegion())) {
- setRegion(region);
- }
+ S3Endpoint endpoint = new S3Endpoint(uri, this, configuration);
+ endpoint.getConfiguration().setAccessKey(accessKey);
+ endpoint.getConfiguration().setSecretKey(secretKey);
+ endpoint.getConfiguration().setRegion(region);
+ setProperties(endpoint, parameters);
checkAndSetRegistryClient(configuration);
if (!configuration.isUseIAMCredentials() && configuration.getAmazonS3Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException("useIAMCredentials is set to false, AmazonS3Client or accessKey and secretKey must be specified");
}
- S3Endpoint endpoint = new S3Endpoint(uri, this, configuration);
- setProperties(endpoint, parameters);
return endpoint;
}
@@ -94,29 +84,29 @@ public class S3Component 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;
}
/**
@@ -124,7 +114,7 @@ public class S3Component extends DefaultComponent {
* `com.amazonaws.services.s3.model.CreateBucketRequest`.
*/
public void setRegion(String region) {
- configuration.setRegion(region);
+ this.region = region;
}
private void checkAndSetRegistryClient(S3Configuration configuration) {
diff --git a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentClientRegistryTest.java b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentClientRegistryTest.java
index 1e78328..913e1fe 100644
--- a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentClientRegistryTest.java
+++ b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentClientRegistryTest.java
@@ -26,7 +26,7 @@ public class S3ComponentClientRegistryTest extends CamelTestSupport {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -42,7 +42,7 @@ public class S3ComponentClientRegistryTest extends CamelTestSupport {
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithMinimalS3ClientMisconfiguration() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket");
}
}
diff --git a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
index b941326..fc05a5c 100644
--- a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
+++ b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
@@ -27,7 +27,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?amazonS3Client=#amazonS3Client&accessKey=xxx&secretKey=yyy");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -44,7 +44,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithMinimalCredentialsConfiguration() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?accessKey=xxx&secretKey=yyy");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -62,7 +62,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
public void createEndpointWithMinimalArnConfiguration() throws Exception {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://arn:aws:s3:::MyBucket?amazonS3Client=#amazonS3Client&accessKey=xxx&secretKey=yyy");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -73,7 +73,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?amazonS3Client=#amazonS3Client");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -92,7 +92,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
public void createEndpointWithMaximalConfiguration() throws Exception {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component
.createEndpoint("aws-s3://MyBucket?amazonS3Client=#amazonS3Client"
+ "&accessKey=xxx&secretKey=yyy®ion=us-west-1&deleteAfterRead=false&maxMessagesPerPoll=1&policy=%7B%22Version%22%3A%222008-10-17%22,%22Id%22%3A%22Policy4324355464%22,"
@@ -116,25 +116,25 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutBucketName() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.createEndpoint("aws-s3:// ");
}
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutAccessKeyConfiguration() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.createEndpoint("aws-s3://MyTopic?secretKey=yyy");
}
@Test(expected = IllegalArgumentException.class)
public void createEndpointWithoutSecretKeyConfiguration() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.createEndpoint("aws-s3://MyTopic?accessKey=xxx");
}
@Test
public void createEndpointWithComponentElements() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.setAccessKey("XXX");
component.setSecretKey("YYY");
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket");
@@ -146,7 +146,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithComponentAndEndpointElements() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.setAccessKey("XXX");
component.setSecretKey("YYY");
component.setRegion(Regions.US_WEST_1.toString());
@@ -161,7 +161,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithChunkedEncoding() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?chunkedEncodingDisabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -173,7 +173,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithAccelerateMode() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?accelerateModeEnabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -185,7 +185,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithDualstack() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?dualstackEnabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -197,7 +197,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithPayloadSigning() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?payloadSigningEnabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -209,7 +209,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithForceGlobalBucketAccess() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component.createEndpoint("aws-s3://MyBucket?forceGlobalBucketAccessEnabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1");
assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
@@ -221,7 +221,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
@Test
public void createEndpointWithAutocreateOption() throws Exception {
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
S3Endpoint endpoint = (S3Endpoint)component
.createEndpoint("aws-s3://MyBucket?forceGlobalBucketAccessEnabled=true&accessKey=xxx&secretKey=yyy®ion=US_WEST_1&autoCreateBucket=false");
@@ -236,7 +236,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception {
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
context.getRegistry().bind("amazonS3Client", clientMock);
- S3Component component = new S3Component(context);
+ S3Component component = context.getComponent("aws-s3", S3Component.class);
component.createEndpoint("aws-s3://MyTopic?amazonS3Client=#amazonS3Client");
}
}