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-6390] Getting the exception set on the callback only once in case of POST requests failing on the client side
Date Tue, 05 May 2015 20:27:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 53d270e7f -> be23f28c9


[CXF-6390] Getting the exception set on the callback only once in case of POST requests failing
on the client side


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/be23f28c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/be23f28c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/be23f28c

Branch: refs/heads/3.0.x-fixes
Commit: be23f28c9991419599482c11bfb5366646787397
Parents: 53d270e
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue May 5 18:55:20 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue May 5 21:27:18 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java | 20 ++++++++++++----
 .../org/apache/cxf/jaxrs/client/WebClient.java  | 10 +-------
 .../cxf/systest/jaxrs/JAXRSAsyncClientTest.java | 24 +++++++++++++++++++-
 3 files changed, 39 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/be23f28c/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 c36d6a9..bf3dc6d 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
@@ -1067,12 +1067,22 @@ public abstract class AbstractClient implements Client {
         } 
 
         public void handleMessage(Message message) throws Fault {
-            Exception ex = message.getContent(Exception.class);
-            if (!message.getExchange().isSynchronous() && ex != null) {
-                //TODO: make sure it works with the failover feature
-                JaxrsClientCallback<?> cb = message.getExchange().get(JaxrsClientCallback.class);
-                cb.handleException(message, new ProcessingException(ex));
+            if (!message.getExchange().isSynchronous()) {
+                Throwable ex = message.getContent(Exception.class);
+                if (ex == null) {
+                    ex = message.getExchange().get(Exception.class);
+                }
+                if (ex != null) {
+                    JaxrsClientCallback<?> cb = message.getExchange().get(JaxrsClientCallback.class);
+                    if (ex instanceof Fault) {
+                        ex = ex.getCause();
+                    }
+                    ex = ex instanceof ProcessingException ? ex : new ProcessingException(ex);
+                    cb.handleException(message, ex);
+                }
             }
+            
+            
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/be23f28c/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index ff1650f..5097bec 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -984,15 +984,7 @@ public class WebClient extends AbstractClient {
         
         doRunInterceptorChain(m);
         
-        Future<T> future = cb.createFuture();
-        if (m.getExchange().get(Exception.class) != null) {
-            Throwable ex = m.getExchange().get(Exception.class);
-            if (ex instanceof Fault) {
-                ex = ex.getCause();
-            }
-            cb.handleException(m, ex);
-        }
-        return future;
+        return cb.createFuture();
     }
 
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/be23f28c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
index 4cf617e..2991df5 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
@@ -38,9 +38,11 @@ import javax.ws.rs.client.ClientRequestContext;
 import javax.ws.rs.client.ClientResponseContext;
 import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.client.ResponseProcessingException;
 import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -150,7 +152,7 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase
{
         }
     }
     @Test
-    public void testNonExistentJaxrs20() throws Exception {
+    public void testNonExistentJaxrs20WithGet() throws Exception {
         String address = "http://localhostt/bookstore";
         Client c = ClientBuilder.newClient();
         c.register(new TestResponseFilter());
@@ -169,6 +171,26 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testNonExistentJaxrs20WithPost() throws Exception {
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target("http://test.test/");
+        Invocation.Builder builder = target.request();
+        Entity<String> entity = Entity.entity("entity", MediaType.WILDCARD_TYPE);
+        Invocation invocation = builder.buildPost(entity);
+        Future<String> future = invocation.submit(
+            new GenericType<String>() {
+            }
+        );
+        
+        try {
+            future.get();
+        } catch (Exception ex) {
+            Throwable cause = ex.getCause();
+            assertTrue(cause instanceof ProcessingException);
+        }
+    }
+    
+    @Test
     public void testPostBookProcessingException() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/";
         List<Object> providers = new ArrayList<Object>();


Mime
View raw message