View Javadoc

1   /*
2    * $Id: ExceptionHandlingMessageProcessor.java 20465 2010-12-05 18:14:15Z mike.schilling $
3    * -------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.processor;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.config.ExceptionHelper;
16  import org.mule.message.DefaultExceptionPayload;
17  import org.mule.transport.NullPayload;
18  
19  public class ExceptionHandlingMessageProcessor extends AbstractInterceptingMessageProcessor
20  {
21      public MuleEvent process(MuleEvent event) throws MuleException
22      {
23          try
24          {
25              return processNext(event);
26          }
27          catch (Exception e)
28          {
29              e = (Exception) ExceptionHelper.sanitizeIfNeeded(e);
30              if (e instanceof InternalProcessingException)
31              {
32                  event.getMessage().setPayload(NullPayload.getInstance());
33                  event.getMessage().setExceptionPayload(new DefaultExceptionPayload(e));
34                  return event;
35              }
36              else
37              {
38                  return event.getFlowConstruct().getExceptionListener().handleException(e, event);
39              }
40          }
41      }
42  }