You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/02/22 14:10:01 UTC

svn commit: r1449022 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Author: sergeyb
Date: Fri Feb 22 13:10:01 2013
New Revision: 1449022

URL: http://svn.apache.org/r1449022
Log:
Merged revisions 1448978,1449000 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1448978 | sergeyb | 2013-02-22 10:39:18 +0000 (Fri, 22 Feb 2013) | 1 line
  
  [CXF-4848] Support for GenericEntity in WebClient
........
  r1449000 | sergeyb | 2013-02-22 11:42:46 +0000 (Fri, 22 Feb 2013) | 1 line
  
  [CXF-4848] Minor update
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1448978-1449000

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1449022&r1=1449021&r2=1449022&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Fri Feb 22 13:10:01 2013
@@ -38,6 +38,7 @@ import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -760,12 +761,25 @@ public class WebClient extends AbstractC
             responseClass, outGenericType);
     }
     
+    private static Type getGenericEntityType(GenericEntity<?> genericEntity, Type inGenericType) {
+        if (inGenericType != null && genericEntity.getType() != inGenericType) {
+            throw new IllegalArgumentException("Illegal type");    
+        }
+        return genericEntity.getType();
+    }
+
     protected Response doInvoke(String httpMethod, 
                                 Object body, 
                                 Class<?> requestClass,
                                 Type inGenericType,
                                 Class<?> responseClass, 
                                 Type outGenericType) {
+        if (body instanceof GenericEntity) {
+            GenericEntity<?> genericEntity = (GenericEntity<?>)body;
+            body = genericEntity.getEntity();
+            requestClass = genericEntity.getRawType();
+            inGenericType = getGenericEntityType(genericEntity, inGenericType);
+        }
         
         MultivaluedMap<String, String> headers = prepareHeaders(responseClass, body);
         resetResponse();

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1449022&r1=1449021&r2=1449022&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Fri Feb 22 13:10:01 2013
@@ -35,6 +35,7 @@ import javax.ws.rs.NotAcceptableExceptio
 import javax.ws.rs.ServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.client.ClientException;
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -318,6 +319,28 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testPostCollectionGenericEntityWebClient() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/collections3"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept("application/xml").type("application/xml");
+        Book b1 = new Book("CXF in Action", 123L);
+        Book b2 = new Book("CXF Rocks", 124L);
+        List<Book> books = new ArrayList<Book>();
+        books.add(b1);
+        books.add(b2);
+        GenericEntity<List<Book>> genericCollectionEntity = 
+            new GenericEntity<List<Book>>(books) {
+            };
+        
+        Book book = wc.post(genericCollectionEntity, Book.class);
+        assertEquals(200, wc.getResponse().getStatus());
+        assertNotSame(b1, book);
+        assertEquals(b1.getName(), book.getName());
+    }
+    
+    @Test
     public void testPostCollectionOfBooksWebClient() throws Exception {
         
         String endpointAddress =