RESOLVED - issue BATCH-1239: Add email-sending item writer

Change method signature in error handler for Spring 3
This commit is contained in:
dsyer
2010-01-13 12:54:32 +00:00
parent 26de51c9b7
commit 2977c2076c
9 changed files with 16 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
#Tue Jul 07 11:35:38 BST 2009
#Wed Jan 13 12:53:06 GMT 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.batch.item.mail;
import javax.mail.MessagingException;
import org.springframework.mail.MailException;
import org.springframework.mail.MailMessage;
import org.springframework.mail.MailSendException;
@@ -48,14 +46,14 @@ public class DefaultMailErrorHandler implements MailErrorHandler {
/**
* Wraps the input exception with a runtime {@link MailException}. The
* exception message will contain the failed message.
* exception message will contain the failed message (using toString).
*
* @param message a failed message
* @param exception a MessagingException
* @throws MailException a translation of the MessagingException
* @see MailErrorHandler#handle(MailMessage, MessagingException)
* @throws MailException a translation of the Exception
* @see MailErrorHandler#handle(MailMessage, Exception)
*/
public void handle(MailMessage message, MessagingException exception) throws MailException {
public void handle(MailMessage message, Exception exception) throws MailException {
String msg = message.toString();
throw new MailSendException("Mail server send failed: "
+ msg.substring(0, Math.min(maxMessageLength, msg.length())), exception);

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.batch.item.mail;
import javax.mail.MessagingException;
import org.springframework.mail.MailException;
import org.springframework.mail.MailMessage;
@@ -33,13 +31,14 @@ public interface MailErrorHandler {
/**
* This method will be called for each message that failed sending in the
* chunk. If an exception is thrown from this method, then it will propagate
* to the caller.
*
* chunk. If the failed message is needed by the handler it will need to be
* downcast according to its runtime type. If an exception is thrown from
* this method, then it will propagate to the caller.
*
* @param message the failed message
* @param exception the exception that caused the failure
* @throws MailException if the exception cannot be handled
*/
public void handle(MailMessage message, MessagingException exception) throws MailException;
public void handle(MailMessage message, Exception exception) throws MailException;
}

View File

@@ -19,8 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.mail.MessagingException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.mail.MailException;
@@ -104,7 +102,7 @@ public class SimpleMailMessageItemWriter implements ItemWriter<SimpleMailMessage
@SuppressWarnings("unchecked")
Map<Object, Exception> failedMessages = e.getFailedMessages();
for (Entry<Object, Exception> entry : failedMessages.entrySet()) {
mailErrorHandler.handle((SimpleMailMessage) entry.getKey(), (MessagingException) entry.getValue());
mailErrorHandler.handle((SimpleMailMessage) entry.getKey(), entry.getValue());
}
}
}

View File

@@ -19,7 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.batch.item.ItemWriter;
@@ -108,7 +107,7 @@ public class MimeMessageItemWriter implements ItemWriter<MimeMessage> {
@SuppressWarnings("unchecked")
Map<Object, Exception> failedMessages = e.getFailedMessages();
for (Entry<Object, Exception> entry : failedMessages.entrySet()) {
mailErrorHandler.handle(new MimeMailMessage((MimeMessage)entry.getKey()), (MessagingException)entry.getValue());
mailErrorHandler.handle(new MimeMailMessage((MimeMessage)entry.getKey()), entry.getValue());
}
}
}

View File

@@ -52,7 +52,7 @@ public class DefaultMailErrorHandlerTests {
}
/**
* Test method for {@link DefaultMailErrorHandler#handle(MailMessage, MessagingException)}.
* Test method for {@link DefaultMailErrorHandler#handle(MailMessage, Exception)}.
*/
@Test(expected=MailSendException.class)
public void testHandle() {

View File

@@ -89,7 +89,7 @@ public class SimpleMailMessageItemWriterTests {
final AtomicReference<String> content = new AtomicReference<String>();
writer.setMailErrorHandler(new MailErrorHandler() {
public void handle(MailMessage message, MessagingException exception) throws MailException {
public void handle(MailMessage message, Exception exception) throws MailException {
content.set(exception.getMessage());
}
});

View File

@@ -94,7 +94,7 @@ public class MimeMessageItemWriterTests {
final AtomicReference<String> content = new AtomicReference<String>();
writer.setMailErrorHandler(new MailErrorHandler() {
public void handle(MailMessage message, MessagingException exception) throws MailException {
public void handle(MailMessage message, Exception exception) throws MailException {
content.set(exception.getMessage());
}
});

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.sample.domain.mail.internal;
import java.util.ArrayList;
import java.util.List;
import javax.mail.MessagingException;
import org.springframework.batch.item.mail.MailErrorHandler;
import org.springframework.mail.MailMessage;
@@ -37,7 +36,7 @@ public class TestMailErrorHandler implements MailErrorHandler {
private List<MailMessage> failedMessages = new ArrayList<MailMessage>();
public void handle(MailMessage failedMessage, MessagingException ex) {
public void handle(MailMessage failedMessage, Exception ex) {
this.failedMessages.add(failedMessage);
System.out.println("Mail message failed: " + failedMessage);
System.out.println(ex);