cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r720290 - in /cxf/branches/2.1.x-fixes: rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ systests/src/test/java/org/apache/cxf/systest/handlers/
Date Mon, 24 Nov 2008 20:53:09 GMT
Author: eglynn
Date: Mon Nov 24 12:53:09 2008
New Revision: 720290

URL: http://svn.apache.org/viewvc?rev=720290&view=rev
Log:
Better assertion in HandlerInvocationTest

Modified:
    cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
    cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
    cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java

Modified: cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java?rev=720290&r1=720289&r2=720290&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
Mon Nov 24 12:53:09 2008
@@ -41,12 +41,17 @@
     }
 
     public void handleMessage(SoapMessage message) throws Fault {
+        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
+
+        message.setContent(Exception.class, unmarshalFault(message, reader));
+    }
+
+    public static SoapFault unmarshalFault(SoapMessage message, 
+                                           XMLStreamReader reader) {
         String exMessage = null;
         QName faultCode = null;
         String role = null;
         Element detail = null;
-
-        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
         
         try {
             while (reader.nextTag() == XMLStreamReader.START_ELEMENT) {
@@ -70,8 +75,6 @@
         SoapFault fault = new SoapFault(exMessage, faultCode);
         fault.setDetail(detail);
         fault.setRole(role);
-
-        message.setContent(Exception.class, fault);
+        return fault;
     }
-
 }

Modified: cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java?rev=720290&r1=720289&r2=720290&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
Mon Nov 24 12:53:09 2008
@@ -50,6 +50,12 @@
     }
 
     public void handleMessage(SoapMessage message) throws Fault {
+        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
+        message.setContent(Exception.class, unmarshalFault(message, reader));
+    }
+
+    public static SoapFault unmarshalFault(SoapMessage message, 
+                                           XMLStreamReader reader) {
         String exMessage = null;
         QName faultCode = null;
         QName subCode = null;
@@ -57,7 +63,6 @@
         String node = null;
         Element detail = null;
 
-        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
         Map<String, String> ns = new HashMap<String, String>();
         ns.put("s", Soap12.SOAP_NAMESPACE);
         XPathUtils xu = new XPathUtils(ns);        
@@ -106,8 +111,7 @@
         fault.setDetail(detail);
         fault.setRole(role);
         fault.setNode(node);
-
-        message.setContent(Exception.class, fault);
+        return fault;
     }
 
 }

Modified: cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=720290&r1=720289&r2=720290&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
Mon Nov 24 12:53:09 2008
@@ -28,6 +28,7 @@
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
@@ -45,6 +46,8 @@
 import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
+import org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor;
+import org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.headers.Header;
@@ -107,11 +110,38 @@
             }
             
             XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
-            StaxUtils.readDocElements(soapMessage.getSOAPBody(), xmlReader, true);
-            DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
-            xmlReader = StaxUtils.createXMLStreamReader(bodySource);
-            xmlReader.nextTag();
-            xmlReader.nextTag(); // move past body tag
+
+            if (hasFault(message, xmlReader)) {
+                SOAPFault soapFault = 
+                    soapMessage.getSOAPPart().getEnvelope().getBody().addFault();
+                SoapFault fault = 
+                    message.getVersion() instanceof Soap11 
+                    ? Soap11FaultInInterceptor.unmarshalFault(message, xmlReader)
+                    : Soap12FaultInInterceptor.unmarshalFault(message, xmlReader);
+                if (fault.getFaultCode() != null) {
+                    soapFault.setFaultCode(fault.getFaultCode());
+                }
+                if (fault.getMessage() != null) {
+                    soapFault.setFaultString(fault.getMessage());
+                }
+                if (fault.getRole() != null) {
+                    soapFault.setFaultActor(fault.getRole());
+                }
+                if (fault.getDetail() != null) {
+                    soapFault.addDetail().appendChild(
+                        soapMessage.getSOAPPart().importNode(
+                            fault.getDetail().getFirstChild(), true));
+                }
+
+                DOMSource bodySource = new DOMSource(soapFault);
+                xmlReader = StaxUtils.createXMLStreamReader(bodySource);
+            } else { 
+                StaxUtils.readDocElements(soapMessage.getSOAPBody(), xmlReader, true);
+                DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
+                xmlReader = StaxUtils.createXMLStreamReader(bodySource);
+                xmlReader.nextTag();
+                xmlReader.nextTag(); // move past body tag
+            }
             message.setContent(XMLStreamReader.class, xmlReader);           
         } catch (SOAPException soape) {
             throw new SoapFault(new org.apache.cxf.common.i18n.Message(
@@ -170,4 +200,14 @@
         }
     }
 
+
+    private static boolean hasFault(SoapMessage message, 
+                                    XMLStreamReader xmlReader) {
+        try {
+            QName name = xmlReader.getName();
+            return message.getVersion().getFault().equals(name);
+        } catch (Exception e) {
+            return false;
+        }
+    }
 }

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?rev=720290&r1=720289&r2=720290&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
Mon Nov 24 12:53:09 2008
@@ -967,10 +967,10 @@
                     if (!outbound) {
                         LogicalMessage msg = ctx.getMessage();
                         String payload = convertDOMToString(msg.getPayload());
-                        assertTrue(payload.indexOf(
-                            "<faultstring>"
-                            + "servant throws SOAPFaultException"
-                            + "</faultstring>") > -1);
+                        assertTrue("expected faultstring in: " + payload,
+                            payload.indexOf(
+                                "servant throws SOAPFaultException"
+                                + "</faultstring>") > -1);
                     }
                 } catch (Exception e) {
                     e.printStackTrace();



Mime
View raw message