cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7119] Optional propagation of the proxy runtime exceptions without wrapping them into ProcessingEx
Date Fri, 25 Nov 2016 20:02:00 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 53e9b5825 -> bbe8829c6


[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/bbe8829c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/bbe8829c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/bbe8829c

Branch: refs/heads/3.0.x-fixes
Commit: bbe8829c65cbaf1b8f8fe761d4cb2b5c285f6dd1
Parents: 53e9b58
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Nov 25 19:59:24 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Nov 25 20:01:45 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/bbe8829c/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 d37de1c..efdc25a 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
@@ -585,16 +585,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/bbe8829c/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/bbe8829c/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 4ad73f8..148dc24 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;
@@ -2633,11 +2634,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());
         }


Mime
View raw message