View Javadoc

1   /*
2    * $Id: ExceptionNotification.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.context.notification;
12  
13  import org.apache.commons.lang.exception.ExceptionUtils;
14  import org.mule.api.context.notification.ServerNotification;
15  
16  /**
17   * This class is from Mule 2.2.5. It is modified so the ExceptionNotification has a
18   * resourceId of the exception type. This is only here so we can avoid doing a hot
19   * fix of Mule to run MMC. This will be removed in future releases of MMC.
20   */
21  public class ExceptionNotification extends ServerNotification
22  {
23      /**
24       * Serial version.
25       */
26      private static final long serialVersionUID = -43091546451476239L;
27      public static final int EXCEPTION_ACTION = EXCEPTION_EVENT_ACTION_START_RANGE + 1;
28  
29      static
30      {
31          registerAction("exception", EXCEPTION_ACTION);
32      }
33  
34      private Throwable exception;
35  
36      public ExceptionNotification(Throwable exception)
37      {
38          super(exception, EXCEPTION_ACTION, getExceptionCause(exception));
39          this.exception = exception;
40      }
41  
42      /**
43       * Find the root cause of the exception as typically Mule wraps the exception in
44       * something like a ServiceException and when we register a listener under a
45       * particular resource ID we want to listen for this root cause, not the
46       * ServiceException.
47       * 
48       * @param exception
49       * @return
50       */
51      private static String getExceptionCause(Throwable exception)
52      {
53          Throwable cause = ExceptionUtils.getRootCause(exception);
54          if (cause != null)
55          {
56              return cause.getClass().getName();
57          }
58          else
59          {
60              return null;
61          }
62      }
63  
64      public Throwable getException()
65      {
66          return this.exception;
67      }
68  
69      @Override
70      public String getType()
71      {
72          return TYPE_ERROR;
73      }
74  }