View Javadoc

1   /*
2    * $Id: DefaultSystemExceptionStrategy.java 19191 2010-08-25 21:05:23Z tcarlson $
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.exception;
12  
13  import org.mule.RequestContext;
14  import org.mule.api.MuleContext;
15  import org.mule.api.exception.SystemExceptionHandler;
16  import org.mule.context.notification.ExceptionNotification;
17  import org.mule.message.DefaultExceptionPayload;
18  
19  /**
20   * Log exception, fire a notification, and clean up transaction if any.
21   */
22  public class DefaultSystemExceptionStrategy extends AbstractExceptionListener implements SystemExceptionHandler
23  {
24      /** 
25       * For IoC only 
26       * @deprecated Use DefaultSystemExceptionStrategy(MuleContext muleContext) instead 
27       */
28      public DefaultSystemExceptionStrategy()
29      {
30          super();
31      }
32      
33      public DefaultSystemExceptionStrategy(MuleContext muleContext)
34      {
35          super();
36          setMuleContext(muleContext);
37      }
38  
39      public void handleException(Exception e)
40      {
41          if (enableNotifications)
42          {
43              fireNotification(new ExceptionNotification(e));
44          }
45  
46          logException(e);
47          
48          handleTransaction(e);
49  
50          if (RequestContext.getEvent() != null)
51          {
52              RequestContext.setExceptionPayload(new DefaultExceptionPayload(e));
53          }
54      }
55  }