You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2021/09/23 04:18:07 UTC
[cxf] branch master updated: [CXF-8596]:Fix infinite loop in
WebFaultOutInterceptor (#850)
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 a77ad3f [CXF-8596]:Fix infinite loop in WebFaultOutInterceptor (#850)
a77ad3f is described below
commit a77ad3f887e5acdbc4d23e98724bd2ad87ac87e2
Author: jimma <em...@apache.org>
AuthorDate: Thu Sep 23 12:18:02 2021 +0800
[CXF-8596]:Fix infinite loop in WebFaultOutInterceptor (#850)
---
.../jaxws/interceptors/WebFaultOutInterceptor.java | 3 ++
.../org/apache/cxf/systest/jaxws/CXF7990Test.java | 24 +++++++--
.../jaxws/{EchoService.java => EchoException.java} | 22 ++++++--
.../cxf/systest/jaxws/EchoProxyServiceImpl.java | 62 ++++++++++++++++++++++
.../org/apache/cxf/systest/jaxws/EchoService.java | 2 +
.../apache/cxf/systest/jaxws/EchoServiceImpl.java | 30 +++++++++++
6 files changed, 135 insertions(+), 8 deletions(-)
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 3ccb336..c334118 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
@@ -188,6 +188,9 @@ public class WebFaultOutInterceptor extends FaultOutInterceptor {
}
} else if (cause instanceof SOAPFaultException && ((SOAPFaultException)cause).getFault().hasDetail()) {
return;
+ } else if (f instanceof SoapFault && f.getCause() instanceof SOAPFaultException
+ && ((SOAPFaultException)f.getCause()).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
index 4be726c..275e56a 100644
--- 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
@@ -39,11 +39,14 @@ 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);
+
+ Object proxyImpl = new EchoProxyServiceImpl();
+ String address2 = "http://localhost:" + PORT + "/proxy/service";
+ Endpoint.publish(address2, proxyImpl);
}
public static void main(String[] args) {
@@ -70,8 +73,6 @@ public class CXF7990Test extends AbstractClientServerTestBase {
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");
@@ -81,4 +82,21 @@ public class CXF7990Test extends AbstractClientServerTestBase {
}
}
+ @Test
+ public void testProxySOAPFaultException() throws Exception {
+ QName serviceName = new QName("urn:echo", "EchoProxyServiceImplService");
+ QName portName = new QName("urn:echo", "MyEchoProxyServicePort");
+ URL wsdlURL = new URL("http://localhost:" + PORT + "/proxy/service?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + PORT
+ + "/proxy/service");
+ EchoService echoService = service.getPort(portName, EchoService.class);
+ try {
+ echoService.echoProxy("http://localhost:" + PORT + "/echo/service?wsdl");
+ fail("SOAPException is expected");
+ } catch (SOAPFaultException e) {
+ assertTrue(e.getMessage(), e.getMessage().equals("SOAPFaultString"));
+ }
+ }
+
}
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/EchoException.java
similarity index 69%
copy from systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoService.java
copy to systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoException.java
index 7be7a4f..0bfa3bf 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoService.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoException.java
@@ -18,10 +18,22 @@
*/
package org.apache.cxf.systest.jaxws;
-import javax.jws.WebService;
-import javax.xml.ws.soap.SOAPFaultException;
+public class EchoException extends Exception {
-@WebService(name = "MyEchoService", targetNamespace = "urn:echo")
-public interface EchoService {
- String echoException(String input) throws SOAPFaultException;
+ private static final long serialVersionUID = -6610080738935731882L;
+ private String code;
+
+ public EchoException(String code) {
+ this.code = code;
+ fillInStackTrace();
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
}
+
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoProxyServiceImpl.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoProxyServiceImpl.java
new file mode 100644
index 0000000..fb33095
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/EchoProxyServiceImpl.java
@@ -0,0 +1,62 @@
+/**
+ * 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.MalformedURLException;
+import java.net.URL;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.cxf.ext.logging.Logging;
+
+@WebService(name = "MyEchoProxyService", targetNamespace = "urn:echo")
+@Logging
+public class EchoProxyServiceImpl implements EchoService {
+ public String echoException(String input) throws SOAPFaultException {
+ return input;
+ }
+
+ public String echoProxy(String address) throws SOAPFaultException {
+ QName serviceName = new QName("urn:echo", "EchoServiceImplService");
+ QName portName = new QName("urn:echo", "MyEchoServicePort");
+ URL wsdlURL = null;
+ try {
+ wsdlURL = new URL(address);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ Service service = Service.create(wsdlURL, serviceName);
+ EchoService echoService = service.getPort(portName, EchoService.class);
+ try {
+ echoService.proxyException("input");
+ } catch (SOAPFaultException se) {
+ throw se;
+ }
+ return "DONE";
+ }
+
+ @Override
+ public String proxyException(String input) throws SOAPFaultException {
+ return input;
+ }
+
+}
\ No newline at end of file
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
index 7be7a4f..e994b0b 100644
--- 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
@@ -24,4 +24,6 @@ import javax.xml.ws.soap.SOAPFaultException;
@WebService(name = "MyEchoService", targetNamespace = "urn:echo")
public interface EchoService {
String echoException(String input) throws SOAPFaultException;
+ String echoProxy(String input) throws SOAPFaultException;
+ String proxyException(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
index 0e55542..0b302f1 100644
--- 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
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.jaxws;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.soap.SOAPFaultException;
@@ -43,6 +44,35 @@ public class EchoServiceImpl implements EchoService {
}
+ public String echoProxy(String input) throws SOAPFaultException {
+ return input;
+ }
+
+
+ @Override
+ public String proxyException(String input) throws SOAPFaultException {
+ try {
+ Integer.parseInt(input);
+ } catch (Exception e) {
+ throw new SOAPFaultException(
+ createSOAPFault(new EchoException("exception from testException()")));
+ }
+ return "DONE";
+ }
+
+ private SOAPFault createSOAPFault(Throwable ex) {
+ try {
+ SOAPFault soapFault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createFault();
+ soapFault.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server", "a"));
+ soapFault.setFaultString("SOAPFaultString");
+ soapFault.setFaultActor("ServerSide");
+ soapFault.addDetail();
+ return soapFault;
+ } catch (SOAPException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private SOAPFaultException wrapToSoapFault(Exception ex) throws Exception {
SOAPFactory fac = null;
try {