cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject cxf git commit: [CXF-6585] Make sure the 1.2 faults meet the spec
Date Tue, 08 Sep 2015 20:08:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3fbfb800d -> 94a6c2439


[CXF-6585] Make sure the 1.2 faults meet the spec


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/94a6c243
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/94a6c243
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/94a6c243

Branch: refs/heads/master
Commit: 94a6c24399cfa0326edfeb669c770adee6f9c773
Parents: 3fbfb80
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Sep 8 16:08:13 2015 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Sep 8 16:08:13 2015 -0400

----------------------------------------------------------------------
 .../org/apache/cxf/binding/soap/SoapFault.java  | 32 +++++++++++++++++++-
 .../interceptor/SoapFaultSerializerTest.java    |  8 ++++-
 .../ws/addressing/impl/ContextUtilsTest.java    |  2 ++
 3 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/94a6c243/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
index 205eecc..bd1fdda 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
@@ -204,6 +204,31 @@ public class SoapFault extends Fault {
         this.namespaces = namespaces;
     }
 
+    private static void updateSoap12FaultCodes(SoapFault f) {
+        //per Soap 1.2 spec, the fault code MUST be one of the 5 values specified in the
spec.
+        //Soap 1.1 allows the soap fault code to be arbitrary (recommends the 4 values in
the spec, but
+        //explicitely mentions that it can be extended to include additional codes).   Soap
1.2 however
+        //requires the use of one of the 5 defined codes.  Additional detail or more specific
information
+        //can be transferred via the SubCodes.
+        QName fc = f.getFaultCode();
+        SoapVersion v = Soap12.getInstance();
+        if (fc.getNamespaceURI().equals(Soap12.SOAP_NAMESPACE)
+            && (fc.equals(v.getReceiver())
+                || fc.equals(v.getSender())
+                || fc.equals(v.getMustUnderstand())
+                || fc.equals(v.getDateEncodingUnknown())
+                || fc.equals(v.getVersionMismatch()))) {
+            //valid fault codes, don't change anything
+            return;
+        }
+        f.setFaultCode(Soap12.getInstance().getReceiver());
+        
+        if (f.getSubCodes() == null) {
+            f.setRootSubCode(fc);
+        } else if (!f.getSubCodes().contains(fc)) {
+            f.getSubCodes().add(fc);
+        }
+    }
     public static SoapFault createFault(Fault f, SoapVersion v) {
         if (f instanceof SoapFault) {
             //make sure the fault code is per spec
@@ -217,6 +242,9 @@ public class SoapFault extends Fault {
                 }
                 f.setFaultCode(fc);
             }
+            if (v == Soap12.getInstance()) {
+                updateSoap12FaultCodes((SoapFault)f);
+            }
             return (SoapFault)f;
         }
 
@@ -229,7 +257,9 @@ public class SoapFault extends Fault {
         SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null),
                                             f.getCause(),
                                             fc);
-        
+        if (v == Soap12.getInstance()) {
+            updateSoap12FaultCodes(soapFault);
+        }
         soapFault.setDetail(f.getDetail());
         return soapFault;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/94a6c243/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
b/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
index e1bccdd..4304c1c 100644
--- a/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
+++ b/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
@@ -238,12 +238,18 @@ public class SoapFaultSerializerTest extends Assert {
         ex = new Exception("fault-two");
         fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
         verifyFaultToSoapFault(fault, "fault-two", true, Soap11.getInstance());
+        
+        fault = new Fault(ex, new QName("http://cxf.apache.org", "myFaultCode"));
+        SoapFault f = verifyFaultToSoapFault(fault, "fault-two", false, Soap12.getInstance());
+        assertEquals("myFaultCode", f.getSubCodes().get(0).getLocalPart());
+
     }
     
-    private void verifyFaultToSoapFault(Fault fault, String msg, boolean sender, SoapVersion
v) {
+    private SoapFault 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());
+        return sf;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/94a6c243/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
index c4915e8..5814bd1 100755
--- a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
+++ b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
@@ -216,5 +216,7 @@ public class ContextUtilsTest extends Assert {
     
     @WebFault(name = "testFault", targetNamespace = "urn:foo:test:7")
     public class TestFault extends Exception {
+
+        private static final long serialVersionUID = 1L;
     }
 }


Mime
View raw message