You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2018/07/23 23:19:56 UTC
[cxf] branch master updated: [CXF-7798] Make sure the
exception/fault is mapped the same for the Async methods as compared to the
normal methods
This is an automated email from the ASF dual-hosted git repository.
dkulp 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 2c237f7 [CXF-7798] Make sure the exception/fault is mapped the same for the Async methods as compared to the normal methods
2c237f7 is described below
commit 2c237f7a5f6af5d6f789d74a26ccf126fee0a9c4
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Mon Jul 23 19:18:48 2018 -0400
[CXF-7798] Make sure the exception/fault is mapped the same for the Async methods as compared to the normal methods
---
.../java/org/apache/cxf/jaxws/DispatchImpl.java | 12 ++-
.../org/apache/cxf/jaxws/JaxWsClientProxy.java | 85 +++++++++++++++-------
.../org/apache/cxf/jaxws/JaxwsClientCallback.java | 6 +-
.../DispatchClientServerWithHugeResponseTest.java | 9 ++-
.../apache/cxf/systest/jaxws/ClientServerTest.java | 26 ++++++-
.../hello_world_soap_http/BaseGreeterImpl.java | 3 +
6 files changed, 106 insertions(+), 35 deletions(-)
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
index 87e3ba2..f70eb77 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
@@ -422,7 +422,17 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider, Closeable
checkError();
client.setExecutor(getClient().getEndpoint().getExecutor());
- ClientCallback callback = new JaxwsClientCallback<T>(asyncHandler, this);
+ ClientCallback callback = new JaxwsClientCallback<T>(asyncHandler, this) {
+ @Override
+ protected Throwable mapThrowable(Throwable t) {
+ if (t instanceof IOException) {
+ return t;
+ } else if (t instanceof Exception) {
+ t = mapException((Exception)t);
+ }
+ return t;
+ }
+ };
Response<T> ret = new JaxwsResponseCallback<T>(callback);
try {
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
index 5048af1..ecd9f6c 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
@@ -61,6 +61,7 @@ import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxws.context.WrappedMessageContext;
import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
import org.apache.cxf.service.invoker.MethodDispatcher;
+import org.apache.cxf.service.model.BindingFaultInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implements
@@ -141,19 +142,52 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem
} catch (WebServiceException wex) {
throw wex;
} catch (Exception ex) {
+ throw mapException(method, oi, ex);
+ } finally {
+ if (addressChanged(address)) {
+ setupEndpointAddressContext(getClient().getEndpoint());
+ }
+ }
+
+ Map<String, Object> respContext = client.getResponseContext();
+ Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>)respContext.get(WrappedMessageContext.SCOPES));
+ if (scopes != null) {
+ for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
+ if (scope.getValue() == Scope.HANDLER) {
+ respContext.remove(scope.getKey());
+ }
+ }
+ }
+ return adjustObject(result);
+ }
+ Exception mapException(Method method, BindingOperationInfo boi, Exception ex) {
+ if (method != null) {
for (Class<?> excls : method.getExceptionTypes()) {
if (excls.isInstance(ex)) {
- throw ex;
+ return ex;
}
}
- if (ex instanceof Fault && ex.getCause() instanceof IOException) {
- throw new WebServiceException(ex.getMessage(), ex.getCause());
+ } else if (boi != null) {
+ for (BindingFaultInfo fi : boi.getFaults()) {
+ Class<?> c = fi.getFaultInfo().getProperty(Class.class.getName(), Class.class);
+ if (c != null && c.isInstance(ex)) {
+ return ex;
+ }
}
- if (getBinding() instanceof HTTPBinding) {
- HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
- exception.initCause(ex);
- throw exception;
- } else if (getBinding() instanceof SOAPBinding) {
+ if (ex instanceof IOException) {
+ return ex;
+ }
+ }
+
+ if (ex instanceof Fault && ex.getCause() instanceof IOException) {
+ return new WebServiceException(ex.getMessage(), ex.getCause());
+ }
+ if (getBinding() instanceof HTTPBinding) {
+ HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
+ exception.initCause(ex);
+ return exception;
+ } else if (getBinding() instanceof SOAPBinding) {
+ try {
SOAPFault soapFault = createSoapFault((SOAPBinding)getBinding(), ex);
if (soapFault == null) {
throw new WebServiceException(ex);
@@ -164,27 +198,14 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem
} else {
exception.initCause(ex);
}
- throw exception;
- } else {
- throw new WebServiceException(ex);
- }
- } finally {
- if (addressChanged(address)) {
- setupEndpointAddressContext(getClient().getEndpoint());
- }
- }
-
- Map<String, Object> respContext = client.getResponseContext();
- Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>)respContext.get(WrappedMessageContext.SCOPES));
- if (scopes != null) {
- for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
- if (scope.getValue() == Scope.HANDLER) {
- respContext.remove(scope.getKey());
- }
+ return exception;
+ } catch (SOAPException e) {
+ return new WebServiceException(ex);
}
}
- return adjustObject(result);
+ return new WebServiceException(ex);
}
+
boolean isAsync(Method m) {
return m.getName().endsWith("Async")
&& (Future.class.equals(m.getReturnType())
@@ -277,7 +298,7 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem
}
@SuppressWarnings("unchecked")
- private Object invokeAsync(Method method, BindingOperationInfo oi, Object[] params) throws Exception {
+ private Object invokeAsync(Method method, final BindingOperationInfo oi, Object[] params) throws Exception {
client.setExecutor(getClient().getEndpoint().getExecutor());
@@ -292,7 +313,15 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem
} else {
handler = null;
}
- ClientCallback callback = new JaxwsClientCallback<Object>(handler, this);
+ ClientCallback callback = new JaxwsClientCallback<Object>(handler, this) {
+ @Override
+ protected Throwable mapThrowable(Throwable t) {
+ if (t instanceof Exception) {
+ t = mapException(null, oi, (Exception)t);
+ }
+ return t;
+ }
+ };
Response<Object> ret = new JaxwsResponseCallback<Object>(callback);
client.invoke(callback, oi, params);
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxwsClientCallback.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxwsClientCallback.java
index 2f0e6df..ceb1450 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxwsClientCallback.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxwsClientCallback.java
@@ -82,7 +82,7 @@ class JaxwsClientCallback<T> extends ClientCallback {
@Override
public void handleException(Map<String, Object> ctx, final Throwable ex) {
context = ctx;
- exception = ex;
+ exception = mapThrowable(ex);
if (handler != null) {
handler.handleResponse(new Response<T>() {
@@ -120,4 +120,8 @@ class JaxwsClientCallback<T> extends ClientCallback {
notifyAll();
}
}
+
+ protected Throwable mapThrowable(Throwable t) {
+ return t;
+ }
}
\ No newline at end of file
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
index b7fe91d..fbe926c 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
@@ -33,6 +33,7 @@ import javax.xml.ws.Dispatch;
import javax.xml.ws.Endpoint;
import javax.xml.ws.Response;
import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.ext.logging.LoggingInInterceptor;
@@ -178,8 +179,8 @@ public class DispatchClientServerWithHugeResponseTest extends AbstractBusClientS
throw e;
}
Throwable t = e.getCause();
- if (t instanceof SoapFault) {
- SoapFault sf = (SoapFault)e.getCause();
+ if (t instanceof SOAPFaultException) {
+ SoapFault sf = (SoapFault)t.getCause();
if (sf.getCause() == null) {
throw e;
}
@@ -236,8 +237,8 @@ public class DispatchClientServerWithHugeResponseTest extends AbstractBusClientS
throw e;
}
Throwable t = e.getCause();
- if (t instanceof SoapFault) {
- SoapFault sf = (SoapFault)e.getCause();
+ if (t instanceof SOAPFaultException) {
+ SoapFault sf = (SoapFault)t.getCause();
if (sf.getCause() == null) {
throw e;
}
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
index 76f9397..18cef94 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
@@ -48,6 +48,7 @@ import javax.xml.ws.Endpoint;
import javax.xml.ws.Response;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
import org.w3c.dom.Document;
@@ -710,6 +711,7 @@ public class ClientServerTest extends AbstractBusClientServerTestBase {
String noSuchCodeFault = "NoSuchCodeLitFault";
String badRecordFault = "BadRecordLitFault";
+ String illegalArgumentException = "IllegalArgumentException";
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
@@ -721,6 +723,13 @@ public class ClientServerTest extends AbstractBusClientServerTestBase {
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
+ try {
+ greeter.testDocLitFault(illegalArgumentException);
+ fail("Should have thrown SOAPFaultException exception");
+ } catch (SOAPFaultException sfe) {
+ assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
+ sfe.printStackTrace();
+ }
try {
greeter.testDocLitFault(badRecordFault);
@@ -735,9 +744,24 @@ public class ClientServerTest extends AbstractBusClientServerTestBase {
assertNotNull(brlf.getFaultInfo());
assertEquals("BadRecordLitFault", brlf.getFaultInfo());
}
+
+ try {
+ greeter.testDocLitFaultAsync(noSuchCodeFault).get();
+ fail("Should have thrown NoSuchCodeLitFault exception");
+ } catch (ExecutionException ee) {
+ NoSuchCodeLitFault nslf = (NoSuchCodeLitFault)ee.getCause();
+ assertNotNull(nslf.getFaultInfo());
+ assertNotNull(nslf.getFaultInfo().getCode());
+ }
+ try {
+ greeter.testDocLitFaultAsync(illegalArgumentException).get();
+ fail("Should have thrown SOAPFaultException exception");
+ } catch (ExecutionException ee) {
+ SOAPFaultException sfe = (SOAPFaultException)ee.getCause();
+ assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
+ }
}
-
}
@Test
diff --git a/testutils/src/main/java/org/apache/hello_world_soap_http/BaseGreeterImpl.java b/testutils/src/main/java/org/apache/hello_world_soap_http/BaseGreeterImpl.java
index a7a2a23..3cbdacd 100644
--- a/testutils/src/main/java/org/apache/hello_world_soap_http/BaseGreeterImpl.java
+++ b/testutils/src/main/java/org/apache/hello_world_soap_http/BaseGreeterImpl.java
@@ -111,6 +111,9 @@ public class BaseGreeterImpl implements Greeter {
nscl.setCode(ec);
throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
}
+ if ("IllegalArgumentException".equals(faultType)) {
+ throw new IllegalArgumentException("TestIllegalArgumentException");
+ }
throw new RuntimeException("Unknown source", new IOException("dummy io exception"));
}