cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1446336 - in /cxf/trunk: api/src/main/java/org/apache/cxf/staxutils/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ systests/jaxws/src/test/java/org/apach...
Date Thu, 14 Feb 2013 21:27:18 GMT
Author: dkulp
Date: Thu Feb 14 21:27:18 2013
New Revision: 1446336

URL: http://svn.apache.org/r1446336
Log:
[CXF-4818] Fix problems with adding soap:Header things to existing MessageMode Provider/Dispatch

Added:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4818data.txt
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java?rev=1446336&r1=1446335&r2=1446336&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java Thu
Feb 14 21:27:18 2013
@@ -48,6 +48,9 @@ public class OverlayW3CDOMStreamWriter e
     public OverlayW3CDOMStreamWriter(Element e) {
         super(e);
     }
+    public OverlayW3CDOMStreamWriter(Document doc, Element e) {
+        super(doc, e);
+    }
     
     @Override
     public void writeEndElement() throws XMLStreamException {
@@ -68,6 +71,7 @@ public class OverlayW3CDOMStreamWriter e
                 if (nd2.getNodeType() == Node.ELEMENT_NODE 
                     && local.equals(nd2.getLocalName())
                     && StringUtils.isEmpty(nd2.getNamespaceURI())) {
+                    adjustOverlaidNode(nd2, null);
                     setChild((Element)nd2, false);
                     return;
                 }
@@ -78,6 +82,9 @@ public class OverlayW3CDOMStreamWriter e
         super.writeStartElement(local);
     }
 
