View Javadoc

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