cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r743087 - in /cxf/trunk/rt: core/src/main/java/org/apache/cxf/interceptor/ core/src/main/java/org/apache/cxf/service/invoker/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/
Date Tue, 10 Feb 2009 20:29:04 GMT
Author: dkulp
Date: Tue Feb 10 20:29:03 2009
New Revision: 743087

URL: http://svn.apache.org/viewvc?rev=743087&view=rev
Log:
[CXF-973, CXF-2025] Fixes for various fault related issues
Patches from Will Gomes and Kaj Kandler applied

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.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=743087&r1=743086&r2=743087&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 Tue
Feb 10 20:29:03 2009
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -148,8 +149,14 @@
                     Constructor constructor = exClass.getConstructor(new Class[]{String.class});
                     e = constructor.newInstance(new Object[]{fault.getMessage()});
                 } else {
-                    Constructor constructor = getConstructor(exClass, e);
-                    e = constructor.newInstance(new Object[]{fault.getMessage(), e});
+                
+                    try {
+                        Constructor constructor = getConstructor(exClass, e);
+                        e = constructor.newInstance(new Object[]{fault.getMessage(), e});
+                    } catch (NoSuchMethodException e1) {
+                        //Use reflection to convert fault bean to exception
+                        e = convertFaultBean(exClass, e, fault);
+                    }
                 }
                 msg.setContent(Exception.class, e);
             } catch (Exception e1) {
@@ -243,4 +250,47 @@
         }
         return null;
     }
+    
+    private Exception convertFaultBean(Class<?> exClass, Object faultBean, Fault fault)
throws Exception {
+        Constructor constructor = exClass.getConstructor(new Class[]{String.class});
+        Exception e = (Exception)constructor.newInstance(new Object[]{fault.getMessage()});
+
+        //Copy fault bean fields to exception
+        for (Class<?> obj = exClass; !obj.equals(Object.class);  obj = obj.getSuperclass())
{   
+            Field[] fields = obj.getDeclaredFields();
+            for (Field f : fields) {
+                try {
+                    Field beanField = faultBean.getClass().getDeclaredField(f.getName());
+                    beanField.setAccessible(true);                    
+                    f.setAccessible(true);
+                    f.set(e, beanField.get(faultBean));
+                } catch (NoSuchFieldException e1) {
+                    //do nothing
+                }
+            }            
+        }
+        //also use/try public getter/setter methods
+        Method meth[] = faultBean.getClass().getMethods();
+        for (Method m : meth) {
+            if (m.getParameterTypes().length == 0
+                && (m.getName().startsWith("get")
+                || m.getName().startsWith("is"))) {
+                try {
+                    String name;
+                    if (m.getName().startsWith("get")) {
+                        name = "set" + m.getName().substring(3);
+                    } else {
+                        name = "set" + m.getName().substring(2);
+                    }
+                    Method m2 = exClass.getMethod(name, m.getReturnType());
+                    m2.invoke(e, m.invoke(faultBean));
+                } catch (Exception e1) {
+                    //ignore
+                }
+            }
+        }
+
+
+        return e;
+    }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java?rev=743087&r1=743086&r2=743087&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java Tue
Feb 10 20:29:03 2009
@@ -147,10 +147,11 @@
         if (checked) {
             return new Fault(ex);
         } else {
-            return new Fault(new Message("EXCEPTION_INVOKING_OBJECT",
-                                         LOG,
-                                         ex.getMessage(), m.toString(), params),
-                                         ex);
+            String message = (ex == null) ? "" : ex.getMessage(); 
+            String method = (m == null) ? "<null>" : m.toString(); 
+            return new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, 
+                                         message, method, params),
+                                         ex); 
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java?rev=743087&r1=743086&r2=743087&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
Tue Feb 10 20:29:03 2009
@@ -141,15 +141,13 @@
                             && (m.getName().startsWith("get")
                             || m.getName().startsWith("is"))) {
                             try {
-                                Method m2 = cls.getMethod(m.getName(),
-                                                          m.getParameterTypes());
                                 String name;
                                 if (m.getName().startsWith("get")) {
                                     name = "set" + m.getName().substring(3);
                                 } else {
                                     name = "set" + m.getName().substring(2);
                                 }
-                                m2 = cls.getMethod(name, m.getReturnType());
+                                Method m2 = cls.getMethod(name, m.getReturnType());
                                 m2.invoke(ret, m.invoke(cause));
                             } catch (Exception e) {
                                 //ignore



Mime
View raw message