Java Reference
In-Depth Information
Use Spring Integration's support for an error channel, both implicit and explicitly via code. This solution
works only for solutions that employ channels whose messages are received out of the client's thread.
How It Works
Spring Integration provides the ability to catch exceptions and send them to an error channel of your
choosing. By default, it's a global channel called errorChannel . You can have components subscribe to
messages from this channel to override the exception handling behavior. You can create a class that will
be invoked whenever a message comes in on the errorChannel channel:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans=""
<beans:bean id="defaultErrorHandlingServiceActivator"
<service-activator input-channel="errorChannel" ref="defaultErrorHandling
The Java code is exactly as you'd expect it to be. Of course, the service-activator doesn't need
to be a service-activator . I just use it for convenience here. You could as easily send the error out on a
channel to anywhere you want. The code for the following service-activator depicts some of the
machinations you might go through to build a handler for the errorChannel :
package com.apress.springenterpriserecipes.springintegration;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessagingException;
public class DefaultErrorHandlingServiceActivator {
private static final Logger logger =
Logger.getLogger( DefaultErrorHandlingServiceActivator.class );
public void handleThrowable(Message<Throwable> errorMessage) throws Throwable {
Throwable throwable = errorMessage.getPayload();
logger.debug(String.format("message: %s, stack trace :%s",
if (throwable instanceof MessagingException) {
Message<?> failedMessage =
Search WWH ::

Custom Search