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 aeadd081e29c72c3ebf661b38543e0b0fe5b52c0 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon May 27 10:07:07 2019 +0200 CAMEL-13571 - Camel AWS-SNS: Make the autocreation of the topic configurable --- .../apache/camel/component/aws/sns/SnsConfiguration.java | 16 +++++++++++++++- .../org/apache/camel/component/aws/sns/SnsEndpoint.java | 2 +- .../component/aws/sns/SnsComponentConfigurationTest.java | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java index 0b2ac60..888a755 100644 --- a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java +++ b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java @@ -50,6 +50,8 @@ public class SnsConfiguration implements Cloneable { private String kmsMasterKeyId; @UriParam private boolean serverSideEncryptionEnabled; + @UriParam(defaultValue = "true") + private boolean autoCreateTopic = true; // Producer only properties @UriParam @@ -237,11 +239,23 @@ public class SnsConfiguration implements Cloneable { this.serverSideEncryptionEnabled = serverSideEncryptionEnabled; } + + public boolean isAutoCreateTopic() { + return autoCreateTopic; + } + + /** + * Setting the autocreation of the topic + */ + public void setAutoCreateTopic(boolean autoCreateTopic) { + this.autoCreateTopic = autoCreateTopic; + } + // ************************************************* // // ************************************************* - public SnsConfiguration copy() { + public SnsConfiguration copy() { try { return (SnsConfiguration)super.clone(); } catch (CloneNotSupportedException e) { diff --git a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java index de12b51..64636b4 100644 --- a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java +++ b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java @@ -121,7 +121,7 @@ public class SnsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy } } - if (configuration.getTopicArn() == null) { + if (configuration.getTopicArn() == null && configuration.isAutoCreateTopic()) { // creates a new topic, or returns the URL of an existing one CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName()); diff --git a/components/camel-aws-sns/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java b/components/camel-aws-sns/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java index d255593..7619cc1 100644 --- a/components/camel-aws-sns/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java +++ b/components/camel-aws-sns/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java @@ -198,6 +198,21 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { } @Test + public void createEndpointWithoutAutocreation() throws Exception { + SnsComponent component = new SnsComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + component.setRegion(Regions.US_WEST_1.toString()); + SnsEndpoint endpoint = (SnsEndpoint)component.createEndpoint("aws-sns://MyTopic?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1&autoCreateTopic=false"); + + assertEquals("MyTopic", endpoint.getConfiguration().getTopicName()); + assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); + assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); + assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); + assertEquals(false, endpoint.getConfiguration().isAutoCreateTopic()); + } + + @Test public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { AmazonSNSClientMock mock = new AmazonSNSClientMock();