cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1307039 - in /cxf/trunk/rt/bindings/soap/src: main/java/org/apache/cxf/binding/soap/interceptor/ main/java/org/apache/cxf/binding/soap/saaj/ test/java/org/apache/cxf/binding/soap/interceptor/
Date Thu, 29 Mar 2012 18:41:12 GMT
Author: dkulp
Date: Thu Mar 29 18:41:12 2012
New Revision: 1307039

URL: http://svn.apache.org/viewvc?rev=1307039&view=rev
Log:
[CXF-4181] More work with getting the fault details "correct" along with
fixing some prefix issues with SAAJ implementations.

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/cxf4181.xml

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java?rev=1307039&r1=1307038&r2=1307039&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
Thu Mar 29 18:41:12 2012
@@ -198,7 +198,7 @@ public class ReadHeadersInterceptor exte
                             }
                         }
                         
-                        HeaderProcessor p = bus.getExtension(HeaderManager.class)
+                        HeaderProcessor p = bus == null ? null : bus.getExtension(HeaderManager.class)
                             .getHeaderProcessor(hel.getNamespaceURI());
 
                         Object obj;

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java?rev=1307039&r1=1307038&r2=1307039&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultInInterceptor.java
Thu Mar 29 18:41:12 2012
@@ -41,6 +41,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.FragmentStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamReader;
 
 public class Soap12FaultInInterceptor extends AbstractSoapInterceptor {
     
@@ -72,9 +73,13 @@ public class Soap12FaultInInterceptor ex
         XPathUtils xu = new XPathUtils(ns);        
         try {
             Node mainNode = message.getContent(Node.class);
-            
             Node fault = null;
-            if (mainNode != null) {
+            
+            if (reader instanceof W3CDOMStreamReader) {
+                W3CDOMStreamReader dr = (W3CDOMStreamReader)reader;
+                fault = dr.getCurrentElement();
+                dr.consumeFrame();
+            } else if (mainNode != null) {
                 Node bodyNode = (Node) xu.getValue("//s:Body",
                                                    mainNode,
                                                    XPathConstants.NODE);

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1307039&r1=1307038&r2=1307039&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
Thu Mar 29 18:41:12 2012
@@ -290,7 +290,7 @@ public class SAAJInInterceptor extends A
         }
         Element elem = DOMUtils.getFirstElement(header);
         while (elem != null) {
-            Bus b = message.getExchange().get(Bus.class);
+            Bus b = message.getExchange() == null ? null : message.getExchange().get(Bus.class);
             HeaderProcessor p =  null;
             if (b != null && b.getExtension(HeaderManager.class) != null) {
                 p = b.getExtension(HeaderManager.class).getHeaderProcessor(elem.getNamespaceURI());

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java?rev=1307039&r1=1307038&r2=1307039&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
Thu Mar 29 18:41:12 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.binding.soap.saaj;
 
+import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPPart;
@@ -35,25 +36,42 @@ public final class SAAJStreamWriter exte
         this.part = part;
     }
 
+    private SOAPElement adjustPrefix(SOAPElement e, String prefix) {
+        if (prefix == null) {
+            prefix = "";
+        }
+        try {
+            String s = e.getPrefix();
+            if (!prefix.equals(s)) {
+                e.setPrefix(prefix);
+                e.removeNamespaceDeclaration(s);
+            }
+        } catch (Throwable t) {
+            //likely old old version of SAAJ, we'll just try our best
+        }
+        return e;
+    }
+    
     protected void createAndAddElement(String prefix, String local, String namespace) {
         try {
             if (namespace != null 
                 && namespace.equals(part.getEnvelope().getElementName().getURI()))
{
                 if ("Envelope".equals(local)) {
-                    setChild(part.getEnvelope(), false);
+                    setChild(adjustPrefix(part.getEnvelope(), prefix), false);
+                    adjustPrefix(part.getEnvelope().getHeader(), prefix);
                     return;
                 } else if ("Body".equals(local)) {
-                    setChild(part.getEnvelope().getBody(), false);
+                    setChild(adjustPrefix(part.getEnvelope().getBody(), prefix), false);
                     return;
                 } else if ("Header".equals(local)) {
-                    setChild(part.getEnvelope().getHeader(), false);
+                    setChild(adjustPrefix(part.getEnvelope().getHeader(), prefix), false);
                     return;
                 } else if ("Fault".equals(local)) {
                     SOAPFault f = part.getEnvelope().getBody().getFault();
                     if (f == null) {
                         f = part.getEnvelope().getBody().addFault();
                     }
-                    setChild(f, false);
+                    setChild(adjustPrefix(f, prefix), false);
                     return;
                 }
             } else if (getCurrentNode() instanceof SOAPFault) {

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=1307039&r1=1307038&r2=1307039&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 Mar 29 18:41:12 2012
@@ -23,10 +23,14 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
 import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPPart;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.Soap12;
@@ -34,6 +38,8 @@ import org.apache.cxf.binding.soap.SoapF
 import org.apache.cxf.binding.soap.SoapMessage;
 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;
+import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.ExchangeImpl;
@@ -180,25 +186,69 @@ public class SoapFaultSerializerTest ext
 
     @Test
     public void testCXF4181() throws Exception {
-
+        //Try WITH SAAJ
         SoapMessage m = new SoapMessage(new MessageImpl());
         m.setVersion(Soap12.getInstance());        
-
-
         XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass()
                                                                  .getResourceAsStream("cxf4181.xml"));
 
         m.setContent(XMLStreamReader.class, reader);
 
+        new SAAJPreInInterceptor().handleMessage(m);
         new ReadHeadersInterceptor(null).handleMessage(m);
-        Soap12FaultInInterceptor inInterceptor = new Soap12FaultInInterceptor();
-        inInterceptor.handleMessage(m);
-
+        new StartBodyInterceptor().handleMessage(m);
+        new SAAJInInterceptor().handleMessage(m);
+        new Soap12FaultInInterceptor().handleMessage(m);
+
+        Node nd = m.getContent(Node.class);
+        
+        SOAPPart part = (SOAPPart)nd;
+        assertEquals("S", part.getEnvelope().getPrefix());
+        assertEquals("S2", part.getEnvelope().getHeader().getPrefix());
+        assertEquals("S3", part.getEnvelope().getBody().getPrefix());
+        SOAPFault fault = part.getEnvelope().getBody().getFault();
+        assertEquals("S", fault.getPrefix());
+        
+        assertEquals("Authentication Failure", fault.getFaultString());
+        
         SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
         assertNotNull(fault2);
         
         assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
         assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"),

                      fault2.getSubCode());
+        
+        Element el = part.getEnvelope().getBody();
+        nd = el.getFirstChild();
+        int count = 0;
+        while (nd != null) {
+            if (nd instanceof Element) {
+                count++;
+            }
+            nd = nd.getNextSibling();
+        }
+        assertEquals(1, count);
+        
+        
+        //Try WITHOUT SAAJ
+        m = new SoapMessage(new MessageImpl());
+        m.setVersion(Soap12.getInstance());  
+        reader = StaxUtils.createXMLStreamReader(this.getClass()
+                                                 .getResourceAsStream("cxf4181.xml"));
+
+        m.setContent(XMLStreamReader.class, reader);
+
+        new ReadHeadersInterceptor(null).handleMessage(m);
+        new StartBodyInterceptor().handleMessage(m);
+        new Soap12FaultInInterceptor().handleMessage(m);
+
+        nd = m.getContent(Node.class);
+
+        fault2 = (SoapFault)m.getContent(Exception.class);
+        assertNotNull(fault2);
+
+        assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
+        assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"),

+             fault2.getSubCode());
     }
 }

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/cxf4181.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/cxf4181.xml?rev=1307039&r1=1307038&r2=1307039&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/cxf4181.xml
(original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/cxf4181.xml
Thu Mar 29 18:41:12 2012
@@ -2,7 +2,10 @@
             xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"

             xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"

             xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust">
-  <S:Body>
+  <S2:Header xmlns:S2="http://www.w3.org/2003/05/soap-envelope">
+     <foo:blah xmlns:foo="http://cxf.apache.org/test">Snarf</foo:blah>
+  </S2:Header>
+  <S3:Body xmlns:S3="http://www.w3.org/2003/05/soap-envelope">
     <S:Fault>
       <S:Code>
         <S:Value>S:Sender</S:Value>
@@ -14,5 +17,5 @@
         <S:Text xml:lang="en-US">Authentication Failure</S:Text>
       </S:Reason>
     </S:Fault>
-  </S:Body>
+  </S3:Body>
 </S:Envelope>



Mime
View raw message