Hi,
I want to listen to all the all the errors when my message passes through
bus. After doing some reading on forum, I think I should add a
messageExchangeListener which will listen to all errors.
I got this listener by Bruce's postpublic class ExceptionListenerService
implements ExchangeListener {

    public void exchangeAccepted(ExchangeEvent event) {
        // TODO Auto-generated method stub

    }

    public void exchangeSent(ExchangeEvent event) {
        MessageExchange me = event.getExchange();
        Exception exception = null;

        if (me.getError() != null) {
            exception = analyzeException(me);
        }

        me.setError(exception);
    }

    /**
     * This method abstracts any special exception handling behavior.
     *
     * @TODO Abstract this further using pluggable strategies to hold the
     * custom functionality. Then we just stuff the strategies that are
     * named in the servicemix.xml config into an array and just walk the
     * array, invoking the execute method on each strategy.
     *
     * @param error The exception that was thrown
     * @param endpointName The name of the endpoint that threw the exception
     * @return
     */
    private Exception analyzeException(MessageExchange me) {
        Exception error = me.getError();
        String serviceName = me.getEndpoint().getServiceName().toString();
        String endpointName = me.getEndpoint().getEndpointName();
        String errorMessage = error.getMessage();

        // Add calls to custom processing here

        StringBuilder newErrorMessage =
            new StringBuilder("The following error was caused by service:
[");
        newErrorMessage.append(serviceName != null ? serviceName : "null");
        newErrorMessage.append("] and endpoint: [");
        newErrorMessage.append(endpointName != null ? endpointName :
"null");
        newErrorMessage.append("] ");
        newErrorMessage.append("Original error: ");
        newErrorMessage.append(errorMessage);

        return new Exception(newErrorMessage.toString(), error);
    }

} 

Now how can I configure it in servicemix?

please help

Regard,
Pratibha
-- 
View this message in context: 
http://www.nabble.com/How-to-add-and-configure-a-messageExchangeListener-tp17358800p17358800.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to