Removed the 'errorHandler' property from AbstractMessageConsumer and the 'error-handler' attribute from the schema. Will be adding configurable errorChannel Message header instead.
This commit is contained in:
@@ -46,8 +46,6 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
|
||||
private static final String SELECTOR_ATTRIBUTE = "selector";
|
||||
|
||||
private static final String ERROR_HANDLER_ATTRIBUTE = "error-handler";
|
||||
|
||||
|
||||
@Override
|
||||
protected final Class<?> getBeanClass(Element element) {
|
||||
@@ -92,7 +90,6 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
BeanDefinitionBuilder consumerBuilder = this.parseConsumer(element, parserContext);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(consumerBuilder, element, OUTPUT_CHANNEL_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(consumerBuilder, element, SELECTOR_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(consumerBuilder, element, ERROR_HANDLER_ATTRIBUTE);
|
||||
String consumerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
consumerBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(consumerBeanName);
|
||||
|
||||
@@ -218,7 +218,6 @@
|
||||
<xsd:attribute name="ref" type="xsd:string"/>
|
||||
<xsd:attribute name="method" type="xsd:string"/>
|
||||
<xsd:attribute name="selector" type="xsd:string"/>
|
||||
<xsd:attribute name="error-handler" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -23,14 +23,13 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class for MessageConsumer implementations that provides basic
|
||||
* validation and error handling capabilities. Asserts that the incoming
|
||||
* Message is not null and that it does not contain a null payload. For custom
|
||||
* error handling, provide a reference to an {@link ErrorHandler}.
|
||||
* Message is not null and that it does not contain a null payload. Converts
|
||||
* checked exceptions into runtime {@link MessagingException}s.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@@ -38,49 +37,25 @@ public abstract class AbstractMessageConsumer implements MessageConsumer {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
|
||||
/**
|
||||
* Provide an error handler for any Exceptions that occur
|
||||
* upon invocation of this consumer. 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 onMessage(Message<?> message) {
|
||||
Assert.notNull(message == null, "Message must not be null");
|
||||
Assert.notNull(message.getPayload(), "Message payload must not be null");
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("consumer '" + this + "' processing message: " + message);
|
||||
this.logger.debug("consumer '" + this + "' received message: " + message);
|
||||
}
|
||||
try {
|
||||
this.onMessageInternal(message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof MessagingException) {
|
||||
this.handleException((MessagingException) e);
|
||||
}
|
||||
else {
|
||||
this.handleException(new MessageHandlingException(message,
|
||||
"failure occurred in consumer '" + this.toString() + "'", e));
|
||||
throw (MessagingException) e;
|
||||
}
|
||||
throw new MessageHandlingException(message,
|
||||
"error occurred in consumer [" + this + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleException(MessagingException exception) {
|
||||
if (this.errorHandler == null) {
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("exception occurred in consumer '" + this + "'", exception);
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
this.errorHandler.handle(exception);
|
||||
}
|
||||
|
||||
protected abstract void onMessageInternal(Message<?> message);
|
||||
protected abstract void onMessageInternal(Message<?> message) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ package org.springframework.integration.endpoint;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageProducer;
|
||||
@@ -153,13 +153,14 @@ public abstract class AbstractReplyProducingMessageConsumer extends AbstractMess
|
||||
replyChannel = this.channelResolver.resolveChannelName((String) replyChannelHeader);
|
||||
}
|
||||
else {
|
||||
throw new MessagingException("expected a MessageChannel or String for 'replyChannel', but type is ["
|
||||
throw new ChannelResolutionException("expected a MessageChannel or String for 'replyChannel', but type is ["
|
||||
+ replyChannelHeader.getClass() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (replyChannel == null) {
|
||||
throw new MessagingException("unable to resolve reply channel");
|
||||
throw new ChannelResolutionException(
|
||||
"unable to resolve reply channel for message: " + requestMessage);
|
||||
}
|
||||
return replyChannel;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -76,16 +75,4 @@ public class EndpointParserTests {
|
||||
inputChannel.send(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndpointWithErrorHandler() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithErrorHandler.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channel");
|
||||
TestErrorHandler errorHandler = (TestErrorHandler) context.getBean("errorHandler");
|
||||
assertNull(errorHandler.getLastError());
|
||||
channel.send(new StringMessage("test"));
|
||||
assertNotNull(errorHandler.getLastError());
|
||||
assertEquals("intentional test failure", errorHandler.getLastError().getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="channel"/>
|
||||
|
||||
<service-activator id="endpoint" input-channel="channel" ref="testBean" error-handler="errorHandler"/>
|
||||
|
||||
<beans:bean id="testBean" class="org.springframework.integration.config.ExceptionThrowingTestBean"/>
|
||||
|
||||
<beans:bean id="errorHandler" class="org.springframework.integration.config.TestErrorHandler"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
@@ -98,17 +99,14 @@ public class ReturnAddressTests {
|
||||
assertNull(channel2.receive(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = ChannelResolutionException.class)
|
||||
public void returnAddressFallbackButNotAvailable() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||
PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
|
||||
context.start();
|
||||
StringMessage message = new StringMessage("*");
|
||||
channel3.send(message);
|
||||
Message<?> errorMessage = errorChannel.receive(3000);
|
||||
assertNotNull(errorMessage.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,19 +21,12 @@
|
||||
<si:channel id="replyChannel">
|
||||
<si:queue capacity="5"/>
|
||||
</si:channel>
|
||||
<si:channel id="errorChannel">
|
||||
<si:queue capacity="5"/>
|
||||
</si:channel>
|
||||
|
||||
<si:service-activator input-channel="channel1" ref="testBean" method="duplicate" output-channel="channel2"/>
|
||||
<si:service-activator input-channel="channel2" ref="testBean" method="duplicate" output-channel="channel3"/>
|
||||
<si:service-activator input-channel="channel3" ref="testBean" method="duplicate" error-handler="errorHandler"/>
|
||||
<si:service-activator input-channel="channel3" ref="testBean" method="duplicate"/>
|
||||
<si:service-activator input-channel="channel4" ref="testBean" method="duplicate" output-channel="replyChannel"/>
|
||||
|
||||
<bean id="errorHandler" class="org.springframework.integration.channel.MessagePublishingErrorHandler">
|
||||
<property name="errorChannel" ref="errorChannel"/>
|
||||
</bean>
|
||||
|
||||
<bean id="testBean" class="org.springframework.integration.endpoint.TestBean"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user