diff --git a/.gitignore b/.gitignore
index 5339548..5a36a45 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,4 +17,5 @@ lib
logs
nohup.out
out
-target
\ No newline at end of file
+target
+spring-integration-aws/src/test/resources/awscredentials.properties
\ No newline at end of file
diff --git a/README.md b/README.md
index c7dbf51..eb6b3ef 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ The Spring Integration Extensions project provides extension modules for [Spring
* [Atmosphere][] Support ([Websockets][])
* [XQuery][] Support
* [Splunk][] Support
+* [Amazon Web Services (AWS)][] Support
## Getting support
@@ -127,4 +128,5 @@ The Spring Integration Extensions Framework is released under version 2.0 of the
[Atmosphere]: https://github.com/Atmosphere/atmosphere
[Websockets]: http://www.html5rocks.com/en/tutorials/websockets/basics/
[XQuery]: http://en.wikipedia.org/wiki/XQuery
-[Splunk]:http://www.splunk.com/
\ No newline at end of file
+[Splunk]:http://www.splunk.com/
+[Amazon Web Services (AWS)]: http://aws.amazon.com/
\ No newline at end of file
diff --git a/spring-integration-aws/README.md b/spring-integration-aws/README.md
new file mode 100644
index 0000000..e091601
--- /dev/null
+++ b/spring-integration-aws/README.md
@@ -0,0 +1,141 @@
+Spring Integration Extension for Amazon Web Services (AWS)
+==========================================================
+
+
+##Small Introduction to Amazon Web Services (AWS)
+
+
+Launched in 2006, Amazon Web Services (AWS) started providing key infrastructure for business as web services, which, also known as cloud computing. Using cloud computing businesses can adopt a new business model whereby they do not have to plan and invest in procuring their own IT infrastructure. They can use the infrastructure and services provided by the cloud service provider and pay as they use the services.
+Visit [http://aws.amazon.com/products/] for more details about various products offered by Amazon as a part their cloud computing services.
+
+##Introduction to Spring Integration's extensions to AWS
+
+This guide intends to explain in brief about various adapters available for the AWS and sample xml tag definition for each of them and code snippets wherever necessary,
+
+The library aims to provide adapters for following AWS Services
+
+* **Amazon Simple Email Service (SES)**
+* **Amazon Simple Storage Service (S3)** (Development complete, coming soon)
+* **Amazon Simple Queue Service (SQS)** (Development complete, coming soon)
+* **Amazon DynamoDB** (Analysis ongoing)
+* **Amazon SimpleDB** (Not initiated)
+* **Amazon SNS** (Not initiated)
+
+Of the above libraries, SES and SNS have outbound adapters only. All other
+services have inbound and outbound adapters. The SQS inbound adapter is capable of receiving notifications sent out from SNS where the topic is an SQS Queue.
+For DymamoDB and SimpleDB, apart from inbound and outbound adapters we shall provide a *MessageStore* implementation too.
+
+
+###Executing the test cases.
+
+All the test cases for the adapters are present in the *src/test/java* folder. On executing the build, maven's surefire plugin will execute all
+the tests. Please note that all the tests ending with **AWSTests.java* connect
+to the actual webservices and are excluded by default in the maven build.
+All other tests rely on mocking to test the functionality. You need to execute the **AWSTests.java*
+explicitly, manually to test the conectivity to AWS using your credentials.
+All these **AWSTests.java* tests look for the file *awscredentials.properties* in the classpath.
+To be on the safer side create one at location *src/test/resources* as this file
+*spring-integration-aws/src/test/resources/awscredentials.properties* is added to *.gitignore* file.
+This will prevent this file to be checked in accidently and revealing your credentials.
+This file needs to have two properties *accessKey* and *secretKey* holding the values of your access key and secret key respectively.
+> **Note: AWS Services are chargeable and we recommend not to execute the **AWSTests.java* as part of your regular builds.
+AWS does provide a free tier which is sufficient to perform your tests without being
+charged (not true for DynamoDB though), however keep a check on your account usage regularly.
+Get more information about AWS free tier at [http://aws.amazon.com/free/][]**
+
+
+
+#Adapters
+
+##Simple Email Service (SES)
+
+
+###Introduction
+
+Amazon Simple Email Service (SES) is a web service for sending emails from the cloud. It supports two types of mails currently, the simple mail and raw email.
+Use simple mail if your application just needs to send out emails with some html formatting and without embedded images or attachments. Raw emails gives more flixibility to
+send complex emails with embedded images and attachments.
+For more details about Amazon SES and its pricing visit [http://aws.amazon.com/ses/]
+We have an outbound channel adapter for the Amazon SES Service for sending out simple and raw emails with complete namespace support for configuring the adapter.
+To prevent misuse of the service, Amazon has enforced some restrictions, for sandbox you need to verify email ids which would be used in *to, cc, bcc* and *from*. For more details on how to use SES and
+other details refer to the SES documentation at [http://aws.amazon.com/documentation/ses/][].
+
+###Outbound Channel Adapter
+
+Below xml snippet is a simple definition of the outbound channel adapter
+
+
+
+
+
+
+*propertiesFile* attribute contains the AWS access key and secret key. The
+name of the properties are *accessKey* and *secretKey* respectively.
+An alternative to the *propertiesFile* attribute is the *accessKey* and the
+*secretKey* attributes containing the values of access key and the secret key. The definition will look as below.
+
+
+
+
+Both the approaches for providing the credentials are mutually exclusive to each other.
+
+####Sending Mail Messages
+We shall now see a java code snippet to send a mail using the SNS adapter
+
+
+* **Simple Mail Message**
+
+ A Simple Mail Message does not support attachments and embedded contents. It supports basic html content to be sent as the mail body.
+
+ Map headers = new HashMap();
+ headers.put("fromEmailId", "xyz@somemail.com");
+ headers.put("htmlFormat", true);
+ headers.put("subject", "Mail Sent from AWS SES Outbound adapter");
+ headers.put("toEmailId", "abc@anothermail.com");
+
+ Message msg =
+ MessageBuilder.withPayload("A Simple Mail Message sent from " +
+ "Amazon SES Outbound adapter from Spring integration")
+ .copyHeaders(headers)
+ .build();
+ channel.send(msg);
+
+ The above piece off code is pretty simple.
+ * We add four headers to the message for the *to email id*, *from email id*, *subject* and a *flag* to indicate whether the content is an html content or plain text content.
+ * Of these headers the *from email id* and *subject* are mandatory. We can specify one or more of *to*, *cc* or *bcc* email addresses.
+ * The message needs to have a payload of string which is either a plain
+ text or html content. The content will be rendered a html only if the
+ *htmlFormat *header is set appropriately.
+ * The value of the *htmlFormat* header can be Boolean *true*, or *y*,*yes*
+ or *true* as String. For String the value is case insensitive. Any other value will be considered as *false*.
+ * The message is sent over the channel to which is the input channel of
+ the outbound channel adapter.
+ * See *o.s.i.aws.ses.AmazonSESMailHeaders* for all the possible header values supported.
+
+* **Raw Mail Message**
+
+ Use raw mail when you need more flexibility to send mails, like setting mime types and email headers. As long as the content complies with the standard email format standard you can use this means for sending the mail to your recipients. In the below sample we use the spring's *o.s.mail.javamail.MimeMessageHelper* to construct the Mime message.
+
+ Session session = Session.getDefaultInstance(new Properties());
+ MimeMessageHelper helper = new MimeMessageHelper(new MimeMessage(session),true);
+ helper.setTo("abc@somemail.com");
+ helper.setFrom("xyz@anothermail.com");
+ helper.setText("A Sample Embedded image");
+ helper.addAttachment(file.getName(),new File(""));
+ helper.setSubject("Name Pic");
+ Message message =
+ MessageBuilder.withPayload(helper.getMimeMessage()).build();
+ channel.send(message);
+
+ The messages over this channel are consumed by the outbound SES adapter and the mail is sent out using SES.
+
+
+[http://aws.amazon.com/products/]: http://aws.amazon.com/products/
+[http://aws.amazon.com/ses/]: http://aws.amazon.com/ses/
+[http://aws.amazon.com/documentation/ses/]: http://aws.amazon.com/documentation/ses/
+[http://aws.amazon.com/free/]: http://aws.amazon.com/free/
\ No newline at end of file
diff --git a/spring-integration-aws/pom.xml b/spring-integration-aws/pom.xml
new file mode 100644
index 0000000..b868095
--- /dev/null
+++ b/spring-integration-aws/pom.xml
@@ -0,0 +1,223 @@
+
+
+ 4.0.0
+ org.springframework.integration
+ spring-integration-aws
+ 1.0.0.BUILD-SNAPSHOT
+ Spring Integration Amazon Web Services Support
+
+
+ The Apache Software License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
+ 2.2.1
+
+
+
+ 2.2.0.RELEASE
+ 3.1.3.RELEASE
+ 1.3.12
+ 1.5
+ 1.1.1
+ 2.0.1
+ 1.4.4
+ 1.9.11
+ 4.1.1
+ 1.1
+ 4.11
+ 1.9.0
+ UTF8
+
+
+
+
+
+ src/main/java
+
+ **/*
+
+
+ **/*.java
+
+
+
+ src/main/resources
+
+ **/*
+
+
+
+
+
+ src/test/java
+
+ **/*
+
+
+ **/*.java
+
+
+
+ src/test/resources
+
+ **/*
+
+
+
+
+
+ maven-compiler-plugin
+
+ 1.6
+ 1.6
+
+
+
+ maven-surefire-plugin
+
+
+ **/*Tests.java
+
+
+ **/*Abstract*.java
+ **/*AWSTests.java
+
+
+
+
+
+
+
+ springsource-libs-milestone
+ Spring Framework Maven Milestone Repository
+ https://repo.springsource.org/libs-milestone
+
+
+
+
+ com.amazonaws
+ aws-java-sdk
+ ${aws.sdk.version}
+ compile
+
+
+
+ commons-codec
+ commons-codec
+ ${commons.codec.version}
+ compile
+
+
+
+ commons-logging
+ commons-logging
+ ${commons.logging.version}
+ compile
+
+
+
+ commons-io
+ commons-io
+ ${commons.io.version}
+ compile
+
+
+
+ javax.mail
+ mail
+ ${java.mail.version}
+ compile
+
+
+
+ org.springframework.integration
+ spring-integration-core
+ ${spring.integration.version}
+ compile
+
+
+
+ org.springframework.integration
+ spring-integration-mail
+ ${spring.integration.version}
+ compile
+
+
+
+
+ org.codehaus.jackson
+ jackson-core-asl
+ ${jackson.version}
+ compile
+
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ ${jackson.version}
+ compile
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ ${apache.httpclient.version}
+ compile
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ ${apache.httpclient.version}
+ compile
+
+
+
+ org.springframework.integration
+ spring-integration-test
+ ${spring.integration.version}
+ test
+
+
+
+ org.hamcrest
+ hamcrest-core
+ ${hamcrest.version}
+ test
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+
+ org.mockito
+ mockito-all
+ ${mockito.version}
+ test
+
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+
+ org.springframework
+ spring-test
+ ${spring.test.version}
+ test
+
+
+
+
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AWSNamespaceHandler.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AWSNamespaceHandler.java
new file mode 100644
index 0000000..044e702
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AWSNamespaceHandler.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.config.xml;
+
+import org.springframework.integration.aws.ses.config.xml.AmazonSESOutboundAdapterParser;
+import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
+
+/**
+ * The namepsace handler for "int-aws" namespace
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class AWSNamespaceHandler extends
+ AbstractIntegrationNamespaceHandler {
+
+
+ public void init() {
+ this.registerBeanDefinitionParser("ses-outbound-channel-adapter", new AmazonSESOutboundAdapterParser());
+ }
+
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AbstractAWSOutboundChannelAdapterParser.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AbstractAWSOutboundChannelAdapterParser.java
new file mode 100644
index 0000000..3ea2a57
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AbstractAWSOutboundChannelAdapterParser.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.config.xml;
+
+import static org.springframework.integration.aws.config.xml.AmazonWSParserUtils.getAmazonWSCredentials;
+
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
+import org.springframework.integration.core.MessageHandler;
+import org.w3c.dom.Element;
+
+/**
+ * The common adapter parser for all AWS Outbound channel adapters
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public abstract class AbstractAWSOutboundChannelAdapterParser extends
+ AbstractOutboundChannelAdapterParser {
+
+ /* (non-Javadoc)
+ * @see org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser#parseConsumer(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
+ */
+ @Override
+ protected final AbstractBeanDefinition parseConsumer(Element element,
+ ParserContext parserContext) {
+ String awsCredentialsGeneratedName = getAmazonWSCredentials(element,parserContext);
+
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(getMessageHandlerImplementation());
+ builder.addConstructorArgReference(awsCredentialsGeneratedName);
+ processBeanDefinition(builder,awsCredentialsGeneratedName,element,parserContext);
+ return builder.getBeanDefinition();
+ }
+
+ protected abstract Class extends MessageHandler> getMessageHandlerImplementation();
+
+ /**
+ * The subclasses can override this method to set additional attributes and perform some
+ * additional operations on the {@link BeanDefinitionBuilder}
+ *
+ * @param builder
+ * @param awsCredentialsGeneratedName
+ * @param element
+ * @param context
+ */
+ protected void processBeanDefinition(BeanDefinitionBuilder builder,String awsCredentialsGeneratedName,
+ Element element,ParserContext context) {
+ //Default implementation does nothing
+ }
+
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AmazonWSParserUtils.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AmazonWSParserUtils.java
new file mode 100644
index 0000000..974550e
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/config/xml/AmazonWSParserUtils.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.config.xml;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.integration.aws.core.BasicAWSCredentials;
+import org.springframework.integration.aws.core.PropertiesAWSCredentials;
+import org.springframework.util.StringUtils;
+import org.w3c.dom.Element;
+
+/**
+ * The utility class for the namespace parsers
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public final class AmazonWSParserUtils {
+
+ public static final String ACCESS_KEY = "accessKey";
+ public static final String SECRET_KEY = "secretKey";
+ public static final String PROPERTIES_FILE = "propertiesFile";
+ public static final String CREDENTIALS_REF = "credentials-ref";
+
+ private AmazonWSParserUtils() {
+ throw new AssertionError("Cannot instantiate the utility class");
+ }
+
+
+ /**
+ * Registers the {@link AmazonWSCredentials} bean with the current ApplicationContext if
+ * accessKey and secretKey is given, if the credentials-ref is given, the given value
+ * is returned.
+ *
+ * @param element
+ * @param parserContext
+ * @return
+ */
+ public static String getAmazonWSCredentials(Element element,ParserContext parserContext) {
+ //TODO: Some mechanism to use the same instance with same ACCESS_KEY to be implemented
+ String accessKey = element.getAttribute(ACCESS_KEY);
+ String secretKey = element.getAttribute(SECRET_KEY);
+ String propertiesFile = element.getAttribute(PROPERTIES_FILE);
+ String credentialsRef = element.getAttribute(CREDENTIALS_REF);
+ String awsCredentialsGeneratedName;
+
+ if(StringUtils.hasText(credentialsRef)) {
+ if(StringUtils.hasText(propertiesFile)
+ || StringUtils.hasText(accessKey)
+ || StringUtils.hasText(secretKey)) {
+ parserContext.getReaderContext().error("When " + CREDENTIALS_REF + " is specified, " +
+ "do not specify the " + PROPERTIES_FILE + " attribute or the "
+ + SECRET_KEY + " and " + ACCESS_KEY + " attributes", element);
+ }
+ awsCredentialsGeneratedName = credentialsRef;
+ }
+ else {
+ if(StringUtils.hasText(propertiesFile)) {
+ if(StringUtils.hasText(accessKey) && StringUtils.hasText(secretKey)) {
+ parserContext.getReaderContext().error("When " + ACCESS_KEY + " and " + SECRET_KEY +
+ " are specified, do not specify the " + PROPERTIES_FILE + " attribute", element);
+ }
+
+ BeanDefinitionBuilder builder =
+ BeanDefinitionBuilder.genericBeanDefinition(PropertiesAWSCredentials.class);
+ builder.addConstructorArgValue(propertiesFile);
+ awsCredentialsGeneratedName = BeanDefinitionReaderUtils.registerWithGeneratedName(
+ builder.getBeanDefinition(), parserContext.getRegistry());
+ } else {
+ BeanDefinitionBuilder builder
+ = BeanDefinitionBuilder.genericBeanDefinition(BasicAWSCredentials.class);
+ builder.addConstructorArgValue(accessKey);
+ builder.addConstructorArgValue(secretKey);
+ awsCredentialsGeneratedName = BeanDefinitionReaderUtils.registerWithGeneratedName(
+ builder.getBeanDefinition(), parserContext.getRegistry());
+
+ }
+ }
+
+ return awsCredentialsGeneratedName;
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSClientFactory.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSClientFactory.java
new file mode 100644
index 0000000..1c74cbe
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSClientFactory.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+import com.amazonaws.AmazonWebServiceClient;
+
+/**
+ * The factory interface that would be used to get the implementation of the appropriate
+ * instance of {@link AmazonWebServiceClient}
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public interface AWSClientFactory {
+
+ /**
+ * Returns the instance of the {@link AmazonWebServiceClient} with the apropriate endpoint value
+ * set based on the provided url value
+ *
+ * @param url The url of the service
+ * @return The appropriate {@link AmazonWebServiceClient} for the provided endpoint URL
+ */
+ T getClient(String url);
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSCredentials.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSCredentials.java
new file mode 100644
index 0000000..664f231
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSCredentials.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+/**
+ * The common interfaces for all implementations of Amazon WS Credentials
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public interface AWSCredentials {
+
+ /**
+ * Get the Access key to the Amazon WS account
+ * @return
+ */
+ public String getAccessKey();
+
+ /**
+ * Get the Secret key to the Amazon WS account
+ * @return
+ */
+ public String getSecretKey();
+
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSOperationException.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSOperationException.java
new file mode 100644
index 0000000..1b9035d
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AWSOperationException.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+/**
+ * The Base class for all other AWS operation exceptions
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class AWSOperationException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3391888045993691634L;
+
+ private final String accessKey;
+
+ public AWSOperationException(String accessKey) {
+ super();
+ this.accessKey = accessKey;
+ }
+
+ public AWSOperationException(String accessKey,String message) {
+ super(message);
+ this.accessKey = accessKey;
+ }
+
+ public AWSOperationException(String accessKey,String message, Throwable cause) {
+ super(message, cause);
+ this.accessKey = accessKey;
+ }
+
+ public AWSOperationException(String accessKey,Throwable cause) {
+ super(cause);
+ this.accessKey = accessKey;
+ }
+
+ /**
+ * Get the access key for the user who encountered the exception
+ * @return
+ */
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+
+
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AbstractAWSClientFactory.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AbstractAWSClientFactory.java
new file mode 100644
index 0000000..e630607
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/AbstractAWSClientFactory.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
+
+import com.amazonaws.AmazonWebServiceClient;
+
+
+/**
+ * The abstract factory class that will be used by all the client operations to acquire
+ * the appropriate implementation of the {@link AmazonWebServiceClient} based on the URL
+ * passed to the getClient method
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public abstract class AbstractAWSClientFactory implements AWSClientFactory {
+
+ /**
+ * A map storing the {@link AmazonWebServiceClient} endpoint as the key and the SQS Client as the
+ * value. Since setting the endpoint is not a thread safe operation once the client is instantiated,
+ * we maintain a map of endpoint and the {@link AmazonWebServiceClient} instantiated the first time a request
+ * for the designated endpoint is received
+ */
+ private final ConcurrentHashMap clientMap = new ConcurrentHashMap();
+
+ /**
+ * The String constant for HTTP
+ */
+ protected final static String HTTP = "http://";
+
+ /**
+ * The String constant for HTTPS
+ */
+ protected final static String HTTPS = "https://";
+
+ /**
+ * The String constant for SMTP
+ */
+ protected final String SMTP = "smtp://";
+
+ /**
+ * The default protocol to be used in case none is provided
+ */
+ protected final static String DEFAULT_PROTOCOL = HTTPS;
+
+
+ /**
+ * Returns the cached implementation of the {@link AmazonWebServiceClient} based on the URL provided.
+ * the client instance is acquired using the abstract getClientImplementation method.
+ * The instance is added to the client map with the endpoint string as the key and the
+ * {@link AmazonWebServiceClient} as the value.
+ *
+ * @param url the URL for which the client is requested.
+ * @return the implementation of the {@link AmazonWebServiceClient} to be used for the provided url
+ */
+ public final T getClient(String url) {
+ String endpoint = getEndpointFromURL(url);
+ if(!clientMap.containsKey(endpoint)) {
+ T client = getClientImplementation();
+ client.setEndpoint(endpoint);
+ T existingClient = clientMap.putIfAbsent(endpoint, client);
+ if(existingClient != null) {
+ //in rare scenarios where a new implementation was created after
+ //checking for the existence of the endpoint in the client map
+ client = existingClient;
+ }
+ return client;
+ } else
+ return clientMap.get(endpoint);
+ }
+
+ /**
+ * Return a copy of the client map
+ * @return the copy of the clientMap
+ */
+ public final Map getClientMap() {
+ return new HashMap(clientMap);
+ }
+
+ /**
+ * Clears the complete cache
+ */
+ public final void clear() {
+ clientMap.clear();
+ }
+
+ /**
+ * Extracts the endpoint from the URL provided
+ *
+ * @param url
+ * @return
+ */
+ private String getEndpointFromURL(String stringUrl) {
+ Assert.notNull(stringUrl,"Provided String URL is null");
+ String endpoint;
+ try {
+ if(!(stringUrl.startsWith(HTTP)
+ || stringUrl.startsWith(HTTPS)
+ || stringUrl.startsWith(SMTP))) {
+ stringUrl = DEFAULT_PROTOCOL + stringUrl;
+ }
+ URL url = new URL(stringUrl);
+ String host = url.getHost();
+ String protocol = url.getProtocol();
+ if(StringUtils.hasText(protocol)) {
+ endpoint = protocol + "://" + host;
+ }
+ else {
+ endpoint = host;
+ }
+ } catch (MalformedURLException e) {
+ throw new AWSOperationException(null, "The URL \"" + stringUrl + "\" is malformed",e);
+ }
+ return endpoint;
+ }
+
+ /**
+ * The subclass needs to implement this method and return an appropriate implementation
+ * @return
+ */
+ protected abstract T getClientImplementation();
+
+
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/BasicAWSCredentials.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/BasicAWSCredentials.java
new file mode 100644
index 0000000..69cebea
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/BasicAWSCredentials.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+/**
+ * The basic implementation class holding the Access key and the secret
+ * key for the AWS account .
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class BasicAWSCredentials implements AWSCredentials {
+
+ /**.
+ * Hold the Access key for the AWS account
+ */
+ private String accessKey;
+
+ /**.
+ * Hold the Secret key for the
+ */
+ private String secretKey;
+
+
+ /**.
+ * Default constructor
+ */
+ public BasicAWSCredentials() {
+
+ }
+
+ /**.
+ * The constructor accepting the access and secret key
+ * @param accessKey
+ * @param secretKey
+ */
+ public BasicAWSCredentials(String accessKey, String secretKey) {
+ super();
+ this.accessKey = accessKey;
+ this.secretKey = secretKey;
+ }
+
+ /**
+ * Get the Access key to the Amazon WS account
+ * @return
+ */
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ /**
+ * Set the Access key to the Amazon WS account
+ * @param accessKey
+ */
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ /**
+ * Get the Secret key to the Amazon WS account
+ * @return
+ */
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ /**.
+ * Set the Secret key to the Amazon WS account
+ * @param secretKey
+ */
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/InvalidAWSCredentialsException.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/InvalidAWSCredentialsException.java
new file mode 100644
index 0000000..408c916
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/InvalidAWSCredentialsException.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+/**
+ * Thrown when AWS Credentials provided by the user are incomplete or invalid
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class InvalidAWSCredentialsException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public InvalidAWSCredentialsException() {
+ super();
+ }
+
+ public InvalidAWSCredentialsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidAWSCredentialsException(String message) {
+ super(message);
+ }
+
+ public InvalidAWSCredentialsException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/PropertiesAWSCredentials.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/PropertiesAWSCredentials.java
new file mode 100644
index 0000000..2f2ef39
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/core/PropertiesAWSCredentials.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.core;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
+import org.springframework.util.StringUtils;
+
+/**
+ * Load the AWS credentials from the .properties file
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class PropertiesAWSCredentials extends BasicAWSCredentials implements InitializingBean {
+
+
+ public static final String DEFAULT_AWS_ACCESS_KEY_PROPERTY = "accessKey";
+ public static final String DEFAULT_AWS_SECRET_KEY_PROPERTY = "secretKey";
+
+ private String accessKeyProperty = DEFAULT_AWS_ACCESS_KEY_PROPERTY;
+ private String secretKeyProperty = DEFAULT_AWS_SECRET_KEY_PROPERTY;
+ private String propertyFileName;
+
+ /**.
+ * Constructor accepting the properties file
+ * @param propertyFileName
+ */
+ public PropertiesAWSCredentials(String propertyFileName) {
+ super();
+ this.propertyFileName = propertyFileName;
+ }
+
+ /**.
+ * Gets the property name which holds the
+ * @return
+ */
+ public String getAccessKeyProperty() {
+ return accessKeyProperty;
+ }
+
+ /**.
+ * Sets the name of the property that will be used as the key in the properties
+ * file to hold the AWS access key
+ * @param accessKeyProperty
+ */
+ public void setAccessKeyProperty(String accessKeyProperty) {
+ this.accessKeyProperty = accessKeyProperty;
+ }
+
+ /**.
+ * Gets the property name which holds the
+ * @return
+ */
+ public String getSecretKeyProperty() {
+ return secretKeyProperty;
+ }
+
+ /**.
+ * Sets the name of the property that will be used as the key in the properties
+ * file to hold the AWS secret key
+ * @param accessKeyProperty
+ */
+ public void setSecretKeyProperty(String secretKeyProperty) {
+ this.secretKeyProperty = secretKeyProperty;
+ }
+
+ /**.
+ * Get the name of the property file that will hold the AWS credentials
+ * @return
+ */
+ public String getPropertyFileName() {
+ return propertyFileName;
+ }
+
+ /**.
+ * Sets the name of the file that will hold the AW credentials
+ * @param propertyFileName
+ */
+ public void setPropertyFileName(String propertyFileName) {
+ this.propertyFileName = propertyFileName;
+ }
+
+ /**.
+ * Load the properties file and the keys
+ */
+ public void afterPropertiesSet() throws Exception {
+ if (!StringUtils.hasText(propertyFileName))
+ throw new InvalidAWSCredentialsException("Mandatory property propertyFileName expected");
+
+ if(!StringUtils.hasText(accessKeyProperty))
+ throw new InvalidAWSCredentialsException("accessKeyValue has to be non empty and non null");
+
+ if(!StringUtils.hasText(secretKeyProperty))
+ throw new InvalidAWSCredentialsException("secretKeyValue has to be non empty and non null");
+
+ loadProperties();
+
+ }
+
+ /**.
+ * The private method that loads the properties from the .properties file and sets the access keys
+ */
+ private void loadProperties() {
+ Resource resource;
+ if(propertyFileName.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ resource = new ClassPathResource(propertyFileName.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), ClassUtils.getDefaultClassLoader());
+ } else {
+ resource = new ClassPathResource(propertyFileName, ClassUtils.getDefaultClassLoader());
+ }
+ if(!resource.exists())
+ throw new InvalidAWSCredentialsException("Unable to find resource \"" + propertyFileName + "\" in classpath");
+
+ Properties props = new Properties();
+ try {
+ props.load(resource.getInputStream());
+ } catch (IOException e) {
+ throw new InvalidAWSCredentialsException("Unable to load properties from \"" + propertyFileName + "\" in classpath");
+ }
+
+ setAccessKey((String)props.get(accessKeyProperty));
+ setSecretKey((String)props.get(secretKeyProperty));
+
+
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/AmazonSESMessageHandler.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/AmazonSESMessageHandler.java
new file mode 100644
index 0000000..0403c7d
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/AmazonSESMessageHandler.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.ses;
+
+import org.springframework.integration.aws.core.AWSCredentials;
+import org.springframework.integration.aws.ses.core.DefaultAmazonSESMailSender;
+import org.springframework.integration.mail.MailSendingMessageHandler;
+import org.springframework.mail.javamail.JavaMailSender;
+
+/**
+ * The Message handler for the SES Mail. This will be used to send email
+ * using Amazon SES
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class AmazonSESMessageHandler extends MailSendingMessageHandler {
+
+ /**
+ * The Default constructor that extends from the {@link MailSendingMessageHandler} and passes
+ * it an instance of {@link DefaultAmazonSESMailSender}
+ * @param credentials
+ */
+ public AmazonSESMessageHandler(AWSCredentials credentials) {
+ super(new DefaultAmazonSESMailSender(credentials));
+ }
+
+ /**
+ * The constructor that accepts the {@link JavaMailSender} instance, used for
+ * unit tests only
+ * @param mailSender
+ */
+ AmazonSESMessageHandler(JavaMailSender mailSender) {
+ super(mailSender);
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/config/xml/AmazonSESOutboundAdapterParser.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/config/xml/AmazonSESOutboundAdapterParser.java
new file mode 100644
index 0000000..8ea1cae
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/config/xml/AmazonSESOutboundAdapterParser.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.ses.config.xml;
+
+
+import org.springframework.integration.aws.config.xml.AbstractAWSOutboundChannelAdapterParser;
+import org.springframework.integration.aws.ses.AmazonSESMessageHandler;
+import org.springframework.integration.core.MessageHandler;
+
+/**
+ * parse the <ses-outbound-channel-adapter/> of the "int-aws" namespace
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class AmazonSESOutboundAdapterParser extends
+ AbstractAWSOutboundChannelAdapterParser {
+
+
+ @Override
+ public Class extends MessageHandler> getMessageHandlerImplementation() {
+ return AmazonSESMessageHandler.class;
+ }
+}
diff --git a/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/core/AmazonSESMailSendException.java b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/core/AmazonSESMailSendException.java
new file mode 100644
index 0000000..a28018a
--- /dev/null
+++ b/spring-integration-aws/src/main/java/org/springframework/integration/aws/ses/core/AmazonSESMailSendException.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.aws.ses.core;
+
+import java.util.Map;
+
+import org.springframework.integration.aws.core.AWSOperationException;
+
+/**
+ * This exception will be thrown upon failure in sending a mail from Amazon SES
+ *
+ * @author Amol Nayak
+ *
+ * @since 1.0
+ *
+ */
+public class AmazonSESMailSendException extends AWSOperationException {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3035267174544370619L;
+
+ private final Map