On Wed, May 21, 2008 at 2:50 AM, pratibhaG <[EMAIL PROTECTED]> wrote:
>
> 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?

An ExchangeListener is going to get a copy of every message exchange
that comes through the NMR. The analyzeException() method is simply a
method that I put together for a customer who needed to enhance the
error message on exceptions. You'll need to customize the class based
on your requirements. Once it is customized, jar up the class, dropped
it in the SMX lib directory and then add an element to the
conf/servicemix.xml configuration to register it. Below is an example:

<sm:listeners>
  <bean class="full.package.path.to.ExceptionListenerService" />
</sm:listeners>

The example <sm:listeners> element above will register the
ExceptionListenerService class as an exchange listener with
ServiceMix, allowing the exchangeAccepted() and exchangeSent() methods
to be invoked by ServiceMix when a message exchange comes through the
NMR.

Bruce
-- 
perl -e 'print unpack("u30","D0G)[EMAIL 
PROTECTED]&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/

Blog: http://bruceblog.org/

Reply via email to