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-6260] Updating WebClient to check InvocationCallback TypeVariable
Date Sun, 15 Feb 2015 18:48:20 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes c8d09146e -> c1f3dd3d7


[CXF-6260] Updating WebClient to check InvocationCallback TypeVariable


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

Branch: refs/heads/3.0.x-fixes
Commit: c1f3dd3d7051636da5b978866f5df48c8857cdc6
Parents: c8d0914
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Sun Feb 15 18:46:10 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Sun Feb 15 18:47:57 2015 +0000

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/client/WebClient.java  | 10 ++++-
 .../jaxrs/JAXRS20ClientServerBookTest.java      | 39 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c1f3dd3d/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 d1279b4..ff1650f 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
@@ -22,6 +22,7 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.net.URI;
 import java.util.Arrays;
 import java.util.Collection;
@@ -915,10 +916,15 @@ public class WebClient extends AbstractClient {
     private Type getCallbackType(InvocationCallback<?> callback) {
         Class<?> cls = callback.getClass();
         ParameterizedType pt = findCallbackType(cls);
+        Type actualType = null;
         for (Type tp : pt.getActualTypeArguments()) {
-            return tp;
+            actualType = tp;
+            break;
         }
-        return null;
+        if (actualType instanceof TypeVariable) { 
+            actualType = InjectionUtils.getSuperType(cls, (TypeVariable<?>)actualType);
+        }
+        return actualType;
     }
     
     protected <T> Future<T> doInvokeAsyncCallback(String httpMethod, 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1f3dd3d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index d8f5cc6..5bd1740 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -271,6 +271,26 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         assertNotSame(collectionEntity.getEntity().get(0), book);
         assertEquals(collectionEntity.getEntity().get(0).getName(), book.getName());
     }
+    @Test
+    public void testPostCollectionGenericEntityGenericCallback() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/collections3"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept("application/xml").type("application/xml");
+        
+        GenericEntity<List<Book>> collectionEntity = createGenericEntity();
+        final Holder<Book> holder = new Holder<Book>();
+        InvocationCallback<Book> callback = 
+            new GenericInvocationCallback<Book>(holder) { };        
+            
+        Future<Book> future = wc.post(collectionEntity, callback);
+        Book book = future.get();
+        assertEquals(200, wc.getResponse().getStatus());
+        assertSame(book, holder.value);
+        assertNotSame(collectionEntity.getEntity().get(0), book);
+        assertEquals(collectionEntity.getEntity().get(0).getName(), book.getName());
+    }
     
     @Test
     public void testPostCollectionGenericEntityAsEntity() throws Exception {
@@ -465,6 +485,25 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         }
         
     }
+    private static class GenericInvocationCallback<T> implements InvocationCallback<T>
{
+        private Holder<T> holder;
+        public GenericInvocationCallback(Holder<T> holder) {
+            this.holder = holder;
+        }
+        
+        @Override
+        public void completed(T book) {
+            holder.value = book;
+            
+        }
+
+        @Override
+        public void failed(Throwable arg0) {
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
     
     private void doTestGetBook(String address, boolean useAsync) {
         WebClient wc = createWebClient(address);


Mime
View raw message