cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1039197 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Thu, 25 Nov 2010 22:08:44 GMT
Author: sergeyb
Date: Thu Nov 25 22:08:44 2010
New Revision: 1039197

URL: http://svn.apache.org/viewvc?rev=1039197&view=rev
Log:
[CXF-3149] Making WebClient.invokeAndGetCollections work better with 3rd party providers -
patch on behalf of Dobes Vandermeer has been applied

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1039197&r1=1039196&r2=1039197&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Thu
Nov 25 22:08:44 2010
@@ -53,6 +53,7 @@ import org.apache.cxf.jaxrs.model.Parame
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.jaxrs.utils.ParameterizedCollectionType;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.phase.Phase;
@@ -339,8 +340,8 @@ public class WebClient extends AbstractC
      */
     public <T> Collection<? extends T> invokeAndGetCollection(String httpMethod,
Object body, 
                                                     Class<T> memberClass) {
-        
-        Response r = doInvoke(httpMethod, body, Collection.class, memberClass);
+        Response r = doInvoke(httpMethod, body, Collection.class,
+                              new ParameterizedCollectionType<T>(memberClass));
         
         if (r.getStatus() >= 400) {
             throw new WebApplicationException(r);

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java?rev=1039197&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
Thu Nov 25 22:08:44 2010
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.utils;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+public final class ParameterizedCollectionType<T> implements ParameterizedType {
+    private final Class<T> collectionMemberClass;
+    private final Type[] typeArgs;
+
+    public ParameterizedCollectionType(Class<T> collectionMemberClass) {
+        this.collectionMemberClass = collectionMemberClass;
+        this.typeArgs = new Type[] {collectionMemberClass};
+    }
+     
+    public Type[] getActualTypeArguments() {
+        return typeArgs;
+    }
+
+    public Type getOwnerType() {
+        return null;
+    }
+
+    public Type getRawType() {
+        return Collection.class;
+    }
+
+    public String toString() {
+        return "java.util.Collection<" + collectionMemberClass.getName() + ">";
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1039197&r1=1039196&r2=1039197&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Thu
Nov 25 22:08:44 2010
@@ -221,8 +221,8 @@ public class BookStore {
     
     @POST
     @Path("/collections")
-    @Produces("application/xml")
-    @Consumes("application/xml")
+    @Produces({"application/xml", "application/json" })
+    @Consumes({"application/xml", "application/json" })
     public List<Book> getBookCollection(List<Book> bs) throws Exception {
         if (bs == null || bs.size() != 2) {
             throw new RuntimeException();
@@ -230,6 +230,13 @@ public class BookStore {
         return bs;
     }
     
+    @GET
+    @Path("/collections")
+    @Produces({"application/xml", "application/json" })
+    public List<Book> getBookCollection() throws Exception {
+        return new ArrayList<Book>(books.values());
+    }
+    
     @POST
     @Path("/array")
     @Produces("application/xml")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1039197&r1=1039196&r2=1039197&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Thu Nov 25 22:08:44 2010
@@ -64,6 +64,20 @@ public class JAXRSClientServerBookTest e
                    launchServer(BookServer.class));
     }
     
+
+    @Test
+    public void testGetCollectionOfBooks() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/collections"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept("application/xml");
+        Collection<? extends Book> collection = wc.getCollection(Book.class);
+        assertEquals(1, collection.size());
+        Book book = collection.iterator().next();
+        assertEquals(123L, book.getId());
+    }
+    
     
     @Test
     public void testOnewayWebClient() throws Exception {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1039197&r1=1039196&r2=1039197&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Thu Nov 25 22:08:44 2010
@@ -26,8 +26,11 @@ import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Collection;
+import java.util.Collections;
 
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -59,6 +62,20 @@ public class JAXRSClientServerResourceJa
     }
     
     @Test
+    public void testGetCollectionOfBooks() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/webapp/bookstore/collections"; 
+        WebClient wc = WebClient.create(endpointAddress,
+            Collections.singletonList(new org.codehaus.jackson.jaxrs.JacksonJsonProvider()));
+        wc.accept("application/json");
+        Collection<? extends Book> collection = wc.getCollection(Book.class);
+        assertEquals(1, collection.size());
+        Book book = collection.iterator().next();
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testPostPetStatus() throws Exception {
         
         String endpointAddress =



Mime
View raw message