View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.context.notification;
8   
9   import org.apache.commons.lang.exception.ExceptionUtils;
10  import org.mule.api.context.notification.ServerNotification;
11  
12  /**
13   * This class is from Mule 2.2.5. It is modified so the ExceptionNotification has a
14   * resourceId of the exception type. This is only here so we can avoid doing a hot
15   * fix of Mule to run MMC. This will be removed in future releases of MMC.
16   */
17  public class ExceptionNotification extends ServerNotification
18  {
19      /**
20       * Serial version.
21       */
22      private static final long serialVersionUID = -43091546451476239L;
23      public static final int EXCEPTION_ACTION = EXCEPTION_EVENT_ACTION_START_RANGE + 1;
24  
25      static
26      {
27          registerAction("exception", EXCEPTION_ACTION);
28      }
29  
30      private Throwable exception;
31  
32      public ExceptionNotification(Throwable exception)
33      {
34          super(exception, EXCEPTION_ACTION, getExceptionCause(exception));
35          this.exception = exception;
36      }
37  
38      /**
39       * Find the root cause of the exception as typically Mule wraps the exception in
40       * something like a ServiceException and when we register a listener under a
41       * particular resource ID we want to listen for this root cause, not the
42       * ServiceException.
43       * 
44       * @param exception
45       * @return
46       */
47      private static String getExceptionCause(Throwable exception)
48      {
49          Throwable cause = ExceptionUtils.getRootCause(exception);
50          if (cause != null)
51          {
52              return cause.getClass().getName();
53          }
54          else
55          {
56              return null;
57          }
58      }
59  
60      public Throwable getException()
61      {
62          return this.exception;
63      }
64  
65      @Override
66      public String getType()
67      {
68          return TYPE_ERROR;
69      }
70  }