cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1039504 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 26 Nov 2010 18:40:08 GMT
Author: sergeyb
Date: Fri Nov 26 18:40:08 2010
New Revision: 1039504

URL: http://svn.apache.org/viewvc?rev=1039504&view=rev
Log:
[CXF-2958] Support for explicit collections of query or matrix params with proxies

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1039504&r1=1039503&r2=1039504&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Nov 26 18:40:08 2010
@@ -27,8 +27,11 @@ import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URL;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -462,7 +465,18 @@ public class AbstractClient implements C
                                                + "with matrix and query parameters only");
         }
         if (!"".equals(paramName)) {
-            addToBuilder(ub, paramName, pValue, pt);    
+            
+            if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) {
+                Collection<?> c = pValue.getClass().isArray() 
+                    ? Arrays.asList((Object[]) pValue) : (Collection) pValue;
+                for (Iterator<?> it = c.iterator(); it.hasNext();) {
+                    addToBuilder(ub, paramName, it.next(), pt);
+                }
+            } else { 
+                addToBuilder(ub, paramName, pValue, pt); 
+            }
+                
+                    
         } else {
             MultivaluedMap<String, Object> values = 
                 InjectionUtils.extractValuesFromBean(pValue, "");

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=1039504&r1=1039503&r2=1039504&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 Fri
Nov 26 18:40:08 2010
@@ -278,6 +278,15 @@ public class BookStore {
     }
     
     @GET
+    @Path("/segment/matrix-list")
+    public Book getBookByMatrixListParams(@MatrixParam("first") List<String> list)
throws Exception {
+        if (list.size() != 2) {
+            throw new RuntimeException();
+        }
+        return doGetBook(list.get(0) + list.get(1));
+    }
+    
+    @GET
     @Path("/bookheaders/")
     public Book getBookByHeader(@HeaderParam("BOOK") List<String> ids) throws Exception
{
         List<MediaType> types = httpHeaders.getAcceptableMediaTypes();

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=1039504&r1=1039503&r2=1039504&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
Fri Nov 26 18:40:08 2010
@@ -128,6 +128,16 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testProxyWithCollectionMatrixParams() throws Exception {
+        BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        List<String> params = new ArrayList<String>(); 
+        params.add("12");
+        params.add("3");
+        Book book = proxy.getBookByMatrixListParams(params);
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testPropogateException() throws Exception {
         getAndCompare("http://localhost:" + PORT + "/bookstore/propogateexception",
                       "", "application/xml", 500);



Mime
View raw message