Author: klape
Date: 2012-09-05 23:51:14 -0400 (Wed, 05 Sep 2012)
New Revision: 16698
Added:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Provider.java
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Test.java
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4130data.txt
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/resources/wsdl_systest_jaxws/cxf4130.wsdl
Modified:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/pom.xml
Log:
[JBPAPP-9829] Backport CXF-4130: Server using @WebServiceProvider implementation writes
contents of SOAP body in SOAP header
Modified:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java 2012-09-06
03:49:11 UTC (rev 16697)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java 2012-09-06
03:51:14 UTC (rev 16698)
@@ -54,6 +54,7 @@
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
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;
@@ -187,7 +188,7 @@
public void handleMessage(SoapMessage message) throws Fault {
MessageContentsList list =
(MessageContentsList)message.getContent(List.class);
- Object o = list.get(0);
+ Object o = list.remove(0);
SOAPMessage soapMessage = null;
if (o instanceof SOAPMessage) {
@@ -221,7 +222,9 @@
// Replace stax writer with DomStreamWriter
message.setContent(XMLStreamWriter.class, writer);
message.setContent(SOAPMessage.class, soapMessage);
-
+
+ BindingOperationInfo bop =
message.getExchange().get(BindingOperationInfo.class);
+
DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment();
try {
Node body = soapMessage.getSOAPBody();
@@ -231,7 +234,25 @@
frag.appendChild(nd);
nd = soapMessage.getSOAPBody().getFirstChild();
}
- list.set(0, frag);
+
+ int index = 0;
+
+ boolean client = isRequestor(message);
+ BindingMessageInfo bmsg = null;
+
+ if (client) {
+ bmsg = bop.getInput();
+ } else if (bop.getOutput() != null) {
+ bmsg = bop.getOutput();
+ }
+ if (bmsg != null && bmsg.getMessageParts() != null
+ && bmsg.getMessageParts().size() > 0) {
+ index = bmsg.getMessageParts().get(0).getIndex();
+ }
+
+ list.set(index, frag);
+
+
//No need to buffer this as we're already a DOM,
//but only do so if someone hasn't actually configured this
Object buffer = message
@@ -242,7 +263,6 @@
} catch (Exception ex) {
throw new Fault(ex);
}
- BindingOperationInfo bop =
message.getExchange().get(BindingOperationInfo.class);
if (bop != null && bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
message.getExchange().put(BindingOperationInfo.class, bop);
Modified: thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/pom.xml
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/pom.xml 2012-09-06
03:49:11 UTC (rev 16697)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/pom.xml 2012-09-06
03:51:14 UTC (rev 16698)
@@ -197,6 +197,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
</dependency>
Added:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Provider.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Provider.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Provider.java 2012-09-06
03:51:14 UTC (rev 16698)
@@ -0,0 +1,89 @@
+/**
+ * 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.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.Provider;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceProvider;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+@WebServiceProvider(serviceName = "InBandSoapHeaderService",
+ targetNamespace = "http://cxf.apache.org/soapheader/inband",
+ portName = "InBandSoapHeaderSoapHttpPort",
+ wsdlLocation = "/wsdl_systest_jaxws/cxf4130.wsdl")
+@ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
+public class CXF4130Provider implements Provider<SOAPMessage> {
+
+ @Resource
+ protected WebServiceContext context;
+
+ public SOAPMessage invoke(SOAPMessage request) {
+ try {
+ Document soapBodyDomDocument =
request.getSOAPBody().extractContentAsDocument();
+ Node node = soapBodyDomDocument.getDocumentElement();
+ String requestMsgName = node.getLocalName();
+ String responseText = null;
+
+ if ("FooRequest".equals(requestMsgName)) {
+ responseText = "<SOAP-ENV:Envelope "
+ +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<SOAP-ENV:Header>"
+ + "<FooResponseHeader
xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">"
+ + "FooResponseHeader</FooResponseHeader>"
+ + "</SOAP-ENV:Header>"
+ + "<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";
+
+ } else {
+ throw new WebServiceException("Error in InBand Provider JAX-WS
service -- Unknown Request: "
+ + requestMsgName);
+ }
+
+ // 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:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Test.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Test.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Test.java 2012-09-06
03:51:14 UTC (rev 16698)
@@ -0,0 +1,96 @@
+/**
+ * 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 javax.xml.ws.Endpoint;
+
+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 CXF4130Test extends AbstractBusClientServerTestBase {
+
+ public static final String ADDRESS
+ = "http://localhost:" + TestUtil.getPortNumber(Server.class)
+ + "/InBand33MessageServiceProvider/InBandSoapHeaderSoapHttpPort";
+
+ public static class Server extends AbstractBusTestServerBase {
+
+ protected void run() {
+ Object implementor = new CXF4130Provider();
+ 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 testCxf4130() throws Exception {
+ InputStream body = getClass().getResourceAsStream("cxf4130data.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());
+ Element root = doc.getDocumentElement();
+ Node child = root.getFirstChild();
+
+ boolean foundBody = false;
+ while (child != null) {
+ if ("Body".equals(child.getLocalName())) {
+ foundBody = true;
+ assertEquals(1, child.getChildNodes().getLength());
+ assertEquals("FooResponse",
child.getFirstChild().getLocalName());
+ }
+ child = child.getNextSibling();
+ }
+ assertTrue("Did not find the soap:Body element", foundBody);
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4130data.txt
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4130data.txt
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/cxf4130data.txt 2012-09-06
03:51:14 UTC (rev 16698)
@@ -0,0 +1,8 @@
+<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:inb="http://cxf.apache.org/soapheader/inband">
+ <soapenv:Header>
+ <inb:FooRequestHeader>?</inb:FooRequestHeader>
+ </soapenv:Header>
+ <soapenv:Body>
+ <inb:FooRequest/>
+ </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/resources/wsdl_systest_jaxws/cxf4130.wsdl
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/resources/wsdl_systest_jaxws/cxf4130.wsdl
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.4.6-patch-01_JBPAPP-9829/systests/jaxws/src/test/resources/wsdl_systest_jaxws/cxf4130.wsdl 2012-09-06
03:51:14 UTC (rev 16698)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://cxf.apache.org/soapheader/inband"
targetNamespace="http://cxf.apache.org/soapheader/inband">
+ <types>
+ <schema elementFormDefault="qualified"
targetNamespace="http://cxf.apache.org/soapheader/inband"
xmlns="http://www.w3.org/2001/XMLSchema">
+>
+ <element name="FooRequest">
+ <complexType>
+ <sequence/>
+ </complexType>
+ </element>
+
+ <element name="FooResponse">
+ <complexType>
+ <sequence>
+ <element name="Return" type="string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="FooRequestHeader" type="string"/>
+ <element name="FooResponseHeader" type="string"/>
+ </schema>
+ </types>
+
+ <message name="FooRequest">
+ <part name="FooRequestHeader"
element="tns:FooRequestHeader"/>
+ <part name="FooRequest" element="tns:FooRequest"/>
+ </message>
+ <message name="FooResponse">
+ <part name="FooResponseHeader"
element="tns:FooResponseHeader"/>
+ <part name="FooResponse" element="tns:FooResponse"/>
+ </message>
+ <portType name="InBandSoapHeaderPortType">
+ <operation name="Foo">
+ <input name="FooRequest" message="tns:FooRequest"/>
+ <output name="FooResponse" message="tns:FooResponse"/>
+ </operation>
+ </portType>
+ <binding name="InBandSoapHeaderSoapHttpBinding"
type="tns:InBandSoapHeaderPortType">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <operation name="Foo">
+ <soap:operation/>
+ <input>
+ <soap:header message="tns:FooRequest" part="FooRequestHeader"
use="literal"/>
+ <soap:body parts="FooRequest" use="literal"/>
+ </input>
+ <output>
+ <soap:header message="tns:FooResponse"
part="FooResponseHeader" use="literal"/>
+ <!-- mmurphy - The follow line is from customer's original WSDL -->
+ <!-- <soap:body parts="FooCallbackPollResponse"
use="literal"/> -->
+ <!-- mmurphy - Replacing with suggestion from Seumas -->
+ <soap:body use="literal"/>
+ </output>
+ </operation>
+ </binding>
+
+ <service name="InBandSoapHeaderService">
+ <port name="InBandSoapHeaderSoapHttpPort"
binding="tns:InBandSoapHeaderSoapHttpBinding">
+ <soap:address
location="http://localhost:5640/InBand33MessageServiceProvider/InBandSoapHeaderSoapHttpPort"/>
+ </port>
+ </service>
+</definitions>