+    protected void adjustOverlaidNode(Node nd2, String pfx) {
+    }
+
     public void writeStartElement(String namespace, String local) throws XMLStreamException
{
         isOverlaidStack.add(0, isOverlaid);
         if (isOverlaid) {
@@ -92,6 +99,7 @@ public class OverlayW3CDOMStreamWriter e
                 if (nd2.getNodeType() == Node.ELEMENT_NODE 
                     && local.equals(nd2.getLocalName())
                     && namespace.equals(nd2.getNamespaceURI())) {
+                    adjustOverlaidNode(nd2, "");
                     setChild((Element)nd2, false);
                     return;
                 }
@@ -121,6 +129,7 @@ public class OverlayW3CDOMStreamWriter e
                     if (nd2.getNodeType() == Node.ELEMENT_NODE 
                         && local.equals(nd2.getLocalName())
                         && namespace.equals(nd2.getNamespaceURI())) {
+                        adjustOverlaidNode(nd2, prefix);
                         setChild((Element)nd2, false);
                         return;
                     }

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=1446336&r1=1446335&r2=1446336&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 Feb 14 21:27:18 2013
@@ -27,9 +27,9 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+import org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter;
 
-public final class SAAJStreamWriter extends W3CDOMStreamWriter {
+public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter {
     private final SOAPPart part;
 
     public SAAJStreamWriter(SOAPPart part) {
@@ -56,6 +56,18 @@ public final class SAAJStreamWriter exte
         }
         return e;
     }
+    protected void adjustOverlaidNode(Node nd2, String pfx) {
+        String namespace = nd2.getNamespaceURI();
+        try {
+            if (namespace != null 
+                && namespace.equals(part.getEnvelope().getElementName().getURI()))
{
+                adjustPrefix((SOAPElement)nd2, pfx);
+            }
+        } catch (SOAPException e) {
+            //ignore, fallback
+        }
+        super.adjustOverlaidNode(nd2, pfx);
+    }
     
     protected void createAndAddElement(String prefix, String local, String namespace) {
         try {
@@ -69,6 +81,9 @@ public final class SAAJStreamWriter exte
                     setChild(adjustPrefix(part.getEnvelope().getBody(), prefix), false);
                     return;
                 } else if ("Header".equals(local)) {
+                    if (part.getEnvelope().getHeader() == null) {
+                        part.getEnvelope().addHeader();
+                    }
                     setChild(adjustPrefix(part.getEnvelope().getHeader(), prefix), false);
                     return;
                 } else if ("Fault".equals(local)) {

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java?rev=1446336&r1=1446335&r2=1446336&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
Thu Feb 14 21:27:18 2013
@@ -60,7 +60,6 @@ import org.apache.cxf.phase.AbstractPhas
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
@@ -238,7 +237,7 @@ public class MessageModeOutInterceptor e
                 XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
                 message.put(SAAJOutInterceptor.ORIGINAL_XML_WRITER, origWriter);
             }
-            W3CDOMStreamWriter writer = new OverlayW3CDOMStreamWriter(soapMessage.getSOAPPart());
+            W3CDOMStreamWriter writer = new SAAJStreamWriter(soapMessage.getSOAPPart());
             // Replace stax writer with DomStreamWriter
             message.setContent(XMLStreamWriter.class, writer);
             message.setContent(SOAPMessage.class, soapMessage);

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java?rev=1446336&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java
Thu Feb 14 21:27:18 2013
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider;
+
+
+import java.io.InputStream;
+import java.io.StringReader;
+
+import javax.annotation.Resource;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Provider;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.soap.Addressing;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.testutil.common.TestUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CXF4818Test extends AbstractBusClientServerTestBase {
+
+    public static final String ADDRESS 
+        = "http://localhost:" + TestUtil.getPortNumber(Server.class)
+            + "/AddressProvider/AddressProvider";
+    
+    public static class Server extends AbstractBusTestServerBase {
+
+        protected void run() {
+            Object implementor = new CXF4818Provider();
+            Endpoint.publish(ADDRESS, implementor);                                 
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
+    }
+    
+    @Test
+    public void testCXF4818() throws Exception {
+        InputStream body = getClass().getResourceAsStream("cxf4818data.txt");
+        HttpClient client = new HttpClient();
+        PostMethod post = new PostMethod(ADDRESS);
+        post.setRequestEntity(new InputStreamRequestEntity(body, "text/xml"));
+        client.executeMethod(post); 
+
+        Document doc = StaxUtils.read(post.getResponseBodyAsStream());
+        //System.out.println(StaxUtils.toString(doc));
+        Element root = doc.getDocumentElement();
+        Node child = root.getFirstChild();
+        
+        boolean foundBody = false;
+        boolean foundHeader = false;
+        while (child != null) {
+            if ("Header".equals(child.getLocalName())) {
+                foundHeader = true;
+                assertFalse("Already found body", foundBody);
+            } else if ("Body".equals(child.getLocalName())) {
+                foundBody = true;
+                assertTrue("Did not find header before the body", foundHeader);
+            }
+            child = child.getNextSibling();
+        }
+        assertTrue("Did not find the soap:Body element", foundBody);
+        assertTrue("Did not find the soap:Header element", foundHeader);
+    }
+
+    
+    
+    @WebServiceProvider(serviceName = "GenericService",
+        targetNamespace = "http://cxf.apache.org/basictest", 
+        portName = "GenericServicePosrt")
+    @ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
+    @Addressing
+    public static class CXF4818Provider implements Provider<SOAPMessage> {
+
+        @Resource
+        protected WebServiceContext context;
+
+        public SOAPMessage invoke(SOAPMessage request) {
+            try {
+                String responseText = "<SOAP-ENV:Envelope "
+                    + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                    + "<SOAP-ENV:Body>"
+                    + "<ns2:FooResponse xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">"
+                    + "<ns2:Return>Foo Response Body</ns2:Return>"
+                    + "</ns2:FooResponse>"
+                    + "</SOAP-ENV:Body>" 
+                    + "</SOAP-ENV:Envelope>\n";
+
+
+                // Create a SOAP request message
+                MessageFactory soapmsgfactory = MessageFactory.newInstance();
+                SOAPMessage responseMessage = soapmsgfactory.createMessage();
+                StreamSource responseMessageSrc = null;
+
+                responseMessageSrc = new StreamSource(new StringReader(responseText));
+                responseMessage.getSOAPPart().setContent(responseMessageSrc);
+                responseMessage.saveChanges();
+
+                return responseMessage;
+
+            } catch (Exception e) {
+                throw new WebServiceException(e);
+            }
+
+        }
+
+    }    
+}

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4818data.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4818data.txt?rev=1446336&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4818data.txt
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4818data.txt
Thu Feb 14 21:27:18 2013
@@ -0,0 +1,11 @@
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inb="http://cxf.apache.org/soapheader/inband">
+   <soapenv:Header>
+      <Action xmlns="http://www.w3.org/2005/08/addressing">http://cxf.apache.org/output</Action>
+      <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:472f7066-56a3-4807-b1eb-ae1c786c081c</MessageID>
+      <To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
+      <RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:9e58b03c-3253-4bd8-8faa-855d15e217e0</RelatesTo>
+   </soapenv:Header>
+   <soapenv:Body>
+      <inb:FooRequest/>
+   </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file



Mime
View raw message