From 48d813725f0c1313226689e6e00a2788e8cf12f8 Mon Sep 17 00:00:00 2001 From: Tomas Hofman Date: Mon, 11 May 2015 15:08:55 +0200 Subject: [PATCH] Fix regression by storing namespace declarations from Body and Envelope element and later updating the SAAJ model with them - added integration test for this issue --- .../cxf/systest/cxf6319/Cxf6319TestCase.java | 79 +++++++++++++++++++ .../cxf/systest/cxf6319/EmptyHandler.java | 52 ++++++++++++ .../cxf/systest/cxf6319/ServiceImpl.java | 34 ++++++++ .../apache/cxf/systest/cxf6319/handler.xml | 9 +++ .../apache/cxf/systest/cxf6319/request.xml | 27 +++++++ 5 files changed, 201 insertions(+) create mode 100644 systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/Cxf6319TestCase.java create mode 100644 systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/EmptyHandler.java create mode 100644 systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/ServiceImpl.java create mode 100644 systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/handler.xml create mode 100644 systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/request.xml diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/Cxf6319TestCase.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/Cxf6319TestCase.java new file mode 100644 index 00000000000..e97dbe8bf1f --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/Cxf6319TestCase.java @@ -0,0 +1,79 @@ +/** + * 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.cxf6319; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; + +import javax.xml.ws.Endpoint; + +import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.interceptor.URIMappingInterceptor; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.apache.cxf.testutil.common.TestUtil; +import org.junit.Test; + +/** + * Test case for CXF-6319 - namespace declarations in body and envelope are not processed correctly + * when there is a SOAPHandler. + * + * @author Tomas Hofman (thofman@redhat.com) + */ +public class Cxf6319TestCase extends AbstractBusClientServerTestBase { + + static final String PORT = TestUtil.getPortNumber(Cxf6319TestCase.class); + + @Test + public void testDeclarationsInEnvelope() throws Exception { + Endpoint ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort", new ServiceImpl()); + EndpointImpl epi = (EndpointImpl)ep; + epi.getService().getInInterceptors().add(new URIMappingInterceptor()); + + try { + HttpURLConnection httpConnection = + getHttpConnection("http://localhost:" + PORT + "/SoapContext/SoapPort/echo"); + httpConnection.setDoOutput(true); + + InputStream reqin = getClass().getResourceAsStream("request.xml"); + assertNotNull("could not load test data", reqin); + + httpConnection.setRequestMethod("POST"); + httpConnection.addRequestProperty("Content-Type", "text/xml"); + OutputStream reqout = httpConnection.getOutputStream(); + IOUtils.copy(reqin, reqout); + reqout.close(); + + int responseCode = httpConnection.getResponseCode(); + InputStream errorStream = httpConnection.getErrorStream(); + String error = null; + if (errorStream != null) { + error = IOUtils.readStringFromStream(errorStream); + } + assertEquals(error, 200, responseCode); + } catch (Exception e) { + e.printStackTrace(); + } finally { + ep.stop(); + } + } + +} diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/EmptyHandler.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/EmptyHandler.java new file mode 100644 index 00000000000..e5015265f32 --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/EmptyHandler.java @@ -0,0 +1,52 @@ +/** + * 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.cxf6319; + +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +/** + * @author Tomas Hofman (thofman@redhat.com) + */ +public class EmptyHandler implements SOAPHandler { + + @Override + public boolean handleMessage(SOAPMessageContext context) { + return true; + } + + @Override + public boolean handleFault(SOAPMessageContext context) { + return true; + } + + @Override + public void close(javax.xml.ws.handler.MessageContext context) { + } + + @Override + public Set getHeaders() { + return null; + } + +} diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/ServiceImpl.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/ServiceImpl.java new file mode 100644 index 00000000000..d7816049749 --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/ServiceImpl.java @@ -0,0 +1,34 @@ +/** + * 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.cxf6319; + +import javax.jws.HandlerChain; +import javax.jws.WebParam; + +@javax.jws.WebService(serviceName = "SOAPService", + targetNamespace = "http://example.com") +@HandlerChain(file = "handler.xml") +public class ServiceImpl { + + public String echo(@WebParam(name = "s", targetNamespace = "http://example.com") String s) { + return s; + } + +} diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/handler.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/handler.xml new file mode 100644 index 00000000000..16d401cb4f5 --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/handler.xml @@ -0,0 +1,9 @@ + + + + ContextHandler + org.apache.cxf.systest.cxf6319.EmptyHandler + + + diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/request.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/request.xml new file mode 100644 index 00000000000..27a362d3bd9 --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/cxf6319/request.xml @@ -0,0 +1,27 @@ + + + + + + hello + + +