cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r736738 - /cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
Date Thu, 22 Jan 2009 18:37:49 GMT
Author: dkulp
Date: Thu Jan 22 10:37:48 2009
New Revision: 736738

URL: http://svn.apache.org/viewvc?rev=736738&view=rev
Log:
Better fault constructor logic

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java?rev=736738&r1=736737&r2=736738&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java Thu
Jan 22 10:37:48 2009
@@ -148,18 +148,7 @@
                     Constructor constructor = exClass.getConstructor(new Class[]{String.class});
                     e = constructor.newInstance(new Object[]{fault.getMessage()});
                 } else {
-                    Class<?> beanClass = e.getClass();
-                    Constructor constructor = null;
-                    try {
-                        constructor = exClass.getConstructor(new Class[]{String.class, beanClass});
-                    } catch (NoSuchMethodException ex) {
-                        Class<?> cls = getPrimitiveClass(beanClass);
-                        if (cls != null) {
-                            constructor = exClass.getConstructor(new Class[]{String.class,
cls});
-                        } else {
-                            throw ex;
-                        }
-                    }
+                    Constructor constructor = getConstructor(exClass, e);
                     e = constructor.newInstance(new Object[]{fault.getMessage(), e});
                 }
                 msg.setContent(Exception.class, e);
@@ -179,7 +168,29 @@
             }
             msg.setContent(Exception.class, e);
         }
-        
+    }
+    
+    private Constructor getConstructor(Class<?> faultClass, Object e) throws NoSuchMethodException
{
+        Class<?> beanClass = e.getClass();
+        Constructor cons[] = faultClass.getConstructors();
+        for (Constructor c : cons) {
+            if (c.getParameterTypes().length == 2
+                && String.class.equals(c.getParameterTypes()[0])
+                && c.getParameterTypes()[1].isInstance(e)) {
+                return c;
+            }
+        }
+        try {
+            return faultClass.getConstructor(new Class[]{String.class, beanClass});
+        } catch (NoSuchMethodException ex) {
+            Class<?> cls = getPrimitiveClass(beanClass);
+            if (cls != null) {
+                return faultClass.getConstructor(new Class[]{String.class, cls});
+            } else {
+                throw ex;
+            }
+        }
+
     }
 
     private boolean isDOMSupported(DataBinding db) {



Mime
View raw message