This is an automated email from the ASF dual-hosted git repository.
ema pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 4233f91 [CXF-7990]:Fix Infinite loop when service endpoint throws
SOAPFaultException (#538)
4233f91 is described below
commit 4233f9138de22fe5de555d2f176e494e62905de5
Author: jimma <[email protected]>
AuthorDate: Fri Apr 12 10:37:43 2019 +0800
[CXF-7990]:Fix Infinite loop when service endpoint throws
SOAPFaultException (#538)
---
.../jaxws/interceptors/WebFaultOutInterceptor.java | 2 +
.../org/apache/cxf/systest/jaxws/CXF7990Test.java | 84 ++++++++++++++++++++++
.../org/apache/cxf/systest/jaxws/EchoService.java | 27 +++++++
.../apache/cxf/systest/jaxws/EchoServiceImpl.java | 63 ++++++++++++++++
4 files changed, 176 insertions(+)
diff --git
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
index c936ab4..1bed7ad 100644
---
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
+++
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
@@ -181,6 +181,8 @@ public class WebFaultOutInterceptor extends
FaultOutInterceptor {
//and let the rest of the chain try handling it as is.
LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", nex);
}
+ } else if (cause instanceof SOAPFaultException &&
((SOAPFaultException)cause).getFault().hasDetail()) {
+ return;
} else {
FaultMode mode = message.get(FaultMode.class);
if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
diff --git
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF7990Test.java
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF7990Test.java
new file mode 100644
index 0000000..4be726c
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF7990Test.java
@@ -0,0 +1,84 @@
+/**
+ * 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.jaxws;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class CXF7990Test extends AbstractClientServerTestBase {
+ static final String PORT = allocatePort(Server.class);
+
+ public static class Server extends AbstractBusTestServerBase {
+
+ protected void run() {
+ Object implementor = new EchoServiceImpl();
+ String address = "http://localhost:" + PORT + "/echo/service";
+ 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 testSOAPFaultException() throws Exception {
+ QName serviceName = new QName("urn:echo", "EchoServiceImplService");
+ QName portName = new QName("urn:echo", "MyEchoServicePort");
+ URL wsdlURL = new URL("http://localhost:" + PORT +
"/echo/service?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
"http://localhost:" + PORT
+ +
"/echo/service");
+ EchoService echoService = service.getPort(portName, EchoService.class);
+ try {
+ echoService.echoException("test");
+ fail("SOAPException is expected");
+ } catch (SOAPFaultException e) {
+ assertTrue(e.getMessage().equals("TestSOAPFaultException"));
+ }
+ }
+
+}
diff --git
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoService.java
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoService.java
new file mode 100644
index 0000000..7be7a4f
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoService.java
@@ -0,0 +1,27 @@
+/**
+ * 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.jaxws;
+
+import javax.jws.WebService;
+import javax.xml.ws.soap.SOAPFaultException;
+
+@WebService(name = "MyEchoService", targetNamespace = "urn:echo")
+public interface EchoService {
+ String echoException(String input) throws SOAPFaultException;
+}
diff --git
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoServiceImpl.java
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoServiceImpl.java
new file mode 100644
index 0000000..0e55542
--- /dev/null
+++
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoServiceImpl.java
@@ -0,0 +1,63 @@
+/**
+ * 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.jaxws;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.cxf.ext.logging.Logging;
+
+@WebService(name = "MyEchoService", targetNamespace = "urn:echo")
+@Logging
+public class EchoServiceImpl implements EchoService {
+ public String echoException(String input) throws SOAPFaultException {
+
+ SOAPFaultException ex;
+ try {
+ ex = wrapToSoapFault(new Exception("hello"));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ return e.toString();
+ }
+ throw ex;
+
+ }
+
+ private SOAPFaultException wrapToSoapFault(Exception ex) throws Exception {
+ SOAPFactory fac = null;
+ try {
+ fac = SOAPFactory.newInstance();
+ String message = ex.getMessage();
+ SOAPFault sf = fac.createFault(message, new
QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE,
+ "Server"));
+ sf.setFaultString("TestSOAPFaultException");
+ // add detail makes CXF goes in a infinite loop
+ sf.addDetail().addDetailEntry(new QName("urn:echo",
"entry")).addTextNode("SOAPFaultException");
+
+ return new SOAPFaultException(sf);
+ } catch (Exception e2) {
+
+ throw e2;
+ }
+ }
+}