cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1421414 - in /cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/Fault.java rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
Date Thu, 13 Dec 2012 18:18:22 GMT
Author: ay
Date: Thu Dec 13 18:18:20 2012
New Revision: 1421414

URL: http://svn.apache.org/viewvc?rev=1421414&view=rev
Log:
[CXF-4684] SOAPFault message improvement in CXF

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java?rev=1421414&r1=1421413&r2=1421414&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java Thu Dec 13 18:18:20
2012
@@ -85,7 +85,7 @@ public class Fault extends UncheckedExce
         if (super.getMessage() != null) {
             message = super.getMessage();
         } else {
-            message = t == null ? null : t.getMessage();
+            message = getMessage(t);
         }
         code = FAULT_CODE_SERVER;
     }
@@ -107,7 +107,7 @@ public class Fault extends UncheckedExce
         if (super.getMessage() != null) {
             message = super.getMessage();
         } else {
-            message = t == null ? null : t.getMessage();
+            message = getMessage(t);
         }
         code = fc;
     }    
@@ -185,4 +185,13 @@ public class Fault extends UncheckedExce
     public void setStatusCode(int statusCode) {
         this.statusCode = statusCode;
     }
+
+    /**
+     * Extracts the effective message value from the specified exception object
+     * @param t
+     * @return
+     */
+    private static String getMessage(Throwable t) {
+        return t == null ? null : t.getMessage() != null ? t.getMessage() : t.toString();
+    }
 }

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java?rev=1421414&r1=1421413&r2=1421414&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
Thu Dec 13 18:18:20 2012
@@ -36,6 +36,7 @@ import org.apache.cxf.binding.soap.Soap1
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor.Soap11FaultOutInterceptorInternal;
 import org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor.Soap12FaultOutInterceptorInternal;
 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
@@ -146,23 +147,27 @@ public class SoapFaultSerializerTest ext
     public void testFaultToSoapFault() throws Exception {
         Exception ex = new Exception();
         Fault fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
-        
-        SoapFault sf = SoapFault.createFault(fault, Soap11.getInstance());
-        assertEquals(Soap11.getInstance().getSender(), sf.getFaultCode());
-        
-        sf = SoapFault.createFault(fault, Soap12.getInstance());
-        assertEquals(Soap12.getInstance().getSender(), sf.getFaultCode());
+        verifyFaultToSoapFault(fault, ex.toString(), true, Soap11.getInstance());
+        verifyFaultToSoapFault(fault, ex.toString(), true, Soap12.getInstance());
         
         fault = new Fault(ex, Fault.FAULT_CODE_SERVER);
-        sf = SoapFault.createFault(fault, Soap11.getInstance());
-        assertEquals(Soap11.getInstance().getReceiver(), sf.getFaultCode());
-        
-        sf = SoapFault.createFault(fault, Soap12.getInstance());
-        assertEquals(Soap12.getInstance().getReceiver(), sf.getFaultCode());
+        verifyFaultToSoapFault(fault, ex.toString(), false, Soap11.getInstance());
+        verifyFaultToSoapFault(fault, ex.toString(), false, Soap12.getInstance());
         
+        fault.setMessage("fault-one");
+        verifyFaultToSoapFault(fault, "fault-one", false, Soap11.getInstance());
+
+        ex = new Exception("fault-two");
+        fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
+        verifyFaultToSoapFault(fault, "fault-two", true, Soap11.getInstance());
     }
     
-    
+    private void verifyFaultToSoapFault(Fault fault, String msg, boolean sender, SoapVersion
v) {
+        SoapFault sf = SoapFault.createFault(fault, v);
+        assertEquals(sender ? v.getSender() : v.getReceiver(), sf.getFaultCode());
+        assertEquals(msg, sf.getMessage());
+    }
+
     @Test
     public void testCXF1864() throws Exception {
 



Mime
View raw message