RESOLVED - issue BATCH-1239: Add email-sending item writer
Change method signature in error handler for Spring 3
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user