You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/07/25 11:22:49 UTC
[cxf] 01/02: CXF-7805 - Transform feature outDropElements has no
effect
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 43da57d1fe0384d98df9529f12f69c841c875b6a
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Jul 25 10:01:54 2018 +0100
CXF-7805 - Transform feature outDropElements has no effect
(cherry picked from commit 336c91fe4dc824fa2aab98a7906d249f3f0078e1)
(cherry picked from commit 3ae8a02ba67698f35441d92ddb242d9490d82fc5)
---
.../transform/TransformOutInterceptor.java | 4 +-
.../cxf/systest/soap/StaxTransformFeatureTest.java | 85 ++++++++++++++++++++++
.../apache/cxf/systest/soap/TransformServer.java | 47 ++++++++++++
.../src/test/resources/DoubleItLogical.wsdl | 9 ++-
.../apache/cxf/systest/soap/DoubleItTransform.wsdl | 72 ++++++++++++++++++
.../apache/cxf/systest/soap/transform-server.xml | 72 ++++++++++++++++++
6 files changed, 286 insertions(+), 3 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
index a0fff5b..1340b09 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
@@ -98,11 +98,11 @@ public class TransformOutInterceptor extends AbstractPhaseInterceptor<Message> {
XMLStreamWriter transformWriter = createTransformWriterIfNeeded(writer, out);
if (transformWriter != null) {
message.setContent(XMLStreamWriter.class, transformWriter);
+ message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION,
+ Boolean.TRUE);
if (MessageUtils.isRequestor(message)) {
message.removeContent(OutputStream.class);
message.put(OUTPUT_STREAM_HOLDER, out);
- message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION,
- Boolean.TRUE);
message.getInterceptorChain().add(ENDING);
}
}
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/StaxTransformFeatureTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/StaxTransformFeatureTest.java
new file mode 100644
index 0000000..d1d43bf
--- /dev/null
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/StaxTransformFeatureTest.java
@@ -0,0 +1,85 @@
+/**
+ * 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.soap;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.example.contract.doubleit.DoubleItPortType2;
+
+import org.junit.BeforeClass;
+
+/**
+ * A test for the StaxTransformFeature. The client uses "DoubleIt2" but the service uses "DoubleIt".
+ * The service uses the StaxTransformFeature's "inTransformElements" and "outTransformElements" to alter
+ * the client request/response.
+ */
+public class StaxTransformFeatureTest extends AbstractBusClientServerTestBase {
+ static final String PORT = allocatePort(TransformServer.class);
+
+ private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
+ private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue(
+ "Server failed to launch",
+ // run the server in the same process
+ // set this to false to fork
+ launchServer(TransformServer.class, true)
+ );
+ }
+
+ @org.junit.AfterClass
+ public static void cleanup() throws Exception {
+ stopAllServers();
+ }
+
+ @org.junit.Test
+ public void testTransformFeature() throws Exception {
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = StaxTransformFeatureTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ BusFactory.setDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = StaxTransformFeatureTest.class.getResource("DoubleItTransform.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort2");
+ DoubleItPortType2 port =
+ service.getPort(portQName, DoubleItPortType2.class);
+ updateAddressPort(port, PORT);
+
+ assertEquals(50, port.doubleIt2(25));
+
+ ((java.io.Closeable)port).close();
+
+ bus.shutdown(true);
+ }
+
+}
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/TransformServer.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/TransformServer.java
new file mode 100644
index 0000000..37b4119
--- /dev/null
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/TransformServer.java
@@ -0,0 +1,47 @@
+/**
+ * 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.soap;
+
+import java.net.URL;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class TransformServer extends AbstractBusTestServerBase {
+
+ public TransformServer() {
+
+ }
+
+ protected void run() {
+ URL busFile = TransformServer.class.getResource("transform-server.xml");
+ Bus busLocal = new SpringBusFactory().createBus(busFile);
+ BusFactory.setDefaultBus(busLocal);
+ setBus(busLocal);
+
+ try {
+ new TransformServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/systests/uncategorized/src/test/resources/DoubleItLogical.wsdl b/systests/uncategorized/src/test/resources/DoubleItLogical.wsdl
index 768ac76..735c6b3 100644
--- a/systests/uncategorized/src/test/resources/DoubleItLogical.wsdl
+++ b/systests/uncategorized/src/test/resources/DoubleItLogical.wsdl
@@ -58,6 +58,13 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
+ <xsd:element name="DoubleItResponse2">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="doubledResult" type="xsd:int"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
<xsd:element name="DoubleItHeader" type="xsd:int"/>
<xsd:element name="DoubleItFault">
<xsd:complexType>
@@ -90,7 +97,7 @@
<wsdl:part element="di:DoubleItResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="DoubleIt2Response">
- <wsdl:part element="di:DoubleItResponse" name="parameters"/>
+ <wsdl:part element="di:DoubleItResponse2" name="parameters"/>
</wsdl:message>
<wsdl:message name="DoubleIt3Response">
<wsdl:part element="di:DoubleItResponse" name="parameters"/>
diff --git a/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/DoubleItTransform.wsdl b/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/DoubleItTransform.wsdl
new file mode 100644
index 0000000..04871f2
--- /dev/null
+++ b/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/DoubleItTransform.wsdl
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.example.org/contract/DoubleIt" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sp13="http:// [...]
+ <wsdl:import location="src/test/resources/DoubleItLogical.wsdl" namespace="http://www.example.org/contract/DoubleIt"/>
+ <wsdl:binding name="DoubleItPlaintextBinding" type="tns:DoubleItPortType">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="DoubleIt">
+ <soap:operation soapAction=""/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ <wsdl:fault name="DoubleItFault">
+ <soap:body use="literal" name="DoubleItFault"/>
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="DoubleItPlaintextBinding2" type="tns:DoubleItPortType2">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="DoubleIt">
+ <soap:operation soapAction=""/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ <wsdl:fault name="DoubleItFault">
+ <soap:body use="literal" name="DoubleItFault"/>
+ </wsdl:fault>
+ </wsdl:operation>
+ <wsdl:operation name="DoubleIt2">
+ <soap:operation soapAction=""/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ <wsdl:fault name="DoubleItFault">
+ <soap:body use="literal" name="DoubleItFault"/>
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="DoubleItService">
+ <wsdl:port name="DoubleItPlaintextPort" binding="tns:DoubleItPlaintextBinding">
+ <soap:address location="http://localhost:9009/doubleit"/>
+ </wsdl:port>
+ <wsdl:port name="DoubleItPlaintextPort2" binding="tns:DoubleItPlaintextBinding2">
+ <soap:address location="http://localhost:9009/doubleit"/>
+ </wsdl:port>
+ </wsdl:service>
+ </wsdl:definitions>
\ No newline at end of file
diff --git a/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/transform-server.xml b/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/transform-server.xml
new file mode 100644
index 0000000..a37e340
--- /dev/null
+++ b/systests/uncategorized/src/test/resources/org/apache/cxf/systest/soap/transform-server.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:http="http://cxf.apache.org/transports/http/configuration"
+ xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
+ xmlns:sec="http://cxf.apache.org/configuration/security"
+ xmlns:cxf="http://cxf.apache.org/core"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+ http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd
+ http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
+ http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd">
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+ <cxf:bus>
+ <cxf:features>
+ </cxf:features>
+ </cxf:bus>
+
+ <bean id="transformClientMessage" class="org.apache.cxf.feature.StaxTransformFeature">
+ <property name="outTransformElements">
+ <map>
+ <entry key="{http://www.example.org/schema/DoubleIt}DoubleItResponse"
+ value="{http://www.example.org/schema/DoubleIt}DoubleItResponse2"/>
+ <entry key="doubledNumber" value="doubledResult"/>
+ </map>
+ </property>
+ <property name="inTransformElements">
+ <map>
+ <entry key="{http://www.example.org/schema/DoubleIt}DoubleIt2" value="{http://www.example.org/schema/DoubleIt}DoubleIt"/>
+ </map>
+ </property>
+ </bean>
+
+ <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt" id="TransformEndpoint"
+ address="http://localhost:${testutil.ports.soap.TransformServer}/doubleit"
+ serviceName="s:DoubleItService"
+ endpointName="s:DoubleItPlaintextPort"
+ implementor="org.apache.cxf.systest.soap.DoubleItImpl"
+ wsdlLocation="org/apache/cxf/systest/soap/DoubleIt.wsdl">
+ <jaxws:features>
+ <ref bean="transformClientMessage" />
+ </jaxws:features>
+ <!-- Not required any longer
+ <jaxws:properties>
+ <entry key="disable.outputstream.optimization" value="true"/>
+ </jaxws:properties>
+ -->
+ </jaxws:endpoint>
+
+</beans>