INTEXT-6 - Add AWS SES Samples

* Add SES JavaMailSender Sample
* Add SES Spring Integration Sample
* Refactor DefaultAmazonSESMailSender to implement JavaMailSender and delegate to JavaMailSenderImpl rather than extending it
* Cleanup
This commit is contained in:
Gunnar Hillert
2013-01-17 17:14:54 -05:00
parent 639d4b27e0
commit 897fc0e9b4
34 changed files with 929 additions and 311 deletions

View File

@@ -0,0 +1,4 @@
AWS SES Spring Integration Sample
=========================

View File

@@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>mail-ses-integration</artifactId>
<name>AWS SES Mail Demo</name>
<version>1.0.0.BUILD-SNAPSHOT</version>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.2.0.RELEASE</spring.integration.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.10</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mail</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-aws</artifactId>
<version>0.5.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp-wiser</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.springframework.integration.samples.mailses.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repo.springsource.org.milestone</id>
<name>SpringSource Maven Milestone Repository</name>
<url>https://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
</project>

View File

@@ -0,0 +1,24 @@
package org.springframework.integration.samples.mailses;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.Payload;
import org.springframework.integration.mail.MailHeaders;
public interface EmailService {
void send(
@Header(MailHeaders.FROM)
String fromEmail,
@Header(MailHeaders.TO)
String toEmail,
@Header(MailHeaders.SUBJECT)
String subject,
@Payload
String body);
}

View File

@@ -0,0 +1,101 @@
/*
* 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.samples.mailses;
import java.util.Scanner;
import org.apache.log4j.Logger;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* Starts the Spring Context and will initialize the Spring Integration routes.
*
* @author Gunnar Hillert
* @since 1.0
*
*/
public final class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class);
private static final String HORIZONTAL_LINE = "\n=========================================================";
private Main() {
}
/**
* Load the Spring Integration Application Context
*
* @param args - command line arguments
*/
public static void main(final String... args) {
final Scanner scanner = new Scanner(System.in);
LOGGER.info(HORIZONTAL_LINE + "\n"
+ "\n Welcome to Spring Integration! "
+ "\n"
+ "\n For more information please visit: "
+ "\n http://www.springsource.org/spring-integration "
+ "\n" + HORIZONTAL_LINE);
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
final ConfigurableEnvironment environment = context.getEnvironment();
final String fromEmailAddress;
final String toEmailAddress;
final String subject;
final String body;
System.out.print("\nFrom which email address would you like to send a message?: ");
fromEmailAddress = scanner.nextLine();
System.out.print("To which email address would you like to send a message?: ");
toEmailAddress = scanner.nextLine();
System.out.print("What is the subject line?: ");
subject = scanner.nextLine();
System.out.print("What is the body of the message?: ");
body = scanner.nextLine();
if (!environment.containsProperty("accessKey")) {
System.out.print("Please enter your access key: ");
final String accessKey = scanner.nextLine();
environment.getSystemProperties().put("accessKey", accessKey);
}
if (!environment.containsProperty("secretKey")) {
System.out.print("Please enter your secret key: ");
final String secretKey = scanner.nextLine();
environment.getSystemProperties().put("secretKey", secretKey);
}
context.load("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();
context.refresh();
final EmailService emailService = context.getBean(EmailService.class);
emailService.send(fromEmailAddress, toEmailAddress, subject, body);
System.out.println(String.format("The email to '%s' was sent successfully.", toEmailAddress));
System.exit(0);
}
}

View File

@@ -0,0 +1,34 @@
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
xsi:schemaLocation="http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<bean id="serverPort" class="java.lang.Integer">
<constructor-arg value="#{tcpIpUtils.findAvailableServerSocket(12000)}"/>
</bean>
<int:gateway id="emailService" service-interface="org.springframework.integration.samples.mailses.EmailService">
<int:method name="send" request-channel="inputChannel" request-timeout="5000"/>
</int:gateway>
<int:channel id="inputChannel"/>
<int-aws:ses-outbound-channel-adapter id="sesOutbound" channel="inputChannel" accessKey="${accessKey}" secretKey="${secretKey}"/>
</beans>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework.integration.mail">
<level value="debug" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -0,0 +1,5 @@
AWS SES MailSender sample
=========================
This sample uses a Spring-provided *JavaMailSender* to send emails. This application demonstrates that by only replacing the *JavaMailSender* XML bean declaration with the *DefaultAmazonSESMailSender*, existing applications can send emails using Amazon SES without changing application code. The *DefaultAmazonSESMailSender* is provided by the *Spring Integration Extensions AWS Module*.

