Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 49C34200BFB for ; Sun, 4 Dec 2016 02:11:45 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 469C0160B32; Sun, 4 Dec 2016 01:11:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9521F160B2B for ; Sun, 4 Dec 2016 02:11:44 +0100 (CET) Received: (qmail 35917 invoked by uid 500); 4 Dec 2016 01:11:43 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 35544 invoked by uid 99); 4 Dec 2016 01:11:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Dec 2016 01:11:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 612FDF1763; Sun, 4 Dec 2016 01:11:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: reta@apache.org To: commits@cxf.apache.org Date: Sun, 04 Dec 2016 01:11:49 -0000 Message-Id: <707b45969ca648b9a9f9802132ae2233@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/30] cxf git commit: [CXF-7119] Optional propagation of the proxy runtime exceptions without wrapping them into ProcessingEx archived-at: Sun, 04 Dec 2016 01:11:45 -0000 [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/CXF-6882.nio Commit: 57649645ce6592a23445b17be4fe64a25855db91 Parents: a43c1eb Author: Sergey Beryozkin Authored: Fri Nov 25 19:59:24 2016 +0000 Committer: Sergey Beryozkin 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 { - 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()); }