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 2018/01/15 10:18:05 UTC
[camel] 05/07: CAMEL-12144 - Camel-AWS SNS: Add the ability to
specify credentials and region at component level
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 d9c96a34ef47d877cd1162f183f7164e6cf68427
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Jan 15 11:12:18 2018 +0100
CAMEL-12144 - Camel-AWS SNS: Add the ability to specify credentials and region at component level
---
.../camel-aws/src/main/docs/aws-sns-component.adoc | 14 +-
.../camel/component/aws/sns/SnsComponent.java | 68 +++++++-
.../camel/component/aws/sns/SnsConfiguration.java | 14 ++
.../aws/sns/SnsComponentConfigurationTest.java | 28 +++
.../sns/springboot/SnsComponentConfiguration.java | 190 +++++++++++++++++++++
5 files changed, 312 insertions(+), 2 deletions(-)
diff --git a/components/camel-aws/src/main/docs/aws-sns-component.adoc b/components/camel-aws/src/main/docs/aws-sns-component.adoc
index 2009e5f..9ed31c1 100644
--- a/components/camel-aws/src/main/docs/aws-sns-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-sns-component.adoc
@@ -28,7 +28,19 @@ The topic will be created if they don't already exists. +
// component options: START
-The AWS Simple Notification System component has no options.
+The AWS Simple Notification System component supports 5 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *configuration* (advanced) | The AWS SNS default configuration | | SnsConfiguration
+| *accessKey* (producer) | Amazon AWS Access Key | | String
+| *secretKey* (producer) | Amazon AWS Secret Key | | String
+| *region* (producer) | The region in which SNS client needs to work | | String
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
+|===
// component options: END
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
index b410805..655f92e 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
@@ -21,9 +21,20 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.ObjectHelper;
public class SnsComponent extends DefaultComponent {
+ @Metadata
+ private String accessKey;
+ @Metadata
+ private String secretKey;
+ @Metadata
+ private String region;
+ @Metadata(label = "advanced")
+ private SnsConfiguration configuration;
+
public SnsComponent() {
this(null);
}
@@ -31,11 +42,12 @@ public class SnsComponent extends DefaultComponent {
public SnsComponent(CamelContext context) {
super(context);
+ this.configuration = new SnsConfiguration();
registerExtension(new SnsComponentVerifierExtension());
}
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- SnsConfiguration configuration = new SnsConfiguration();
+ SnsConfiguration configuration = this.configuration.copy();
setProperties(configuration, parameters);
if (remaining == null || remaining.trim().length() == 0) {
@@ -47,6 +59,16 @@ public class SnsComponent extends DefaultComponent {
configuration.setTopicName(remaining);
}
+ if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
+ setAccessKey(accessKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
+ setSecretKey(secretKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getRegion())) {
+ setRegion(region);
+ }
+
if (configuration.getAmazonSNSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException("AmazonSNSClient or accessKey and secretKey must be specified");
}
@@ -54,4 +76,48 @@ public class SnsComponent extends DefaultComponent {
SnsEndpoint endpoint = new SnsEndpoint(uri, this, configuration);
return endpoint;
}
+
+ public SnsConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The AWS SNS default configuration
+ */
+ public void setConfiguration(SnsConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getAccessKey() {
+ return configuration.getAccessKey();
+ }
+
+ /**
+ * Amazon AWS Access Key
+ */
+ public void setAccessKey(String accessKey) {
+ configuration.setAccessKey(accessKey);
+ }
+
+ public String getSecretKey() {
+ return configuration.getSecretKey();
+ }
+
+ /**
+ * Amazon AWS Secret Key
+ */
+ public void setSecretKey(String secretKey) {
+ configuration.setSecretKey(secretKey);
+ }
+
+ /**
+ * The region in which SNS client needs to work
+ */
+ public String getRegion() {
+ return configuration.getRegion();
+ }
+
+ public void setRegion(String region) {
+ configuration.setRegion(region);
+ }
}
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
index 3253bea..0dc6446 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.aws.sns;
import com.amazonaws.services.sns.AmazonSNS;
+
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -181,4 +183,16 @@ public class SnsConfiguration implements Cloneable {
public void setRegion(String region) {
this.region = region;
}
+
+ // *************************************************
+ //
+ // *************************************************
+
+ public SnsConfiguration copy() {
+ try {
+ return (SnsConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}
\ No newline at end of file
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
index 8c1374b..52077c6 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.aws.sns;
+import com.amazonaws.regions.Regions;
+
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.impl.PropertyPlaceholderDelegateRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
@@ -129,6 +131,32 @@ public class SnsComponentConfigurationTest extends CamelTestSupport {
}
@Test
+ public void createEndpointWithComponentElements() throws Exception {
+ SnsComponent component = new SnsComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ SnsEndpoint endpoint = (SnsEndpoint)component.createEndpoint("aws-sns://MyTopic");
+
+ assertEquals("MyTopic", endpoint.getConfiguration().getTopicName());
+ assertEquals("XXX", endpoint.getConfiguration().getAccessKey());
+ assertEquals("YYY", endpoint.getConfiguration().getSecretKey());
+ }
+
+ @Test
+ public void createEndpointWithComponentAndEndpointElements() 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");
+
+ assertEquals("MyTopic", endpoint.getConfiguration().getTopicName());
+ assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+ assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+ assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+ }
+
+ @Test
public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception {
AmazonSNSClientMock mock = new AmazonSNSClientMock();
diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
index f9c59f2..b5962a2 100644
--- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws.sns.springboot;
import javax.annotation.Generated;
+import com.amazonaws.services.sns.AmazonSNS;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -33,12 +34,61 @@ public class SnsComponentConfiguration
ComponentConfigurationPropertiesCommon {
/**
+ * The AWS SNS default configuration
+ */
+ private SnsConfigurationNestedConfiguration configuration;
+ /**
+ * Amazon AWS Access Key
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key
+ */
+ private String secretKey;
+ /**
+ * The region in which SNS client needs to work
+ */
+ private String region;
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
*/
private Boolean resolvePropertyPlaceholders = true;
+ public SnsConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ SnsConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
@@ -47,4 +97,144 @@ public class SnsComponentConfiguration
Boolean resolvePropertyPlaceholders) {
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
+
+ public static class SnsConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.sns.SnsConfiguration.class;
+ /**
+ * The region with which the AWS-SNS client wants to work with.
+ */
+ private String amazonSNSEndpoint;
+ /**
+ * The subject which is used if the message header 'CamelAwsSnsSubject'
+ * is not present.
+ */
+ private String subject;
+ /**
+ * The Amazon Resource Name (ARN) assigned to the created topic.
+ */
+ private String topicArn;
+ /**
+ * Amazon AWS Access Key
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key
+ */
+ private String secretKey;
+ /**
+ * To use the AmazonSNS as the client
+ */
+ private AmazonSNS amazonSNSClient;
+ /**
+ * The name of the topic
+ */
+ private String topicName;
+ /**
+ * The policy for this queue
+ */
+ private String policy;
+ /**
+ * The message structure to use such as json
+ */
+ private String messageStructure;
+ private String proxyHost;
+ private Integer proxyPort;
+ private String region;
+
+ public String getAmazonSNSEndpoint() {
+ return amazonSNSEndpoint;
+ }
+
+ public void setAmazonSNSEndpoint(String amazonSNSEndpoint) {
+ this.amazonSNSEndpoint = amazonSNSEndpoint;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ public String getTopicArn() {
+ return topicArn;
+ }
+
+ public void setTopicArn(String topicArn) {
+ this.topicArn = topicArn;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public AmazonSNS getAmazonSNSClient() {
+ return amazonSNSClient;
+ }
+
+ public void setAmazonSNSClient(AmazonSNS amazonSNSClient) {
+ this.amazonSNSClient = amazonSNSClient;
+ }
+
+ public String getTopicName() {
+ return topicName;
+ }
+
+ public void setTopicName(String topicName) {
+ this.topicName = topicName;
+ }
+
+ public String getPolicy() {
+ return policy;
+ }
+
+ public void setPolicy(String policy) {
+ this.policy = policy;
+ }
+
+ public String getMessageStructure() {
+ return messageStructure;
+ }
+
+ public void setMessageStructure(String messageStructure) {
+ this.messageStructure = messageStructure;
+ }
+
+ public String getProxyHost() {
+ return proxyHost;
+ }
+
+ public void setProxyHost(String proxyHost) {
+ this.proxyHost = proxyHost;
+ }
+
+ public Integer getProxyPort() {
+ return proxyPort;
+ }
+
+ public void setProxyPort(Integer proxyPort) {
+ this.proxyPort = proxyPort;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.