INTEXT-136: Make based on Spring Cloud AWS
JIRA: https://jira.spring.io/browse/INTEXT-136 * Add `spring-cloud-aws` dependencies * Remove all SES stuff, since Spring Cloud AWS provides implementations for `org.springframework.mail.MailSender`
This commit is contained in:
128
README.md
128
README.md
@@ -5,9 +5,15 @@ Spring Integration Extension for Amazon Web Services (AWS)
|
||||
|
||||
## Amazon Web Services (AWS)
|
||||
|
||||
Launched in 2006, [Amazon Web Services][] (AWS) provides key infrastructure services for business through its cloud computing platform. 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.
|
||||
Launched in 2006, [Amazon Web Services][] (AWS) provides key infrastructure services for business through
|
||||
its cloud computing platform. 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.
|
||||
|
||||
*Spring Integration Extension for Amazon Web Services* provides Spring Integration adapters for the various services provided by the [AWS SDK for Java][].
|
||||
*Spring Integration Extension for Amazon Web Services* provides Spring Integration adapters for the various services
|
||||
provided by the [AWS SDK for Java][].
|
||||
Note the Spring Integration AWS Extension is based on the [Spring Cloud AWS][] project.
|
||||
|
||||
## Spring Integration's extensions to AWS
|
||||
|
||||
@@ -20,22 +26,35 @@ This guide intends to explain briefly the various adapters available for [Amazon
|
||||
* **Amazon SimpleDB** (Not initiated)
|
||||
* **Amazon SNS** (Not initiated)
|
||||
|
||||
Sample XML Namespace configurations for each adapter as well as sample code snippets are provided wherever necessary. Of the above libraries, *SES* and *SNS* provide 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.
|
||||
Sample XML Namespace configurations for each adapter as well as sample code snippets are provided wherever necessary.
|
||||
Of the above libraries, *SES* and *SNS* provide 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*, besides providing *Inbound*- and *Outbound Adapters*, a *MessageStore* implementation is provided, too.
|
||||
For *DymamoDB* and *SimpleDB*, besides providing *Inbound*- and *Outbound Adapters*,
|
||||
a *MessageStore* implementation is provided, too.
|
||||
|
||||
# Executing the test cases.
|
||||
|
||||
All 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.
|
||||
All test cases for the adapters are present in the *src/test/java* folder. On executing the build, maven surefire
|
||||
plugin will execute all the tests.
|
||||
|
||||
> Please note that all the tests ending with **AWSTests.java* connect to the actual [Amazon Web Services][] 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* manually to test the connectivity to AWS using your credentials.
|
||||
> Please note that all the tests ending with **AWSTests.java* connect to the actual [Amazon Web Services][]
|
||||
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* manually to test the connectivity to AWS using your credentials.
|
||||
|
||||
All these **AWSTests.java* tests look for the file *awscredentials.properties* in the classpath. To be on the safe side, create the following file at *src/test/resources*:
|
||||
*spring-integration-aws/src/test/resources/awscredentials.properties*. It is added to the *.gitignore* file by default. This will prevent this file to be checked in accidentally and revealing your credentials.
|
||||
All these **AWSTests.java* tests look for the file *awscredentials.properties* in the classpath.
|
||||
To be on the safe side, create the following file at *src/test/resources*:
|
||||
*spring-integration-aws/src/test/resources/awscredentials.properties*. It is added to the *.gitignore* file by default.
|
||||
This will prevent this file to be checked in accidentally 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.
|
||||
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/][]**
|
||||
> **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
|
||||
|
||||
@@ -48,93 +67,14 @@ This file needs to have two properties *accessKey* and *secretKey*, holding the
|
||||
|
||||
##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
|
||||
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
<int-aws-ses:outbound-channel-adapter
|
||||
propertiesFile="classpath:awscredentials.properties"
|
||||
channel="outboundAdapterChannel"/>
|
||||
|
||||
|
||||
*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.
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
<int-aws-ses:outbound-channel-adapter
|
||||
accessKey="{your access key}"
|
||||
secreKey="{your secret key}"
|
||||
channel="outboundAdapterChannel"/>
|
||||
|
||||
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<String, Object> headers = new HashMap<String, Object>();
|
||||
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<String> msg =
|
||||
MessageBuilder.withPayload("<html><i>A Simple Mail Message sent from " +
|
||||
"Amazon SES Outbound adapter from Spring integration<i></html>")
|
||||
.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("<File path to the attachment>"));
|
||||
helper.setSubject("Name Pic");
|
||||
Message<MimeMessage> 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.
|
||||
There is no adapter for SES, since [Spring Cloud AWS][] provides implementations for
|
||||
`org.springframework.mail.MailSender` - `SimpleEmailServiceMailSender` and `SimpleEmailServiceJavaMailSender`, which
|
||||
can be injected to the `<int-mail:outbound-channel-adapter>`.
|
||||
|
||||
[Spring Cloud AWS]: https://github.com/spring-cloud/spring-cloud-aws
|
||||
[AWS SDK for Java]: http://aws.amazon.com/sdkforjava/
|
||||
[Amazon Web Services]: http://aws.amazon.com/
|
||||
[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/
|
||||
[http://aws.amazon.com/free/]: http://aws.amazon.com/free/
|
||||
|
||||
33
build.gradle
33
build.gradle
@@ -28,23 +28,19 @@ configurations {
|
||||
}
|
||||
|
||||
ext {
|
||||
apacheHttpclientVersion='4.3.4'
|
||||
apacheHttpCoreVersion='4.3.2'
|
||||
awsSdkVersion='1.8.7'
|
||||
commonsCodecVersion='1.9'
|
||||
commonsIoVersion='2.0.1'
|
||||
javaMailVersion='1.5.2'
|
||||
jacksonVersion='1.9.11'
|
||||
springIntegrationVersion = '4.0.3.RELEASE'
|
||||
commonsIoVersion='2.4'
|
||||
jacocoVersion = '0.7.1.201405082137'
|
||||
springCloudAwsVersion = '1.0.0.RC2'
|
||||
springIntegrationVersion = '4.1.2.RELEASE'
|
||||
|
||||
idPrefix = 'aws'
|
||||
|
||||
linkHomepage = 'https://github.com/spring-projects/spring-integration-extensions'
|
||||
linkHomepage = 'https://github.com/spring-projects/spring-integration-aws'
|
||||
linkCi = 'https://build.spring.io/browse/INTEXT'
|
||||
linkIssue = 'https://jira.spring.io/browse/INTEXT'
|
||||
linkScmUrl = 'https://github.com/spring-projects/spring-integration-extensions'
|
||||
linkScmConnection = 'https://github.com/spring-projects/spring-integration-extensions.git'
|
||||
linkScmDevConnection = 'git@github.com:spring-projects/spring-integration-extensions.git'
|
||||
linkScmUrl = 'https://github.com/spring-projects/spring-integration-aws'
|
||||
linkScmConnection = 'https://github.com/spring-projects/spring-integration-aws.git'
|
||||
linkScmDevConnection = 'git@github.com:spring-projects/spring-integration-aws.git'
|
||||
}
|
||||
|
||||
ext.javadocLinks = [
|
||||
@@ -55,21 +51,12 @@ ext.javadocLinks = [
|
||||
dependencies {
|
||||
|
||||
compile "org.springframework.integration:spring-integration-core:$springIntegrationVersion"
|
||||
compile "com.amazonaws:aws-java-sdk:$awsSdkVersion"
|
||||
compile "commons-codec:commons-codec:$commonsCodecVersion"
|
||||
compile "org.springframework.cloud:spring-cloud-aws-messaging:$springCloudAwsVersion"
|
||||
compile "commons-io:commons-io:$commonsIoVersion"
|
||||
compile "org.codehaus.jackson:jackson-core-asl:$jacksonVersion"
|
||||
compile "org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion"
|
||||
compile "org.apache.httpcomponents:httpclient:$apacheHttpclientVersion"
|
||||
compile "org.apache.httpcomponents:httpcore:$apacheHttpCoreVersion"
|
||||
|
||||
//Amazon SES Support
|
||||
compile ("org.springframework.integration:spring-integration-mail:$springIntegrationVersion", optional)
|
||||
compile ("javax.mail:javax.mail-api:$javaMailVersion", optional)
|
||||
|
||||
testCompile "org.springframework.integration:spring-integration-test:$springIntegrationVersion"
|
||||
|
||||
jacoco group: "org.jacoco", name: "org.jacoco.agent", version: "0.7.1.201405082137", classifier: "runtime"
|
||||
jacoco "org.jacoco:org.jacoco.agent:$jacocoVersion:runtime"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
version=0.5.0.BUILD-SNAPSHOT
|
||||
version=1.0.0.BUILD-SNAPSHOT
|
||||
|
||||
@@ -31,7 +31,7 @@ def customizePom(pom, gradleProject) {
|
||||
generatedPom.project {
|
||||
name = gradleProject.description
|
||||
description = gradleProject.description
|
||||
url = 'https://github.com/SpringSource/spring-integration-extensions'
|
||||
url = 'https://github.com/spring-projects/spring-integration-aws'
|
||||
organization {
|
||||
name = 'SpringSource'
|
||||
url = 'http://springsource.org'
|
||||
@@ -44,9 +44,9 @@ def customizePom(pom, gradleProject) {
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/SpringSource/spring-integration-extensions'
|
||||
connection = 'scm:git:git://github.com/SpringSource/spring-integration-extensions'
|
||||
developerConnection = 'scm:git:git://github.com/SpringSource/spring-integration-extensions'
|
||||
url = 'https://github.com/spring-projects/spring-integration-aws'
|
||||
connection = 'scm:git:git://github.com/spring-projects/spring-integration-aws'
|
||||
developerConnection = 'scm:git:git://github.com/spring-projects/spring-integration-aws'
|
||||
}
|
||||
|
||||
developers {
|
||||
@@ -58,7 +58,12 @@ def customizePom(pom, gradleProject) {
|
||||
developer {
|
||||
id = 'ghillert'
|
||||
name = 'Gunnar Hillert'
|
||||
email = 'ghillert@vmware.com'
|
||||
email = 'ghillert@pivotal.io'
|
||||
}
|
||||
developer {
|
||||
id = 'abilan'
|
||||
name = 'Artem Bilan'
|
||||
email = 'abilan@pivotal.io'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -17,24 +17,19 @@ package org.springframework.integration.aws.config.xml;
|
||||
|
||||
import org.springframework.integration.aws.s3.config.xml.AmazonS3InboundChannelAdapterParser;
|
||||
import org.springframework.integration.aws.s3.config.xml.AmazonS3OutboundChannelAdapterParser;
|
||||
import org.springframework.integration.aws.ses.config.xml.AmazonSESOutboundAdapterParser;
|
||||
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
|
||||
|
||||
/**
|
||||
* The namespace handler for "int-aws" namespace
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
public class AWSNamespaceHandler extends
|
||||
AbstractIntegrationNamespaceHandler {
|
||||
public class AWSNamespaceHandler extends AbstractIntegrationNamespaceHandler {
|
||||
|
||||
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("ses-outbound-channel-adapter", new AmazonSESOutboundAdapterParser());
|
||||
this.registerBeanDefinitionParser("s3-outbound-channel-adapter",new AmazonS3OutboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("s3-outbound-channel-adapter", new AmazonS3OutboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("s3-inbound-channel-adapter", new AmazonS3InboundChannelAdapterParser());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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 0.5
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.messaging.MessageHandler;
|
||||
|
||||
/**
|
||||
* parse the <ses-outbound-channel-adapter/> of the "int-aws" namespace
|
||||
*
|
||||
* @author Amol Nayak
|
||||
* @author Rob Harrop
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
public class AmazonSESOutboundAdapterParser extends
|
||||
AbstractAWSOutboundChannelAdapterParser {
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends MessageHandler> getMessageHandlerImplementation() {
|
||||
return AmazonSESMessageHandler.class;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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 0.5
|
||||
*
|
||||
*/
|
||||
public class AmazonSESMailSendException extends AWSOperationException {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3035267174544370619L;
|
||||
|
||||
private final Map<Object, Exception> failedMessages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param accessKey
|
||||
* @param message
|
||||
* @param cause
|
||||
* @param failedMessages
|
||||
*/
|
||||
public AmazonSESMailSendException(String accessKey, String message,
|
||||
Throwable cause,Map<Object, Exception> failedMessages) {
|
||||
super(accessKey, message, cause);
|
||||
this.failedMessages = failedMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param accessKey
|
||||
* @param message
|
||||
* @param failedMessages
|
||||
*/
|
||||
public AmazonSESMailSendException(String accessKey,
|
||||
String message,Map<Object, Exception> failedMessages) {
|
||||
super(accessKey, message);
|
||||
this.failedMessages = failedMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param accessKey
|
||||
* @param cause
|
||||
* @param failedMessages
|
||||
*/
|
||||
public AmazonSESMailSendException(String accessKey,
|
||||
Throwable cause,Map<Object, Exception> failedMessages) {
|
||||
super(accessKey, cause);
|
||||
this.failedMessages = failedMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param accessKey
|
||||
* @param failedMessages
|
||||
*/
|
||||
public AmazonSESMailSendException(String accessKey,Map<Object, Exception> failedMessages) {
|
||||
super(accessKey);
|
||||
this.failedMessages = failedMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map of failed messages where the failed message is the key and the exception
|
||||
* while sending it is the value
|
||||
*/
|
||||
public Map<Object, Exception> getFailedMessages() {
|
||||
return failedMessages;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* 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.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.NoSuchProviderException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.integration.aws.core.AWSCredentials;
|
||||
import org.springframework.integration.aws.core.AWSOperationException;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessagePreparator;
|
||||
|
||||
import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
|
||||
|
||||
/**
|
||||
* The implementation class for sending mail using the Amazon SES service
|
||||
*
|
||||
* @author Amol Nayak
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
public class DefaultAmazonSESMailSender implements JavaMailSender {
|
||||
|
||||
public DefaultAmazonSESMailSender(AWSCredentials credentials) {
|
||||
|
||||
if(credentials == null) {
|
||||
throw new AWSOperationException(null, "Credentials cannot be null, provide a non null valid set of credentials");
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup JavaMail to use the Amazon Simple Email Service by specifying
|
||||
* the "aws" protocol.
|
||||
*/
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("mail.transport.protocol", "aws");
|
||||
|
||||
properties.setProperty(AWSJavaMailTransport.AWS_ACCESS_KEY_PROPERTY, credentials.getAccessKey());
|
||||
properties.setProperty(AWSJavaMailTransport.AWS_SECRET_KEY_PROPERTY, credentials.getSecretKey());
|
||||
|
||||
javaMailSender.setJavaMailProperties(properties);
|
||||
|
||||
}
|
||||
|
||||
private JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl() {
|
||||
|
||||
@Override
|
||||
protected Transport getTransport(Session session)
|
||||
throws NoSuchProviderException {
|
||||
return new AWSJavaMailTransport(session, null);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void send(SimpleMailMessage simpleMessage) throws MailException {
|
||||
javaMailSender.send(simpleMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(SimpleMailMessage[] simpleMessages) throws MailException {
|
||||
javaMailSender.send(simpleMessages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MimeMessage createMimeMessage() {
|
||||
return javaMailSender.createMimeMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MimeMessage createMimeMessage(InputStream contentStream)
|
||||
throws MailException {
|
||||
return javaMailSender.createMimeMessage(contentStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MimeMessage mimeMessage) throws MailException {
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MimeMessage[] mimeMessages) throws MailException {
|
||||
javaMailSender.send(mimeMessages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MimeMessagePreparator mimeMessagePreparator)
|
||||
throws MailException {
|
||||
javaMailSender.send(mimeMessagePreparator);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MimeMessagePreparator[] mimeMessagePreparators)
|
||||
throws MailException {
|
||||
javaMailSender.send(mimeMessagePreparators);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,48 +62,6 @@
|
||||
</xsd:attribute>
|
||||
</xsd:attributeGroup>
|
||||
|
||||
<xsd:element name="ses-outbound-channel-adapter">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an outbound mail-sending Channel Adapter for sending mails using Amazon SES.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
Identifies channel attached to this adapter. This is the channel over which
|
||||
the SES outbound adapter will receive messages from. The received message
|
||||
will then be converted to the email to be sent.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attributeGroup ref="awsAdaptersCommonAttributes"/>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Lifecycle attribute signaling if this component should be started during
|
||||
Application Context startup. Default is 'true'
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
<xsd:attribute name="order">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specifies the order for invocation when this endpoint is connected as a
|
||||
subscriber to a SubscribableChannel.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="s3-outbound-channel-adapter">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -262,6 +220,7 @@
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="s3-inbound-channel-adapter">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -388,4 +347,5 @@
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
|
||||
</xsd:schema>
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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 static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.integration.mail.MailHeaders.BCC;
|
||||
import static org.springframework.integration.mail.MailHeaders.CC;
|
||||
import static org.springframework.integration.mail.MailHeaders.FROM;
|
||||
import static org.springframework.integration.mail.MailHeaders.SUBJECT;
|
||||
import static org.springframework.integration.mail.MailHeaders.TO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
|
||||
|
||||
/**
|
||||
* The test class for {@link AmazonSESMessageHandler}
|
||||
*
|
||||
* @author Amol Nayak
|
||||
* @author Rob Harrop
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
public class AmazonSESMessageHandlerTests {
|
||||
|
||||
private static final List<SimpleMailMessage> messages = new ArrayList<SimpleMailMessage>();
|
||||
private static final List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>();
|
||||
private static AmazonSESMessageHandler handler;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupAmazonSESMailSender() {
|
||||
JavaMailSender sender = mock(JavaMailSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
messages.add((SimpleMailMessage)args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(SimpleMailMessage.class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
messages.addAll(Arrays.asList((SimpleMailMessage[])args));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(SimpleMailMessage[].class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
mimeMessages.addAll(Arrays.asList((MimeMessage[])args));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(MimeMessage[].class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
mimeMessages.add((MimeMessage)args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(MimeMessage.class));
|
||||
handler = new AmazonSESMessageHandler(sender);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
messages.clear();
|
||||
mimeMessages.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
*Test case for sending a message with subject line of unexpected type
|
||||
*{@link AmazonSESSimpleMailMessage}
|
||||
*
|
||||
*/
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void withIncorrectSubjectClass() {
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload("Test")
|
||||
.setHeader(SUBJECT, Arrays.asList("Some Header"))
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test case where the message text used of incorrect type
|
||||
*
|
||||
*/
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void withIncorrectMessageTextClass() {
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload(Arrays.asList("Content"))
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
}
|
||||
|
||||
//Test case to check if from id exists or not cant work now as MailSendingMessageHandler
|
||||
//doesn't check if from is present or not
|
||||
|
||||
/**
|
||||
* With all the details
|
||||
*/
|
||||
@Test
|
||||
public void withAllTheDetails() {
|
||||
clear();
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload("Test Content")
|
||||
.setHeader(TO, "to@to.com")
|
||||
.setHeader(BCC, "bcc@bcc.com")
|
||||
.setHeader(CC, "cc@cc.com")
|
||||
.setHeader(SUBJECT, "Test Subject")
|
||||
.setHeader(FROM, "from@from.com")
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
SimpleMailMessage message = messages.get(0);
|
||||
String[] to = message.getTo();
|
||||
Assert.assertNotNull(to);
|
||||
Assert.assertEquals(1,to.length);
|
||||
Assert.assertEquals("to@to.com", to[0]);
|
||||
|
||||
String[] cc = message.getCc();
|
||||
Assert.assertNotNull(cc);
|
||||
Assert.assertEquals(1,cc.length);
|
||||
Assert.assertEquals("cc@cc.com", cc[0]);
|
||||
|
||||
String[] bcc = message.getBcc();
|
||||
Assert.assertNotNull(bcc);
|
||||
Assert.assertEquals(1,bcc.length);
|
||||
Assert.assertEquals("bcc@bcc.com", bcc[0]);
|
||||
|
||||
Assert.assertEquals("from@from.com",message.getFrom());
|
||||
Assert.assertEquals("Test Subject",message.getSubject());
|
||||
Assert.assertEquals("Test Content", message.getText());
|
||||
}
|
||||
|
||||
//Might need to uncomment this test later when we start allowing null in TO email id of
|
||||
//spring-int-mail
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// @Test
|
||||
// public void withAllMultipleToBccAndCC() {
|
||||
// clear();
|
||||
// Message<?> testMessage = MessageBuilder
|
||||
// .withPayload("Test Content")
|
||||
// .setHeader(TO,
|
||||
// Arrays.asList("to1@to.com","to2@to.com"))
|
||||
// .setHeader(BCC,
|
||||
// Arrays.asList("bcc1@bcc.com","bcc2@bcc.com"))
|
||||
// .setHeader(CC,
|
||||
// Arrays.asList("cc1@cc.com","cc2@cc.com"))
|
||||
// .setHeader(SUBJECT, "Test Subject")
|
||||
// .setHeader(FROM, "from@from.com")
|
||||
// .build();
|
||||
// handler.handleMessage(testMessage);
|
||||
// SimpleMailMessage message = messages.get(0);
|
||||
// String[] to = message.getTo();
|
||||
// Assert.assertNotNull(to);
|
||||
// Assert.assertEquals(2,to.length);
|
||||
// Assert.assertEquals("to1@to.com", to[0]);
|
||||
// Assert.assertEquals("to2@to.com", to[1]);
|
||||
//
|
||||
// String[] cc = message.getCc();
|
||||
// Assert.assertNotNull(cc);
|
||||
// Assert.assertEquals(2,cc.length);
|
||||
// Assert.assertEquals("cc1@cc.com", cc[0]);
|
||||
// Assert.assertEquals("cc2@cc.com", cc[1]);
|
||||
//
|
||||
// String[] bcc = message.getBcc();
|
||||
// Assert.assertEquals(2,bcc.length);
|
||||
// Assert.assertEquals("bcc1@bcc.com", bcc[0]);
|
||||
// Assert.assertEquals("bcc2@bcc.com", bcc[1]);
|
||||
//
|
||||
// Assert.assertEquals("from@from.com",message.getFrom());
|
||||
//
|
||||
// Assert.assertEquals("Test Subject",message.getSubject());
|
||||
// Assert.assertEquals("Test Content", message.getText());
|
||||
// }
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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 java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
|
||||
import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
|
||||
|
||||
/**
|
||||
* The test class for the AmazonSESOutboundAdapterParser
|
||||
*
|
||||
* @author Amol Nayak
|
||||
* @author Rob Harrop
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
public class AmazonSESOutboundAdapterParserTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* in a properties file
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void propFileValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-propfile-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* as individual attributes of the xml
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void propsValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-props-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* as individual attributes of the xml
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void refValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-cred-ref-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private void assertValidDefinition(EventDrivenConsumer consumer) {
|
||||
Assert.assertNotNull("Expected a non null EventDrivenConsumer", consumer);
|
||||
MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class);
|
||||
Assert.assertNotNull("Expected a non null messagehandler", handler);
|
||||
|
||||
Properties properties = TestUtils.getPropertyValue(handler, "mailSender.javaMailSender.javaMailProperties", Properties.class);
|
||||
Assert.assertNotNull("Expected a non null instance of credentials", properties);
|
||||
Assert.assertEquals("dummy", properties.getProperty(AWSJavaMailTransport.AWS_ACCESS_KEY_PROPERTY));
|
||||
Assert.assertEquals("dummy", properties.getProperty(AWSJavaMailTransport.AWS_SECRET_KEY_PROPERTY));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Test case that tests by specifying both the aws credentials properties file
|
||||
* and the individual properties to set the credentials
|
||||
*/
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void invalidDefinitionWithBothPropsAndPropFile() {
|
||||
new ClassPathXmlApplicationContext("classpath:ses-both-awscred-props-property.xml");
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* 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 javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.aws.core.PropertiesAWSCredentials;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* The test class for the {@link DefaultAmazonSESMailSender} class.
|
||||
*
|
||||
* NOTE: You will have to modify the to and from email's yourselves
|
||||
* as you can send to verified emails only as part of the free tier
|
||||
* in which you may be running the test.
|
||||
* To run this test you need to have your AWSAccess key and Secret key in the
|
||||
* file awscredentials.properties in the classpath. This file is not present in the
|
||||
* repository and you need to add one yourselves to src/test/resources folder and have
|
||||
* two properties accessKey and secretKey in it containing the access and the secret key
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
*/
|
||||
@Ignore
|
||||
public class DefaultAmazonSESMailSenderAWSTests {
|
||||
|
||||
private static final String TO_EMAIL_ID = "amolnayak311@gmail.com";
|
||||
private static DefaultAmazonSESMailSender sender;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static final void setupSender() throws Exception {
|
||||
PropertiesAWSCredentials credentials =
|
||||
new PropertiesAWSCredentials("classpath:awscredentials.properties");
|
||||
credentials.afterPropertiesSet();
|
||||
sender = new DefaultAmazonSESMailSender(credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a mail using {@link AmazonSESSimpleMailMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendSimpleMailMessage() {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content");
|
||||
message.setSubject("Test subject message");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
sender.send(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a mail using {@link AmazonSESSimpleMailMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendSimpleMailMessageArray() {
|
||||
SimpleMailMessage[] messages = new SimpleMailMessage[2];
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content one");
|
||||
message.setSubject("Test subject message one");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
messages[0] = message;
|
||||
message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content two");
|
||||
message.setSubject("Test subject message two");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
messages[1] = message;
|
||||
sender.send(messages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The test case for sending a {@link MimeMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendMimeMessage() throws Exception {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(sender.createMimeMessage());
|
||||
helper.setText("Some HTML Text", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line");
|
||||
MimeMessage message = helper.getMimeMessage();
|
||||
sender.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* The test case for sending a {@link MimeMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendMimeMessageArray() throws Exception {
|
||||
MimeMessage[] messages = new MimeMessage[2];
|
||||
MimeMessageHelper helper = new MimeMessageHelper(sender.createMimeMessage());
|
||||
helper.setText("Some HTML Text One", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line One");
|
||||
MimeMessage message = helper.getMimeMessage();
|
||||
messages[0] = message;
|
||||
helper = new MimeMessageHelper(sender.createMimeMessage());
|
||||
helper.setText("Some HTML Text Two", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line Two");
|
||||
message = helper.getMimeMessage();
|
||||
messages[1] = message;
|
||||
sender.send(messages);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws/"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
|
||||
@@ -24,4 +24,4 @@
|
||||
<bean id="customFileNameGenerator"
|
||||
class="org.springframework.integration.aws.s3.config.xml.AmazonS3OutboundChannelAdapterParserTests.DummyFileNameGenerator"/>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
|
||||
<int-aws:ses-outbound-channel-adapter id="validDefinition"
|
||||
propertiesFile="classpath:testawscredentials.properties"
|
||||
accessKey="propDummy"
|
||||
secretKey="propDummy"
|
||||
channel="outboundAdapterChannel"/>
|
||||
</beans>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
|
||||
<bean id="credentials" class="org.springframework.integration.aws.core.BasicAWSCredentials">
|
||||
<constructor-arg name="accessKey" value="dummy"/>
|
||||
<constructor-arg name="secretKey" value="dummy"/>
|
||||
</bean>
|
||||
|
||||
<int-aws:ses-outbound-channel-adapter id="validDefinition"
|
||||
credentials-ref="credentials"
|
||||
channel="outboundAdapterChannel"/>
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
|
||||
<int-aws:ses-outbound-channel-adapter id="validDefinition"
|
||||
propertiesFile="classpath:testawscredentials.properties" channel="outboundAdapterChannel"/>
|
||||
</beans>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<integration:channel id="outboundAdapterChannel"/>
|
||||
|
||||
<int-aws:ses-outbound-channel-adapter id="validDefinition"
|
||||
accessKey="dummy"
|
||||
secretKey="dummy"
|
||||
channel="outboundAdapterChannel"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user