84
samples/mail-ses/pom.xml Normal file
View File

@@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>mail-ses</artifactId>
<name>AWS SES Mail Demo</name>
<version>1.0.0.BUILD-SNAPSHOT</version>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.2.0.RELEASE</spring.integration.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.10</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mail</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-aws</artifactId>
<version>0.5.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp-wiser</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.springframework.integration.samples.mailses.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repo.springsource.org.milestone</id>
<name>SpringSource Maven Milestone Repository</name>
<url>https://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
</project>

View File

@@ -0,0 +1,165 @@
/*
* 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.samples.mailses;
import java.util.List;
import java.util.Scanner;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.log4j.Logger;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
/**
* Starts the Spring Context and will initialize the Spring Integration routes.
*
* @author Gunnar Hillert
* @since 2.2
*
*/
public final class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class);
private static final String HORIZONTAL_LINE = "\n=========================================================";
private Main() {
}
/**
* Load the Spring Integration Application Context
*
* @param args - command line arguments
*/
public static void main(final String... args) {
final Scanner scanner = new Scanner(System.in);
LOGGER.info(HORIZONTAL_LINE + "\n"
+ "\n Welcome to Spring Integration! "
+ "\n"
+ "\n For more information please visit: "
+ "\n http://www.springsource.org/spring-integration "
+ "\n" + HORIZONTAL_LINE);
System.out.println("Please enter a choice and press <enter>: ");
System.out.println("\t1. Use Embedded SMTP Server (Wiser)");
System.out.println("\t2. Use Amazon SES");
System.out.println("\tq. Quit the application");
System.out.print("Enter your choice: ");
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
final ConfigurableEnvironment environment = context.getEnvironment();
boolean usingWiser = false;
String toEmailAddress;
while (true) {
final String input = scanner.nextLine();
if("1".equals(input.trim())) {
environment.setActiveProfiles("default");
usingWiser = true;
System.out.print("\nTo which email address would you like to send a message?: ");
toEmailAddress = scanner.nextLine();
break;
} else if("2".equals(input.trim())) {
environment.setActiveProfiles("aws");
if (!environment.containsProperty("accessKey")) {
System.out.print("\nPlease enter your access key: ");
final String accessKey = scanner.nextLine();
environment.getSystemProperties().put("accessKey", accessKey);
}
if (!environment.containsProperty("secretKey")) {
System.out.print("\nPlease enter your secret key: ");
final String secretKey = scanner.nextLine();
environment.getSystemProperties().put("secretKey", secretKey);
}
System.out.print("\nTo which email address would you like to send a message?: ");
toEmailAddress = scanner.nextLine();
break;
} else if("q".equals(input.trim())) {
System.out.println("Exiting application...bye.");
System.exit(0);
} else {
System.out.println("Invalid choice\n\n");
System.out.print("Enter you choice: ");
}
}
context.load("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();
context.refresh();
final JavaMailSender ms = context.getBean(JavaMailSender.class);
final String toEmailAddressToUse = toEmailAddress;
final MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
mimeMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(toEmailAddressToUse));
mimeMessage.setFrom(new InternetAddress(toEmailAddressToUse));
mimeMessage.setSubject("Testing Email - Subject");
mimeMessage.setText("Hello World");
}
};
try {
ms.send(preparator);
} catch (MailException e) {
throw new IllegalStateException(e);
}
System.out.println(String.format("The email to '%s' was sent successfully.", toEmailAddress));
if (usingWiser) {
Wiser wiser = context.getBean(Wiser.class);
List<WiserMessage> messages = wiser.getMessages();
final String from;
final String subject;
try {
from = messages.get(0).getMimeMessage().getFrom()[0].toString();
subject = messages.get(0).getMimeMessage().getSubject();
} catch (MessagingException e) {
throw new IllegalStateException(e);
}
System.out.println(String.format("Wiser received an email from '%s' with subject '%s'", from, subject));
}
System.exit(0);
}
}

View File

