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 be3f177afbbc9a76547c5de7932f27589be3fbd5 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Jan 15 10:52:55 2018 +0100 CAMEL-12143 - Camel-AWS SES: Add the ability to specify credentials and region at component level --- .../camel-aws/src/main/docs/aws-ses-component.adoc | 14 +- .../camel/component/aws/ses/SesComponent.java | 70 +++++++- .../camel/component/aws/ses/SesConfiguration.java | 16 +- .../aws/ses/SesComponentConfigurationTest.java | 28 +++ .../ses/springboot/SesComponentConfiguration.java | 194 +++++++++++++++++++++ 5 files changed, 318 insertions(+), 4 deletions(-) diff --git a/components/camel-aws/src/main/docs/aws-ses-component.adoc b/components/camel-aws/src/main/docs/aws-ses-component.adoc index 9893b08..545909e 100644 --- a/components/camel-aws/src/main/docs/aws-ses-component.adoc +++ b/components/camel-aws/src/main/docs/aws-ses-component.adoc @@ -25,7 +25,19 @@ You can append query options to the URI in the following format, // component options: START -The AWS Simple Email Service component has no options. +The AWS Simple Email Service 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 SES default configuration | | SesConfiguration +| *accessKey* (producer) | Amazon AWS Access Key | | String +| *secretKey* (producer) | Amazon AWS Secret Key | | String +| *region* (producer) | The region in which SES 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/ses/SesComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java index 9cf4be9..fa64d8a 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java @@ -21,21 +21,33 @@ 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 SesComponent extends DefaultComponent { + @Metadata + private String accessKey; + @Metadata + private String secretKey; + @Metadata + private String region; + @Metadata(label = "advanced") + private SesConfiguration configuration; + public SesComponent() { this(null); } public SesComponent(CamelContext context) { super(context); - + + this.configuration = new SesConfiguration(); registerExtension(new SesComponentVerifierExtension()); } protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - SesConfiguration configuration = new SesConfiguration(); + SesConfiguration configuration = this.configuration.copy(); setProperties(configuration, parameters); if (remaining == null || remaining.trim().length() == 0) { @@ -43,10 +55,64 @@ public class SesComponent extends DefaultComponent { } configuration.setFrom(remaining); + if (ObjectHelper.isEmpty(configuration.getAccessKey())) { + setAccessKey(accessKey); + } + if (ObjectHelper.isEmpty(configuration.getSecretKey())) { + setSecretKey(secretKey); + } + if (ObjectHelper.isEmpty(configuration.getRegion())) { + setRegion(region); + } + if (configuration.getAmazonSESClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("AmazonSESClient or accessKey and secretKey must be specified"); } return new SesEndpoint(uri, this, configuration); } + + public SesConfiguration getConfiguration() { + return configuration; + } + + /** + * The AWS SES default configuration + */ + public void setConfiguration(SesConfiguration 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 SES 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/ses/SesConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesConfiguration.java index ea80a71..fac1dd8 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesConfiguration.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesConfiguration.java @@ -21,13 +21,15 @@ import java.util.List; import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.aws.s3.S3Configuration; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.spi.UriPath; @UriParams -public class SesConfiguration { +public class SesConfiguration implements Cloneable { @UriPath @Metadata(required = "true") private String from; @@ -196,4 +198,16 @@ public class SesConfiguration { public void setRegion(String region) { this.region = region; } + + // ************************************************* + // + // ************************************************* + + public SesConfiguration copy() { + try { + return (SesConfiguration)super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } } diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java index 8873a9c..9c118aa 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.aws.ses; +import com.amazonaws.regions.Regions; + import org.apache.camel.impl.JndiRegistry; import org.apache.camel.impl.PropertyPlaceholderDelegateRegistry; import org.apache.camel.test.junit4.CamelTestSupport; @@ -134,6 +136,32 @@ public class SesComponentConfigurationTest extends CamelTestSupport { } @Test + public void createEndpointWithComponentElements() throws Exception { + SesComponent component = new SesComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + SesEndpoint endpoint = (SesEndpoint)component.createEndpoint("aws-ses://f...@example.com"); + + assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); + assertEquals("XXX", endpoint.getConfiguration().getAccessKey()); + assertEquals("YYY", endpoint.getConfiguration().getSecretKey()); + } + + @Test + public void createEndpointWithComponentAndEndpointElements() throws Exception { + SesComponent component = new SesComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + component.setRegion(Regions.US_WEST_1.toString()); + SesEndpoint endpoint = (SesEndpoint)component.createEndpoint("aws-ses://f...@example.com?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1"); + + assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); + assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); + assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); + assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); + } + + @Test public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { AmazonSESClientMock mock = new AmazonSESClientMock(); diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ses/springboot/SesComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ses/springboot/SesComponentConfiguration.java index 6ee80dc..42c61a0 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ses/springboot/SesComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ses/springboot/SesComponentConfiguration.java @@ -16,7 +16,9 @@ */ package org.apache.camel.component.aws.ses.springboot; +import java.util.List; import javax.annotation.Generated; +import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -32,12 +34,61 @@ public class SesComponentConfiguration ComponentConfigurationPropertiesCommon { /** + * The AWS SES default configuration + */ + private SesConfigurationNestedConfiguration configuration; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * The region in which SES 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 SesConfigurationNestedConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration( + SesConfigurationNestedConfiguration 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; } @@ -46,4 +97,147 @@ public class SesComponentConfiguration Boolean resolvePropertyPlaceholders) { this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; } + + public static class SesConfigurationNestedConfiguration { + public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.ses.SesConfiguration.class; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * To use the AmazonSimpleEmailService as the client + */ + private AmazonSimpleEmailService amazonSESClient; + /** + * The sender's email address. + */ + private String from; + /** + * List of destination email address. Can be overriden with + * 'CamelAwsSesTo' header. + */ + private List to; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * The subject which is used if the message header 'CamelAwsSesSubject' + * is not present. + */ + private String subject; + /** + * The email address to which bounce notifications are to be forwarded, + * override it using 'CamelAwsSesReturnPath' header. + */ + private String returnPath; + /** + * List of reply-to email address(es) for the message, override it using + * 'CamelAwsSesReplyToAddresses' header. + */ + private List replyToAddresses; + /** + * The region with which the AWS-SES client wants to work with. + */ + private String amazonSESEndpoint; + private String proxyHost; + private Integer proxyPort; + private String region; + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public AmazonSimpleEmailService getAmazonSESClient() { + return amazonSESClient; + } + + public void setAmazonSESClient(AmazonSimpleEmailService amazonSESClient) { + this.amazonSESClient = amazonSESClient; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public List getTo() { + return to; + } + + public void setTo(List to) { + this.to = to; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getReturnPath() { + return returnPath; + } + + public void setReturnPath(String returnPath) { + this.returnPath = returnPath; + } + + public List getReplyToAddresses() { + return replyToAddresses; + } + + public void setReplyToAddresses(List replyToAddresses) { + this.replyToAddresses = replyToAddresses; + } + + public String getAmazonSESEndpoint() { + return amazonSESEndpoint; + } + + public void setAmazonSESEndpoint(String amazonSESEndpoint) { + this.amazonSESEndpoint = amazonSESEndpoint; + } + + 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" <commits@camel.apache.org>.