You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Jason Sweeney (JIRA)" <ax...@ws.apache.org> on 2005/08/29 21:57:04 UTC

[jira] Created: (AXIS-2197) Add custom AxisFault constructors through dynamic registration

Add custom AxisFault constructors through dynamic registration
--------------------------------------------------------------

         Key: AXIS-2197
         URL: http://issues.apache.org/jira/browse/AXIS-2197
     Project: Apache Axis
        Type: New Feature
  Components: Basic Architecture  
    Versions: 1.2.1    
 Environment: Unrelated to the current problem
 Reporter: Jason Sweeney


The Axis Fault element has business knowledge of the SOAP error structure.  It so happens that other applications might also have this knowledge within their exception structure.  However, when say a ACMEException is throw and caught by Axis, the conversion to an AxisFault object through the makeFault method is quite basic.  In particular, there is no control over setting details, code and subcode, etc.

It would be a very interesting feature to provide to the AxisFault class a series of exceptions for which specialized construction methods are available.

An example implementation is provided below as a cvs -diff.  Please note that the signature of the method is makeFault(Exception, AxisFault) because the first initialization of the fault is done with a private method of the AxisFault class.  Hence, it is the fault parameter that is augmented and adjusted based on the exception parameter information.



Index: AxisFault.java
===================================================================
RCS file: /home/cvspublic/ws-axis/java/src/org/apache/axis/AxisFault.java,v
retrieving revision 1.90
diff -u -r1.90 AxisFault.java
--- AxisFault.java	6 Jul 2005 06:21:58 -0000	1.90
+++ AxisFault.java	29 Aug 2005 19:55:28 -0000
@@ -18,7 +18,9 @@
 
 import java.io.PrintStream;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Vector;
 import java.io.PrintWriter;
@@ -76,6 +78,12 @@
     protected ArrayList faultHeaders = null;
 
     /**
+     * Map used to keep the product specific fault constructors
+     * See: http://issues.apache.org/jira/browse/AXIS-????
+     */
+    private static HashMap faultConstructors = new HashMap();
+    
+    /**
      * Make an AxisFault based on a passed Exception.  If the Exception is
      * already an AxisFault, simply use that.  Otherwise, wrap it in an
      * AxisFault.  If the Exception is an InvocationTargetException (which
@@ -98,8 +106,56 @@
             return (AxisFault)e;
         }
 
+        // Check if any other fault constructors are defined
+        // See: http://issues.apache.org/jira/browse/AXIS-????
+        if (faultConstructors.size() > 0)
+        {
+            Iterator itExceptions = faultConstructors.keySet().iterator();
+            while (itExceptions.hasNext())
+            {
+                Class faultException = (Class) itExceptions.next();
+                if (faultException.isInstance(e))
+                {
+                    Class constructorCls = (Class) faultConstructors.get(faultException);
+                    try
+                    {
+                        Method makeFault = constructorCls.getMethod("makeFault", new Class[]{Exception.class, AxisFault.class});
+                        return (AxisFault) makeFault.invoke(null, new Object[]{e, new AxisFault(e)});
+                    }
+                    catch (NoSuchMethodException nsme)
+                    {
+                        // Ignore exceptions thrown for the fault constructor
+                        // Default the creation of the fault to the main constructor
+                    }
+                    catch (IllegalAccessException iae)
+                    {
+                        // Ignore exceptions thrown for the fault constructor
+                        // Default the creation of the fault to the main constructor
+                    }
+                    catch (InvocationTargetException ite)
+                    {
+                        // Ignore exceptions thrown for the fault constructor
+                        // Default the creation of the fault to the main constructor
+                    }
+                }
+            }
+        }
+        
         return new AxisFault(e);
     }
+    
+    /**
+     * Register a product specific fault constructor enabling individual
+     * exceptions to control the SOAP related error information.
+     *
+     * @param pExceptionCls The class of exception to capture
+     * @param pConstructorCls The constructor class to use for the fault
+     */
+    public static void registerFaultConstructor(Class pExceptionCls, Class pConstructorCls)
+    {
+        // Add the fault constructor to the list
+        faultConstructors.put(pExceptionCls, pConstructorCls);
+    }
 
     /**
      * Make a fault in the <code>Constants.NS_URI_AXIS</code> namespace.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira