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.soap.axis;
8   
9   import org.mule.api.config.ExceptionReader;
10  
11  import java.util.HashMap;
12  import java.util.Map;
13  
14  import org.apache.axis.AxisFault;
15  
16  /**
17   * Will format and display additional information stored with an Axis fault that is
18   * usually hidden when logged.
19   */
20  public class AxisFaultExceptionReader implements ExceptionReader
21  {
22  
23      public String getMessage(Throwable t)
24      {
25          AxisFault e = (AxisFault)t;
26          Map<?, ?> props = getInfo(e);
27          StringBuffer msg = new StringBuffer(64);
28          msg.append("(");
29          for (Map.Entry<?, ?> entry : props.entrySet())
30          {
31              msg.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
32          }
33          msg.append(")");
34          return e.getMessage() + msg.toString();
35      }
36  
37      public Throwable getCause(Throwable t)
38      {
39          AxisFault e = (AxisFault)t;
40          Throwable cause = e.detail;
41          if (cause == null)
42          {
43              cause = e.getCause();
44          }
45          return cause;
46      }
47  
48      public Class<?> getExceptionType()
49      {
50          return AxisFault.class;
51      }
52  
53      /**
54       * Returns a map of the non-stanard information stored on the exception
55       * 
56       * @return a map of the non-stanard information stored on the exception
57       */
58      public Map<?, ?> getInfo(Throwable t)
59      {
60          AxisFault e = (AxisFault)t;
61          Map<String, Object> info = new HashMap<String, Object>();
62          info.put("Fault", e.getFaultString());
63          info.put("Fault Code", e.getFaultCode().toString());
64          info.put("Fault Actor", e.getFaultActor());
65          info.put("Fault Node", e.getFaultNode());
66          info.put("Fault Reason", e.getFaultReason());
67          info.put("Fault Role", e.getFaultRole());
68          info.put("Fault Dump", e.dumpToString());
69          // Todo Do we need to out put headers and elements or are these part of the
70          // dumpToString??
71          return info;
72      }
73  }