View Javadoc

1   /*
2    * $Id: AxisFaultExceptionReader.java 7976 2007-08-21 14:26:13Z 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   * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26   * @version $Revision: 7976 $
27   */
28  public class AxisFaultExceptionReader implements ExceptionReader
29  {
30  
31      public String getMessage(Throwable t)
32      {
33          AxisFault e = (AxisFault)t;
34          Map props = getInfo(e);
35          StringBuffer msg = new StringBuffer(64);
36          msg.append("(");
37          for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();)
38          {
39              Map.Entry entry = (Map.Entry)iterator.next();
40              msg.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
41          }
42          msg.append(")");
43          return e.getMessage() + msg.toString();
44      }
45  
46      public Throwable getCause(Throwable t)
47      {
48          AxisFault e = (AxisFault)t;
49          Throwable cause = e.detail;
50          if (cause == null)
51          {
52              cause = e.getCause();
53          }
54          return cause;
55      }
56  
57      public Class getExceptionType()
58      {
59          return AxisFault.class;
60      }
61  
62      /**
63       * Returns a map of the non-stanard information stored on the exception
64       * 
65       * @return a map of the non-stanard information stored on the exception
66       */
67      public Map getInfo(Throwable t)
68      {
69          AxisFault e = (AxisFault)t;
70          Map info = new HashMap();
71          info.put("Fault", e.getFaultString());
72          info.put("Fault Code", e.getFaultCode().toString());
73          info.put("Fault Actor", e.getFaultActor());
74          info.put("Fault Node", e.getFaultNode());
75          info.put("Fault Reason", e.getFaultReason());
76          info.put("Fault Role", e.getFaultRole());
77          info.put("Fault Dump", e.dumpToString());
78          // Todo Do we need to out put headers and elements or are these part of the
79          // dumpToString??
80          return info;
81      }
82  }