@@ -0,0 +1,44 @@
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<bean id="serverPort" class="java.lang.Integer">
<constructor-arg value="#{tcpIpUtils.findAvailableServerSocket(12000)}"/>
</bean>
<beans profile="default">
<bean id="wiser" class="org.subethamail.wiser.Wiser" init-method="start">
<property name="port" ref="serverPort"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="port" ref="serverPort"/>
</bean>
</beans>
<beans profile="aws">
<bean id="mailSender" class="org.springframework.integration.aws.ses.core.DefaultAmazonSESMailSender">
<constructor-arg name="credentials">
<bean class="org.springframework.integration.aws.core.BasicAWSCredentials">
<property name="accessKey" value="${accessKey}"/>
<property name="secretKey" value="${secretKey}"/>
</bean>
</constructor-arg>
</bean>
</beans>
</beans>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework.integration.mail">
<level value="debug" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -1,18 +1,16 @@
Spring Integration Extension for Amazon Web Services (AWS)
==========================================================
# Introduction
## Amazon Web Services (AWS)
##Small Introduction to 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.
*Spring Integration Extension for Amazon Web Services* provides Spring Integration adapters for the various services provided by the [AWS SDK for Java][].
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.
## Spring Integration's extensions to AWS
##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
This guide intends to explain briefly the various adapters available for [Amazon Web Services][] such as:
* **Amazon Simple Email Service (SES)**
* **Amazon Simple Storage Service (S3)** (Development complete, coming soon)
@@ -21,35 +19,27 @@ The library aims to provide adapters for following AWS Services
* **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.
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.
###Executing the test cases.
# 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/][]**
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.
> 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.
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.
@@ -134,7 +124,8 @@ We shall now see a java code snippet to send a mail using the SNS adapter
The messages over this channel are consumed by the outbound SES adapter and the mail is sent out using SES.
[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/

View File

@@ -1,28 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-aws</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<name>Spring Integration Amazon Web Services Support</name>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-aws</artifactId>
<version>0.5.0.BUILD-SNAPSHOT</version>
<name>Spring Integration Amazon Web Services Support</name>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<spring.integration.version>2.2.0.RELEASE</spring.integration.version>
<spring.test.version>3.1.3.RELEASE</spring.test.version>
<aws.sdk.version>1.3.12</aws.sdk.version>
<commons.codec.version>1.5</commons.codec.version>
<spring.integration.version>2.2.0.RELEASE</spring.integration.version>
<spring.test.version>3.1.3.RELEASE</spring.test.version>
<aws.sdk.version>1.3.12</aws.sdk.version>
<commons.codec.version>1.5</commons.codec.version>
<commons.logging.version>1.1.1</commons.logging.version>
<commons.io.version>2.0.1</commons.io.version>
<java.mail.version>1.4.4</java.mail.version>
@@ -34,190 +35,189 @@
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*Abstract*.java</exclude>
<exclude>**/*AWSTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>springsource-libs-milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>https://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws.sdk.version}</version>
<scope>compile</scope>
</dependency>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*Abstract*.java</exclude>
<exclude>**/*AWSTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>springsource-libs-milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>https://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws.sdk.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${java.mail.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${java.mail.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mail</artifactId>
<version>${spring.integration.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mail</artifactId>
<version>${spring.integration.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${apache.httpclient.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${apache.httpclient.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${spring.integration.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${spring.integration.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.test.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.test.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
</project>

View File

@@ -23,7 +23,7 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AWSNamespaceHandler extends

View File

@@ -29,7 +29,7 @@ import org.w3c.dom.Element;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public abstract class AbstractAWSOutboundChannelAdapterParser extends

View File

@@ -28,7 +28,7 @@ import org.w3c.dom.Element;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public final class AmazonWSParserUtils {

View File

@@ -23,7 +23,7 @@ import com.amazonaws.AmazonWebServiceClient;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public interface AWSClientFactory<T extends AmazonWebServiceClient> {

View File

@@ -20,7 +20,7 @@ package org.springframework.integration.aws.core;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public interface AWSCredentials {

View File

@@ -20,7 +20,7 @@ package org.springframework.integration.aws.core;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AWSOperationException extends RuntimeException {

View File

@@ -34,7 +34,7 @@ import com.amazonaws.AmazonWebServiceClient;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public abstract class AbstractAWSClientFactory<T extends AmazonWebServiceClient> implements AWSClientFactory<T> {

View File

@@ -15,13 +15,15 @@
*/
package org.springframework.integration.aws.core;
import org.springframework.util.Assert;
/**
* The basic implementation class holding the Access key and the secret
* key for the AWS account .
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class BasicAWSCredentials implements AWSCredentials {
@@ -45,12 +47,15 @@ public class BasicAWSCredentials implements AWSCredentials {
}
/**.
* The constructor accepting the access and secret key
* @param accessKey
* @param secretKey
* The constructor accepting the access and secret key.
*
* @param accessKey Must not be null or empty
* @param secretKey Must not be null or empty
*/
public BasicAWSCredentials(String accessKey, String secretKey) {
super();
Assert.hasText(accessKey, "The accessKey parameter must not be null or empty.");
Assert.hasText(secretKey, "The secretKey parameter must not be null or empty.");
this.accessKey = accessKey;
this.secretKey = secretKey;
}
@@ -68,6 +73,7 @@ public class BasicAWSCredentials implements AWSCredentials {
* @param accessKey
*/
public void setAccessKey(String accessKey) {
Assert.hasText(accessKey, "The accessKey parameter must not be null or empty.");
this.accessKey = accessKey;
}
@@ -84,6 +90,7 @@ public class BasicAWSCredentials implements AWSCredentials {
* @param secretKey
*/
public void setSecretKey(String secretKey) {
Assert.hasText(secretKey, "The secretKey parameter must not be null or empty.");
this.secretKey = secretKey;
}
}

View File

@@ -20,7 +20,7 @@ package org.springframework.integration.aws.core;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class InvalidAWSCredentialsException extends RuntimeException {

View File

@@ -21,6 +21,7 @@ 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.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
@@ -30,7 +31,7 @@ import org.springframework.util.StringUtils;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class PropertiesAWSCredentials extends BasicAWSCredentials implements InitializingBean {
@@ -44,11 +45,13 @@ public class PropertiesAWSCredentials extends BasicAWSCredentials implements Ini
private String propertyFileName;
/**.
* Constructor accepting the properties file
* @param propertyFileName
* Constructor accepting the properties file.
*
* @param propertyFileName Must not be null or empty
*/
public PropertiesAWSCredentials(String propertyFileName) {
super();
Assert.hasText(propertyFileName, "The propertyFileName parameter must not be null or empty.");
this.propertyFileName = propertyFileName;
}
@@ -95,10 +98,12 @@ public class PropertiesAWSCredentials extends BasicAWSCredentials implements Ini
}
/**.
* Sets the name of the file that will hold the AW credentials
* @param propertyFileName
* Sets the name of the file that will hold the AW credentials.
*
* @param propertyFileName Must not be null or empty
*/
public void setPropertyFileName(String propertyFileName) {
Assert.hasText(propertyFileName, "The propertyFileName parameter must not be null or empty.");
this.propertyFileName = propertyFileName;
}

View File

@@ -26,7 +26,7 @@ import org.springframework.mail.javamail.JavaMailSender;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AmazonSESMessageHandler extends MailSendingMessageHandler {

View File

@@ -25,7 +25,7 @@ import org.springframework.integration.core.MessageHandler;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AmazonSESOutboundAdapterParser extends

View File

@@ -24,7 +24,7 @@ import org.springframework.integration.aws.core.AWSOperationException;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AmazonSESMailSendException extends AWSOperationException {

View File

@@ -15,94 +15,107 @@
*/
package org.springframework.integration.aws.ses.core;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
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.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.RawMessage;
import com.amazonaws.services.simpleemail.model.SendRawEmailRequest;
import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
/**
* The implementation class for sending mail using the Amazon SES service
*
* @author Amol Nayak
* @author Gunnar Hillert
*
* @since 1.0
* @since 0.5
*
*/
public class DefaultAmazonSESMailSender extends JavaMailSenderImpl {
/**.
* The API class used for sending email using Amazon SES
*/
private final AmazonSimpleEmailServiceClient emailService;
private final AWSCredentials credentials;
public class DefaultAmazonSESMailSender implements JavaMailSender {
public DefaultAmazonSESMailSender(AWSCredentials credentials) {
if(credentials == null)
if(credentials == null) {
throw new AWSOperationException(null, "Credentials cannot be null, provide a non null valid set of credentials");
this.credentials = 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);
emailService = new AmazonSimpleEmailServiceClient(
new BasicAWSCredentials(credentials.getAccessKey(),
credentials.getSecretKey()));
}
private JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl() {
@Override
protected Transport getTransport(Session session)
throws NoSuchProviderException {
return new AWSJavaMailTransport(session, null);
}
};
/**
* The Actual implementation of the sending of the mail message using the AWS SES
* SDK
*/
@Override
protected void doSend(MimeMessage[] mimeMessages, Object[] originalMessages)
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 {
Map<Object, Exception> failedMessageMap = new HashMap<Object, Exception>();
if(mimeMessages != null && mimeMessages.length > 0) {
int index = 0;
for(MimeMessage mailMessage:mimeMessages) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mailMessage.writeTo(baos);
RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(baos.toByteArray()));
SendRawEmailRequest rawMail = new SendRawEmailRequest(rawMessage);
emailService.sendRawEmail(rawMail);
index++;
} catch (Exception e) {
failedMessageMap.put(originalMessages != null? originalMessages[index]:mailMessage, e);
}
}
}
if(!failedMessageMap.isEmpty()) {
throw new AmazonSESMailSendException(credentials.getAccessKey(),
"Exception while sending one or more messages, see failedMessages for more details",
failedMessageMap);
}
return javaMailSender.createMimeMessage(contentStream);
}
@Override
public void setPort(int port) {
throw new UnsupportedOperationException("AWS SES Implementation of mail " +
"sender does not allow setting the port number");
public void send(MimeMessage mimeMessage) throws MailException {
javaMailSender.send(mimeMessage);
}
@Override
public void setHost(String host) {
throw new UnsupportedOperationException("AWS SES Implementation of mail " +
"sender does not allow setting the host name. It is already configured with an endpoint");
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);
}
//Should we disallow setSession?
}

View File

@@ -28,7 +28,7 @@ import com.amazonaws.services.sqs.AmazonSQSClient;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AWSClientFactoryTest {

View File

@@ -24,7 +24,7 @@ import java.util.Properties;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public abstract class BaseTestCase {

View File

@@ -32,7 +32,7 @@ import org.springframework.integration.test.util.TestUtils;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public abstract class AbstractAWSOutboundChannelAdapterParserTests<T extends MessageHandler> {

View File

@@ -30,7 +30,7 @@ import com.amazonaws.AmazonWebServiceClient;
* The abstract test class for Amazon WebService client factory tests
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public abstract class AbstractAWSClientFactoryTests<T extends AmazonWebServiceClient> {

View File

@@ -48,7 +48,7 @@ import org.springframework.mail.javamail.JavaMailSender;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AmazonSESMessageHandlerTests {

View File

@@ -15,22 +15,25 @@
*/
package org.springframework.integration.aws.ses.config.xml;
import java.util.Properties;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.aws.core.AWSCredentials;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.test.util.TestUtils;
import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
/**
* The test class for the AmazonSESOutboundAdapterParser
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class AmazonSESOutboundAdapterParserTests {
@@ -79,10 +82,11 @@ public class AmazonSESOutboundAdapterParserTests {
Assert.assertNotNull("Expected a non null EventDrivenConsumer", consumer);
MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class);
Assert.assertNotNull("Expected a non null messagehandler", handler);
AWSCredentials credentials = TestUtils.getPropertyValue(handler, "mailSender.credentials", AWSCredentials.class);
Assert.assertNotNull("Expected a non null instance of credentials", credentials);
Assert.assertEquals("dummy", credentials.getAccessKey());
Assert.assertEquals("dummy", credentials.getSecretKey());
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));
}
/**

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.integration.aws.ses.core;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import org.junit.BeforeClass;
@@ -38,7 +37,7 @@ import org.springframework.mail.javamail.MimeMessageHelper;
*
* @author Amol Nayak
*
* @since 1.0
* @since 0.5
*
*/
public class DefaultAmazonSESMailSenderAWSTests {
@@ -96,8 +95,7 @@ public class DefaultAmazonSESMailSenderAWSTests {
*/
@Test
public void sendMimeMessage() throws Exception {
Session session = sender.getSession();
MimeMessageHelper helper = new MimeMessageHelper(new MimeMessage(session));
MimeMessageHelper helper = new MimeMessageHelper(sender.createMimeMessage());
helper.setText("Some HTML Text", true);
helper.setTo(TO_EMAIL_ID);
helper.setFrom(TO_EMAIL_ID);
@@ -111,16 +109,15 @@ public class DefaultAmazonSESMailSenderAWSTests {
*/
@Test
public void sendMimeMessageArray() throws Exception {
Session session = sender.getSession();
MimeMessage[] messages = new MimeMessage[2];
MimeMessageHelper helper = new MimeMessageHelper(new MimeMessage(session));
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(new MimeMessage(session));
helper = new MimeMessageHelper(sender.createMimeMessage());
helper.setText("Some HTML Text Two", true);
helper.setTo(TO_EMAIL_ID);
helper.setFrom(TO_EMAIL_ID);