cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1501339 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java test/java/org/apache/cxf/jaxrs/Customer.java test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Date Tue, 09 Jul 2013 15:41:32 GMT
Author: sergeyb
Date: Tue Jul  9 15:41:31 2013
New Revision: 1501339

URL: http://svn.apache.org/r1501339
Log:
[CXF-5115] Support for primitive arays

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1501339&r1=1501338&r2=1501339&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Tue Jul  9 15:41:31 2013
@@ -804,6 +804,8 @@ public final class InjectionUtils {
         if (o != null) {
             if (theValues instanceof Collection) {
                 Collection.class.cast(theValues).add(o);
+            } else if (theValues.getClass().getComponentType().isPrimitive()) {
+                Array.set(theValues, index, o);
             } else {
                 ((Object[]) theValues)[index] = o;
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1501339&r1=1501338&r2=1501339&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Jul 
9 15:41:31 2013
@@ -364,6 +364,16 @@ public class Customer extends AbstractCu
     }
     
     @Produces("text/xml")   
+    public void testQueryIntegerArray(@QueryParam("query") Integer[] query) {
+        // complete
+    }
+    
+    @Produces("text/xml")   
+    public void testQueryIntArray(@QueryParam("query") int[] query) {
+        // complete
+    }
+    
+    @Produces("text/xml")   
     public void testQueryAsList(
         @DefaultValue("default") @QueryParam("query") List<String> queryString,
         @QueryParam("query2") List<String> queryString2,

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1501339&r1=1501338&r2=1501339&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Jul  9 15:41:31 2013
@@ -830,6 +830,38 @@ public class JAXRSUtilsTest extends Asse
         assertNull(params.get(3));
     }
     
+    @Test
+    public void testQueryParametersIntegerArray() throws Exception {
+        Class<?>[] argType = {Integer[].class};
+        Method m = Customer.class.getMethod("testQueryIntegerArray", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        
+        messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals(1, params.size());
+        Integer[] intValues = (Integer[])params.get(0);
+        assertEquals(1, (int)intValues[0]);
+        assertEquals(2, (int)intValues[1]);
+    }
+    
+    @Test
+    public void testQueryParametersIntArray() throws Exception {
+        Class<?>[] argType = {int[].class};
+        Method m = Customer.class.getMethod("testQueryIntArray", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        
+        messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals(1, params.size());
+        int[] intValues = (int[])params.get(0);
+        assertEquals(1, intValues[0]);
+        assertEquals(2, intValues[1]);
+    }
+    
     @SuppressWarnings("unchecked")
     @Test
     public void testQueryParamAsListWithDefaultValue() throws Exception {



Mime
View raw message