Hi Bruce/Guillaume

I followed the approach suggested by you with the message listener and it
works great ! I need to improve the error handling part with user
friendly messages but just being able to get to the exception message is
great.

Thanks a million !



On Sat, Mar 1, 2008 at 5:55 AM, Bruce Snyder <[EMAIL PROTECTED]> wrote:

>  On Fri, Feb 29, 2008 at 3:27 PM, Tropi Geek <[EMAIL PROTECTED]> wrote:
> > Guys, things seem to be working very well with servicemix but one of the
> >  challenges I am facing is to track errors happening at component level.
> >
> >  Is there a generic listener that I can use/implement to listen to all
> >  exceptions and then send it to a common exception queue component. I
> need to
> >  report issues back to the requesting application. I can do that with
> most
> >  bean/pojo components in a  try/catch block but not with any components.
> >
> >  Seems like a generic problem but I dont seem to be getting the right
> pointer
> >  for this. Kindly help.
>
> Well, you could create an ExchangeListener to capture every message
> exchange flowing through the NMR. This gives you the ability to
> manipulate the message exchanges however you like including checking
> for errors on the exchange. Below is an example of something I wrote
> to enhance the error messages on an exchange:
>
> package org.apache.servicemix.jbi.exceptions;
>
> import javax.jbi.messaging.MessageExchange;
>
> import org.apache.servicemix.jbi.event.ExchangeEvent;
> import org.apache.servicemix.jbi.event.ExchangeListener;
>
> /**
>  * An [EMAIL PROTECTED] org.apache.servicemix.jbi.event.ExchangeListener}
> implementation
>  * to handle exception customization.
>  *
>  * @org.apache.xbean.XBean element="exceptionListenerService"
>  * @version $Revision$
>  * @author bsnyder
>  */
> public 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);
>    }
>
> }
>
> To use this with ServiceMIx, you simply register it as a service in
> the servicemix.xml file using the XBean element in the class level
> XBean annotation (exceptionListenerService).
>
> 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