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.transport.jms;
8   
9   import org.mule.api.config.ExceptionReader;
10  
11  import java.util.HashMap;
12  import java.util.Map;
13  
14  import javax.jms.JMSException;
15  
16  /**
17   * This reader will ensure that the LinkedException and JMS code is not lost when
18   * printing the JMSException.
19   */
20  public class JmsExceptionReader implements ExceptionReader
21  {
22  
23      public String getMessage(Throwable t)
24      {
25          JMSException e = (JMSException)t;
26          return e.getMessage() + "(JMS Code: " + e.getErrorCode() + ")";
27      }
28  
29      public Throwable getCause(Throwable t)
30      {
31          JMSException e = (JMSException)t;
32          Throwable cause = e.getLinkedException();
33          if (cause == null)
34          {
35              cause = e.getCause();
36          }
37          return cause;
38      }
39  
40      public Class<?> getExceptionType()
41      {
42          return JMSException.class;
43      }
44  
45      /**
46       * Returns a map of the non-stanard information stored on the exception
47       * 
48       * @return a map of the non-stanard information stored on the exception
49       */
50      public Map<?, ?> getInfo(Throwable t)
51      {
52          JMSException e = (JMSException)t;
53          Map<String, Object> info = new HashMap<String, Object>();
54          info.put("JMS Code", e.getErrorCode());
55          return info;
56      }
57  
58  }