cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1449220 - in /cxf/branches/2.6.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
Date Fri, 22 Feb 2013 21:32:43 GMT
Author: sergeyb
Date: Fri Feb 22 21:32:42 2013
New Revision: 1449220

URL: http://svn.apache.org/r1449220
Log:
Merged revisions 1449022 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1449022 | sergeyb | 2013-02-22 13:10:01 +0000 (Fri, 22 Feb 2013) | 13 lines
  
  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.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Feb 22 21:32:42 2013
@@ -0,0 +1,2 @@
+/cxf/branches/2.7.x-fixes:1449022
+/cxf/trunk:1448978-1449000

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1449220&r1=1449219&r2=1449220&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Fri Feb 22 21:32:42 2013
@@ -31,6 +31,7 @@ import java.util.Map;
 
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -729,12 +730,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 = getHeaders();
         boolean contentTypeNotSet = headers.getFirst(HttpHeaders.CONTENT_TYPE) == null;

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1449220&r1=1449219&r2=1449220&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Feb 22 21:32:42 2013
@@ -31,6 +31,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -279,6 +280,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 =



Mime
View raw message