View Javadoc

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