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,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>