Repository: cxf Updated Branches: refs/heads/master a43c1eb00 -> 57649645c
[CXF-7119] Optional propagation of the proxy runtime exceptions without wrapping them into ProcessingEx Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/57649645 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/57649645 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/57649645 Branch: refs/heads/master Commit: 57649645ce6592a23445b17be4fe64a25855db91 Parents: a43c1eb Author: Sergey Beryozkin <[email protected]> Authored: Fri Nov 25 19:59:24 2016 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Nov 25 19:59:24 2016 +0000 ---------------------------------------------------------------------- .../apache/cxf/jaxrs/client/AbstractClient.java | 20 +++++++++++++------- .../systest/jaxrs/CustomFaultInInterceptor.java | 18 +++++++++++++++--- .../jaxrs/JAXRSClientServerBookTest.java | 5 +++-- 3 files changed, 31 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/57649645/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java index c8a76ba..b97483e 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java @@ -586,16 +586,22 @@ public abstract class AbstractClient implements Client { protected void checkClientException(Message outMessage, Exception ex) throws Exception { Throwable actualEx = ex instanceof Fault ? ((Fault)ex).getCause() : ex; - Integer responseCode = getResponseCode(outMessage.getExchange()); + Exchange exchange = outMessage.getExchange(); + Integer responseCode = getResponseCode(exchange); if (responseCode == null - || actualEx instanceof IOException - && outMessage.getExchange().get("client.redirect.exception") != null) { + || actualEx instanceof IOException && exchange.get("client.redirect.exception") != null) { if (actualEx instanceof ProcessingException) { - throw (ProcessingException)actualEx; + throw (RuntimeException)actualEx; } else if (actualEx != null) { - throw new ProcessingException(actualEx); - } else if (!outMessage.getExchange().isOneWay() || cfg.isResponseExpectedForOneway()) { - waitForResponseCode(outMessage.getExchange()); + Object useProcExProp = exchange.get("wrap.in.processing.exception"); + if (actualEx instanceof RuntimeException + && useProcExProp != null && PropertyUtils.isFalse(useProcExProp)) { + throw (Exception)actualEx; + } else { + throw new ProcessingException(actualEx); + } + } else if (!exchange.isOneWay() || cfg.isResponseExpectedForOneway()) { + waitForResponseCode(exchange); } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/57649645/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomFaultInInterceptor.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomFaultInInterceptor.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomFaultInInterceptor.java index bd29c08..e86792a 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomFaultInInterceptor.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomFaultInInterceptor.java @@ -26,16 +26,28 @@ import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; public class CustomFaultInInterceptor extends AbstractPhaseInterceptor<Message> { - public CustomFaultInInterceptor() { + private boolean useProcEx; + public CustomFaultInInterceptor(boolean useProcEx) { super(Phase.PRE_STREAM); + this.useProcEx = useProcEx; } public void handleMessage(Message message) throws Fault { Exception ex = message.getContent(Exception.class); - throw new ProcessingException(ex.getCause().getClass().getSimpleName() + String errorMessage = ex.getCause().getClass().getSimpleName() + ": Microservice at " + message.get(Message.REQUEST_URI) - + " is not available"); + + " is not available"; + message.getExchange().put("wrap.in.processing.exception", useProcEx); + throw useProcEx ? new ProcessingException(new CustomRuntimeException(errorMessage)) + : new CustomRuntimeException(errorMessage); + } + public static class CustomRuntimeException extends RuntimeException { + private static final long serialVersionUID = -4664563239685175537L; + + public CustomRuntimeException(String errorMessage) { + super(errorMessage); + } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/57649645/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java index da1f046..b19dc6b 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java @@ -73,6 +73,7 @@ import org.apache.cxf.jaxrs.provider.XSLTJaxbProvider; import org.apache.cxf.systest.jaxrs.BookStore.BookInfo; import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface; import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException; +import org.apache.cxf.systest.jaxrs.CustomFaultInInterceptor.CustomRuntimeException; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.junit.BeforeClass; @@ -2645,11 +2646,11 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testNonExistentWithGetCustomEx() throws Exception { String address = "http://localhostt/bookstore"; BookStore c = JAXRSClientFactory.create(address, BookStore.class); - WebClient.getConfig(c).getInFaultInterceptors().add(new CustomFaultInInterceptor()); + WebClient.getConfig(c).getInFaultInterceptors().add(new CustomFaultInInterceptor(false)); try { c.getBook("123"); fail("Exception expected"); - } catch (ProcessingException ex) { + } catch (CustomRuntimeException ex) { assertEquals("UnknownHostException: Microservice at http://localhostt/bookstore/bookstore/books/123/" + " is not available", ex.getMessage()); }
