Moved ErrorHandler dependency from AbstractEndpoint to AbstractMessageConsumingEndpoint.
This commit is contained in:
@@ -23,10 +23,8 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.integration.scheduling.TaskSchedulerAware;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
|
||||
@@ -47,8 +45,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, TaskScheduler
|
||||
|
||||
private volatile TransactionDefinition transactionDefinition;
|
||||
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate();
|
||||
|
||||
|
||||
@@ -76,16 +72,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, TaskScheduler
|
||||
return this.channelTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an error handler for any Exceptions that occur
|
||||
* upon invocation of this endpoint. If none is provided,
|
||||
* the Exception messages will be logged (at warn level),
|
||||
* and the Exception rethrown.
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public final void afterPropertiesSet() {
|
||||
try {
|
||||
this.initialize();
|
||||
@@ -104,16 +90,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, TaskScheduler
|
||||
protected void initialize() throws Exception {
|
||||
}
|
||||
|
||||
protected void handleException(MessagingException exception) {
|
||||
if (this.errorHandler == null) {
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("exception occurred in endpoint '" + this.name + "'", exception);
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
this.errorHandler.handle(exception);
|
||||
}
|
||||
|
||||
protected final void configureTransactionSettingsForPoller(AbstractPoller poller) {
|
||||
if (this.transactionManager != null) {
|
||||
poller.setTransactionManager(this.transactionManager);
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.scheduling.IntervalTrigger;
|
||||
import org.springframework.integration.scheduling.Trigger;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,8 @@ public abstract class AbstractMessageConsumingEndpoint extends AbstractEndpoint
|
||||
|
||||
private volatile int maxMessagesPerPoll = -1;
|
||||
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
private volatile boolean running;
|
||||
@@ -69,6 +72,16 @@ public abstract class AbstractMessageConsumingEndpoint extends AbstractEndpoint
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an error handler for any Exceptions that occur
|
||||
* upon invocation of this endpoint. If none is provided,
|
||||
* the Exception messages will be logged (at warn level),
|
||||
* and the Exception rethrown.
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
|
||||
this.maxMessagesPerPoll = maxMessagesPerPoll;
|
||||
if (this.poller != null) {
|
||||
@@ -153,6 +166,16 @@ public abstract class AbstractMessageConsumingEndpoint extends AbstractEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleException(MessagingException exception) {
|
||||
if (this.errorHandler == null) {
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("exception occurred in endpoint '" + this + "'", exception);
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
this.errorHandler.handle(exception);
|
||||
}
|
||||
|
||||
protected abstract void onMessageInternal(Message<?> message);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user