INT-2727 PseudoTX Refactoring
Remove the need for pseudo-transactional element INT-2727 PseudoTX Add PseudoTransactionalTransactionManager INT-2727 addressed PR comments cherry picked previous code for mail module to eliminate breaking change INT-2727 initial refactoring pseudo-tx support to use common configuration INT-2727 finalizing pseudo-tx synchronization support INT-2727 polishing INT-2727 polishing based on PR comments INT-2727 addressed PR comments INT-2727 polishing INT-2727 Remove PseudoTransactionalMessageSource Instead of getResource, bind the resource holder before receive() and then add attributes to the holder. INT-2727 polishing INT-2727 Polishing Remove bind of #resource; add beforeCommit() test; add TransactionTemplate tests.
This commit is contained in:
committed by
Gary Russell
parent
5828f70321
commit
94cc5a73e2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -33,6 +33,7 @@ import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
@@ -41,18 +42,17 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class for {@link MailReceiver} implementations.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public abstract class AbstractMailReceiver extends IntegrationObjectSupport implements MailReceiver, DisposableBean{
|
||||
|
||||
public final static String SI_USER_FLAG = "spring-integration-mail-adapter";
|
||||
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final URLName url;
|
||||
@@ -65,10 +65,10 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private volatile Store store;
|
||||
|
||||
private final ThreadLocal<MailReceiverContext> contextHolder = new ThreadLocal<MailReceiverContext>();
|
||||
private volatile Folder folder;
|
||||
|
||||
private volatile boolean shouldDeleteMessages;
|
||||
|
||||
|
||||
protected volatile int folderOpenMode = Folder.READ_ONLY;
|
||||
|
||||
private volatile Properties javaMailProperties = new Properties();
|
||||
@@ -81,6 +81,8 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
protected volatile boolean initialized;
|
||||
|
||||
private final Object folderMonitor = new Object();
|
||||
|
||||
|
||||
public AbstractMailReceiver() {
|
||||
this.url = null;
|
||||
@@ -115,7 +117,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
/**
|
||||
* Set the {@link Session}. Otherwise, the Session will be created by invocation of
|
||||
* {@link Session#getInstance(Properties)} or {@link Session#getInstance(Properties, Authenticator)}.
|
||||
*
|
||||
*
|
||||
* @see #setJavaMailProperties(Properties)
|
||||
* @see #setJavaMailAuthenticator(Authenticator)
|
||||
*/
|
||||
@@ -127,7 +129,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
/**
|
||||
* A new {@link Session} will be created with these properties (and the JavaMailAuthenticator if provided).
|
||||
* Use either this method or {@link #setSession}, but not both.
|
||||
*
|
||||
*
|
||||
* @see #setJavaMailAuthenticator(Authenticator)
|
||||
* @see #setSession(Session)
|
||||
*/
|
||||
@@ -138,7 +140,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
/**
|
||||
* Optional, sets the Authenticator to be used to obtain a session. This will not be used if
|
||||
* {@link AbstractMailReceiver#setSession} has been used to configure the {@link Session} directly.
|
||||
*
|
||||
*
|
||||
* @see #setSession(Session)
|
||||
*/
|
||||
public void setJavaMailAuthenticator(Authenticator javaMailAuthenticator) {
|
||||
@@ -166,27 +168,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
protected Folder getFolder() {
|
||||
return this.getTransactionContext().getFolder();
|
||||
}
|
||||
|
||||
public MailReceiverContext getTransactionContext() {
|
||||
return doObtainTransactionContext();
|
||||
}
|
||||
|
||||
private MailReceiverContext doObtainTransactionContext() {
|
||||
MailReceiverContext mailReceiverContext = this.contextHolder.get();
|
||||
if (mailReceiverContext == null ||
|
||||
mailReceiverContext.getFolder() == null ||
|
||||
!mailReceiverContext.getFolder().isOpen()) {
|
||||
try {
|
||||
this.openFolder();
|
||||
return this.contextHolder.get();
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new org.springframework.integration.MessagingException("Failed to open folder", e);
|
||||
}
|
||||
}
|
||||
return mailReceiverContext;
|
||||
return this.folder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,71 +204,104 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized void openFolder() throws MessagingException {
|
||||
protected void openFolder() throws MessagingException {
|
||||
this.openSession();
|
||||
MailReceiverContext context = this.contextHolder.get();
|
||||
Folder folder = null;
|
||||
if (context == null) {
|
||||
folder = this.store.getFolder(this.url);
|
||||
this.contextHolder.set(new MailReceiverContext(folder));
|
||||
if (this.folder == null) {
|
||||
this.folder = this.store.getFolder(this.url);
|
||||
}
|
||||
else {
|
||||
folder = context.getFolder();
|
||||
}
|
||||
if (folder == null || !folder.exists()) {
|
||||
if (this.folder == null || !this.folder.exists()) {
|
||||
throw new IllegalStateException("no such folder [" + this.url.getFile() + "]");
|
||||
}
|
||||
if (folder.isOpen()) {
|
||||
if (this.folder.isOpen()) {
|
||||
return;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("opening folder [" + MailTransportUtils.toPasswordProtectedString(this.url) + "]");
|
||||
}
|
||||
folder.open(this.folderOpenMode);
|
||||
this.folder.open(this.folderOpenMode);
|
||||
}
|
||||
|
||||
public Message[] receive() throws javax.mail.MessagingException {
|
||||
this.openFolder();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("attempting to receive mail from folder [" + this.getFolder().getFullName() + "]");
|
||||
}
|
||||
Message[] messages = this.searchForNewMessages();
|
||||
if (this.maxFetchSize > 0 && messages.length > this.maxFetchSize) {
|
||||
Message[] reducedMessages = new Message[this.maxFetchSize];
|
||||
System.arraycopy(messages, 0, reducedMessages, 0, this.maxFetchSize);
|
||||
messages = reducedMessages;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("found " + messages.length + " new messages");
|
||||
}
|
||||
if (messages.length > 0) {
|
||||
this.fetchMessages(messages);
|
||||
}
|
||||
List<Message> copiedMessages = new LinkedList<Message>();
|
||||
logger.debug("Received " + messages.length + " messages");
|
||||
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
if (this.selectorExpression != null) {
|
||||
Message message = messages[i];
|
||||
if (this.selectorExpression.getValue(this.context, message, Boolean.class)){
|
||||
copiedMessages.add(new MimeMessage((MimeMessage) message));
|
||||
|
||||
public Message[] receive() throws javax.mail.MessagingException {
|
||||
synchronized (this.folderMonitor) {
|
||||
try {
|
||||
this.openFolder();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("attempting to receive mail from folder [" + this.getFolder().getFullName() + "]");
|
||||
}
|
||||
Message[] messages = this.searchForNewMessages();
|
||||
if (this.maxFetchSize > 0 && messages.length > this.maxFetchSize) {
|
||||
Message[] reducedMessages = new Message[this.maxFetchSize];
|
||||
System.arraycopy(messages, 0, reducedMessages, 0, this.maxFetchSize);
|
||||
messages = reducedMessages;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("found " + messages.length + " new messages");
|
||||
}
|
||||
if (messages.length > 0) {
|
||||
this.fetchMessages(messages);
|
||||
}
|
||||
List<Message> copiedMessages = new LinkedList<Message>();
|
||||
logger.debug("Recieved " + messages.length + " messages");
|
||||
|
||||
boolean recentFlagSupported = false;
|
||||
|
||||
Flags flags = this.getFolder().getPermanentFlags();
|
||||
|
||||
if (flags != null){
|
||||
recentFlagSupported = flags.contains(Flags.Flag.RECENT);
|
||||
}
|
||||
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
if (!recentFlagSupported){
|
||||
if (flags != null && flags.contains(Flags.Flag.USER)){
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("USER flags are supported by this mail server. Flagging message with '" + SI_USER_FLAG + "' user flag");
|
||||
}
|
||||
Flags siFlags = new Flags();
|
||||
siFlags.add(SI_USER_FLAG);
|
||||
messages[i].setFlags(siFlags, true);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("USER flags are not supported by this mail server. Flagging message with system flag");
|
||||
}
|
||||
messages[i].setFlag(Flags.Flag.FLAGGED, true);
|
||||
}
|
||||
}
|
||||
if (this.selectorExpression != null) {
|
||||
Message message = messages[i];
|
||||
if (this.selectorExpression.getValue(this.context, message, Boolean.class)){
|
||||
this.setAdditionalFlags(message);
|
||||
copiedMessages.add(new MimeMessage((MimeMessage) message));
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("Fetched email with subject '" + message.getSubject() + "' will be discarded by the matching filter" +
|
||||
" and will not be flagged as SEEN.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.setAdditionalFlags(messages[i]);
|
||||
copiedMessages.add(new MimeMessage((MimeMessage) messages[i]));
|
||||
}
|
||||
}
|
||||
if (this.shouldDeleteMessages()) {
|
||||
this.deleteMessages(messages);
|
||||
}
|
||||
return copiedMessages.toArray(new Message[copiedMessages.size()]);
|
||||
}
|
||||
else {
|
||||
copiedMessages.add(new MimeMessage((MimeMessage) messages[i]));
|
||||
finally {
|
||||
MailTransportUtils.closeFolder(this.folder, this.shouldDeleteMessages);
|
||||
}
|
||||
}
|
||||
if (messages.length > 0) {
|
||||
this.contextHolder.get().setMessages(messages);
|
||||
}
|
||||
return copiedMessages.toArray(new Message[copiedMessages.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the specified messages from this receiver's folder. Default
|
||||
* implementation {@link Folder#fetch(Message[], FetchProfile) fetches}
|
||||
* every {@link javax.mail.FetchProfile.Item}.
|
||||
*
|
||||
*
|
||||
* @param messages the messages to fetch
|
||||
* @throws MessagingException in case of JavaMail errors
|
||||
*/
|
||||
@@ -295,12 +310,12 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
contentsProfile.add(FetchProfile.Item.ENVELOPE);
|
||||
contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
|
||||
contentsProfile.add(FetchProfile.Item.FLAGS);
|
||||
this.contextHolder.get().getFolder().fetch(messages, contentsProfile);
|
||||
this.folder.fetch(messages, contentsProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given messages from this receiver's folder.
|
||||
*
|
||||
*
|
||||
* @param messages the messages to delete
|
||||
* @throws MessagingException in case of JavaMail errors
|
||||
*/
|
||||
@@ -311,19 +326,23 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional method allowing you to set additional flags.
|
||||
* Optional method allowing you to set additional flags.
|
||||
* Currently only implemented in IMapMailReceiver.
|
||||
*
|
||||
*
|
||||
* @param message
|
||||
* @throws MessagingException
|
||||
*/
|
||||
protected void setAdditionalFlags(Message message) throws MessagingException {
|
||||
}
|
||||
|
||||
public synchronized void destroy() throws Exception {
|
||||
MailTransportUtils.closeService(this.store);
|
||||
this.store = null;
|
||||
this.initialized = false;
|
||||
public void destroy() throws Exception {
|
||||
synchronized (this.folderMonitor) {
|
||||
MailTransportUtils.closeFolder(this.folder, this.shouldDeleteMessages);
|
||||
MailTransportUtils.closeService(this.store);
|
||||
this.folder = null;
|
||||
this.store = null;
|
||||
this.initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -342,84 +361,4 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
return this.store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete and expunge messages after success.
|
||||
* @param context
|
||||
*/
|
||||
public void closeContextAfterSuccess(MailReceiverContext context) {
|
||||
Assert.notNull(context, "Mail Reader Context cannot be null");
|
||||
Message[] messages = this.contextHolder.get().getMessages();
|
||||
Assert.state(messages != null, "No messages in mail receiver context");
|
||||
RuntimeException exceptionToThrow = null;
|
||||
boolean recentFlagSupported = false;
|
||||
|
||||
Flags flags = context.getFolder().getPermanentFlags();
|
||||
|
||||
if (flags != null){
|
||||
recentFlagSupported = flags.contains(Flags.Flag.RECENT);
|
||||
}
|
||||
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
try {
|
||||
if (!recentFlagSupported){
|
||||
if (flags != null && flags.contains(Flags.Flag.USER)){
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("USER flags are supported by this mail server. Flagging message with '" + SI_USER_FLAG + "' user flag");
|
||||
}
|
||||
Flags siFlags = new Flags();
|
||||
siFlags.add(SI_USER_FLAG);
|
||||
messages[i].setFlags(siFlags, true);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("USER flags are not supported by this mail server. Flagging message with system flag");
|
||||
}
|
||||
messages[i].setFlag(Flags.Flag.FLAGGED, true);
|
||||
}
|
||||
}
|
||||
if (this.selectorExpression != null) {
|
||||
Message message = messages[i];
|
||||
if (this.selectorExpression.getValue(this.context, message, Boolean.class)){
|
||||
this.setAdditionalFlags(message);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("Fetched email with subject '" + message.getSubject() + "' will be discarded by the matching filter" +
|
||||
" and will not be flagged as SEEN.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.setAdditionalFlags(messages[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptionToThrow = new org.springframework.integration.MessagingException("Failed to set flags", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldDeleteMessages) {
|
||||
if (messages != null) {
|
||||
try {
|
||||
this.deleteMessages(messages);
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
exceptionToThrow = new org.springframework.integration.MessagingException("Failed to delete messages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Folder folder = context.getFolder();
|
||||
MailTransportUtils.closeFolder(folder, this.shouldDeleteMessages);
|
||||
this.contextHolder.remove();
|
||||
if (exceptionToThrow != null) {
|
||||
throw exceptionToThrow;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeContextAfterFailure(MailReceiverContext context) {
|
||||
Assert.notNull(context, "Mail Reader Context cannot be null");
|
||||
MailTransportUtils.closeFolder(context.getFolder(), false);
|
||||
this.contextHolder.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.integration.mail;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.FolderClosedException;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
@@ -27,7 +26,6 @@ import javax.mail.Store;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||
import org.springframework.integration.mail.MailReceiver.MailReceiverContext;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
@@ -40,11 +38,10 @@ import org.springframework.util.Assert;
|
||||
* messages will be converted and sent as Spring Integration Messages to the
|
||||
* output channel. The Message payload will be the {@link javax.mail.Message}
|
||||
* instance that was received.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
|
||||
@@ -61,7 +58,7 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
private volatile ScheduledFuture<?> pingTask;
|
||||
|
||||
private volatile long connectionPingInterval = 10000;
|
||||
|
||||
|
||||
private final ExceptionAwarePeriodicTrigger receivingTaskTrigger = new ExceptionAwarePeriodicTrigger();
|
||||
|
||||
|
||||
@@ -80,7 +77,6 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
this.shouldReconnectAutomatically = shouldReconnectAutomatically;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentType() {
|
||||
return "mail:imap-idle-channel-adapter";
|
||||
}
|
||||
@@ -134,16 +130,12 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
public void run() {
|
||||
final TaskScheduler scheduler = getTaskScheduler();
|
||||
Assert.notNull(scheduler, "'taskScheduler' must not be null" );
|
||||
MailReceiverContext context = null;
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("waiting for mail");
|
||||
}
|
||||
mailReceiver.waitForNewMessages();
|
||||
context = mailReceiver.getTransactionContext();
|
||||
Assert.state(context != null, "Mail receiver returned a null context");
|
||||
Folder folder = context.getFolder();
|
||||
if (folder.isOpen()) {
|
||||
if (mailReceiver.getFolder().isOpen()) {
|
||||
Message[] mailMessages = mailReceiver.receive();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("received " + mailMessages.length + " mail messages");
|
||||
@@ -167,11 +159,6 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
"Failure in 'idle' task. Will NOT resubmit.", e);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (context != null) {
|
||||
mailReceiver.closeContextAfterSuccess(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,9 +176,9 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ExceptionAwarePeriodicTrigger implements Trigger {
|
||||
|
||||
|
||||
private volatile boolean delayNextExecution;
|
||||
|
||||
|
||||
@@ -199,12 +186,12 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
if (delayNextExecution){
|
||||
delayNextExecution = false;
|
||||
return new Date(System.currentTimeMillis() + reconnectDelay);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new Date(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void delayNextExecution() {
|
||||
this.delayNextExecution = true;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,6 @@ public interface MailReceiver {
|
||||
|
||||
javax.mail.Message[] receive() throws javax.mail.MessagingException;
|
||||
|
||||
MailReceiverContext getTransactionContext();
|
||||
|
||||
void closeContextAfterSuccess(MailReceiverContext context);
|
||||
|
||||
void closeContextAfterFailure(MailReceiverContext context);
|
||||
|
||||
public static class MailReceiverContext {
|
||||
|
||||
private final Folder folder;
|
||||
@@ -60,6 +54,5 @@ public interface MailReceiver {
|
||||
Folder getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.core.PseudoTransactionalMessageSource;
|
||||
import org.springframework.integration.mail.MailReceiver.MailReceiverContext;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -38,8 +36,9 @@ import org.springframework.util.Assert;
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MailReceivingMessageSource implements PseudoTransactionalMessageSource<javax.mail.Message, MailReceiverContext> {
|
||||
public class MailReceivingMessageSource implements MessageSource<javax.mail.Message> {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -53,7 +52,6 @@ public class MailReceivingMessageSource implements PseudoTransactionalMessageSou
|
||||
this.mailReceiver = mailReceiver;
|
||||
}
|
||||
|
||||
|
||||
public Message<javax.mail.Message> receive() {
|
||||
try {
|
||||
javax.mail.Message mailMessage = this.mailQueue.poll();
|
||||
@@ -77,31 +75,4 @@ public class MailReceivingMessageSource implements PseudoTransactionalMessageSou
|
||||
return null;
|
||||
}
|
||||
|
||||
public MailReceiverContext getResource() {
|
||||
return this.mailReceiver.getTransactionContext();
|
||||
}
|
||||
|
||||
public void afterCommit(Object context) {
|
||||
Assert.isTrue(context instanceof MailReceiverContext, "Expected a MailReceiverContext");
|
||||
this.mailReceiver.closeContextAfterSuccess((MailReceiverContext) context);
|
||||
}
|
||||
|
||||
public void afterRollback(Object context) {
|
||||
Assert.isTrue(context instanceof MailReceiverContext, "Expected a MailReceiverContext");
|
||||
this.mailReceiver.closeContextAfterFailure((MailReceiverContext) context);
|
||||
}
|
||||
|
||||
/**
|
||||
* For backwards-compatibility; with no tx, the mail adapter updates the status before the send.
|
||||
*/
|
||||
public void afterReceiveNoTx(MailReceiverContext resource) {
|
||||
this.afterCommit(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* For backwards-compatibility; with no tx, the mail adapter updates the status before the send.
|
||||
*/
|
||||
public void afterSendNoTx(MailReceiverContext resource) {
|
||||
// No op
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user