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 2009/03/31 10:45:55 UTC
svn commit: r760369 - in /cxf/branches/2.1.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/sr...
Author: sergeyb
Date: Tue Mar 31 08:45:52 2009
New Revision: 760369
URL: http://svn.apache.org/viewvc?rev=760369&view=rev
Log:
Merged revisions 759890 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r759890 | sergeyb | 2009-03-30 10:28:29 +0100 (Mon, 30 Mar 2009) | 1 line
JAXRS: support for arrays
........
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 31 08:45:52 2009
@@ -1 +1 @@
-/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,759961,759963-759964,759966,760029,760073,760150,760178
+/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,759890,759961,759963-759964,759966,760029,760073,760150,760178
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Tue Mar 31 08:45:52 2009
@@ -205,6 +205,7 @@
private static void handleMapper(List<Object> candidates, ProviderInfo em,
Class<?> expectedType, Message m) {
+
Type[] types = em.getProvider().getClass().getGenericInterfaces();
for (Type t : types) {
if (t instanceof ParameterizedType) {
@@ -217,6 +218,7 @@
InjectionUtils.injectContextMethods(em.getProvider(), em, m);
}
candidates.add(em.getProvider());
+ break;
}
}
}
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Tue Mar 31 08:45:52 2009
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxrs.utils;
+import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -134,10 +135,14 @@
}
public static Class<?> getActualType(Type genericType) {
- if (genericType == null
- || !ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
+
+ if (genericType == null) {
return null;
}
+ if (!ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
+ Class<?> cls = (Class<?>)genericType;
+ return cls.isArray() ? cls.getComponentType() : null;
+ }
ParameterizedType paramType = (ParameterizedType)genericType;
return (Class<?>)paramType.getActualTypeArguments()[0];
}
@@ -320,6 +325,21 @@
return theValues;
}
+ @SuppressWarnings("unchecked")
+ public static Object injectIntoArray(Type genericType, List<String> values,
+ boolean decoded, ParameterType pathParam, Message message) {
+ Class<?> realType = InjectionUtils.getActualType(genericType);
+ values = checkPathSegment(values, realType, pathParam);
+ Object[] array = (Object[])Array.newInstance(realType, values.size());
+ for (int i = 0; i < values.size(); i++) {
+ String value = decodeValue(values.get(i), decoded, pathParam);
+ Object o = InjectionUtils.handleParameter(value, realType, pathParam, message);
+ if (o != null) {
+ array[i] = o;
+ }
+ }
+ return array;
+ }
@SuppressWarnings("unchecked")
@@ -382,16 +402,19 @@
}
}
}
-
+
+ Object value = null;
if (List.class.isAssignableFrom(paramType)) {
- return InjectionUtils.injectIntoList(genericType, paramValues, decoded, pathParam,
+ value = InjectionUtils.injectIntoList(genericType, paramValues, decoded, pathParam,
message);
} else if (Set.class.isAssignableFrom(paramType)) {
- return InjectionUtils.injectIntoSet(genericType, paramValues, false, decoded, pathParam,
+ value = InjectionUtils.injectIntoSet(genericType, paramValues, false, decoded, pathParam,
message);
} else if (SortedSet.class.isAssignableFrom(paramType)) {
- return InjectionUtils.injectIntoSet(genericType, paramValues, true, decoded, pathParam,
+ value = InjectionUtils.injectIntoSet(genericType, paramValues, true, decoded, pathParam,
message);
+ } else if (paramType.isArray()) {
+ value = InjectionUtils.injectIntoArray(genericType, paramValues, decoded, pathParam, message);
} else {
String result = null;
if (paramValues.size() > 0) {
@@ -401,11 +424,10 @@
}
if (result != null) {
result = decodeValue(result, decoded, pathParam);
- return InjectionUtils.handleParameter(result, paramType, pathParam, message);
- } else {
- return null;
+ value = InjectionUtils.handleParameter(result, paramType, pathParam, message);
}
}
+ return value;
}
public static ThreadLocalProxy createThreadLocalProxy(Class<?> type) {
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Mar 31 08:45:52 2009
@@ -235,7 +235,11 @@
// complete
}
- public void testCustomerParam(@QueryParam("p1") Customer c) {
+ public void testCustomerParam(@QueryParam("p1") Customer c, @QueryParam("p2") Customer[] c2) {
+ // complete
+ }
+
+ public void testCustomerParam2(@QueryParam("p1") String[] p) {
// complete
}
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Mar 31 08:45:52 2009
@@ -552,16 +552,34 @@
Message messageImpl = createMessage();
ProviderFactory.getInstance(messageImpl).registerUserProvider(
new CustomerParameterHandler());
- Class[] argType = {Customer.class};
+ Class[] argType = {Customer.class, Customer[].class};
Method m = Customer.class.getMethod("testCustomerParam", argType);
- messageImpl.put(Message.QUERY_STRING, "p1=Fred");
+ messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
null,
messageImpl);
- assertEquals(1, params.size());
+ assertEquals(2, params.size());
Customer c = (Customer)params.get(0);
assertEquals("Fred", c.getName());
+ Customer c2 = ((Customer[])params.get(1))[0];
+ assertEquals("Barry", c2.getName());
+ }
+
+ @Test
+ public void testArrayParamNoProvider() throws Exception {
+ Message messageImpl = createMessage();
+ Class[] argType = {String[].class};
+ Method m = Customer.class.getMethod("testCustomerParam2", argType);
+
+ messageImpl.put(Message.QUERY_STRING, "p1=Fred&p1=Barry");
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ null,
+ messageImpl);
+ assertEquals(1, params.size());
+ String[] values = (String[])params.get(0);
+ assertEquals("Fred", values[0]);
+ assertEquals("Barry", values[1]);
}
@Test
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Mar 31 08:45:52 2009
@@ -191,6 +191,15 @@
int index = url2.lastIndexOf('/');
return doGetBook(url2.substring(index + 1));
}
+
+ @GET
+ @Path("/bookidarray")
+ public Book getBookByURLQuery(@QueryParam("id") String[] ids) throws Exception {
+ if (ids == null || ids.length != 3) {
+ throw new WebApplicationException();
+ }
+ return doGetBook(ids[0] + ids[1] + ids[2]);
+ }
@GET
@Path("/securebooks/{bookId}/")
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=760369&r1=760368&r2=760369&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Tue Mar 31 08:45:52 2009
@@ -73,7 +73,14 @@
"application/xml", 200);
}
-
+ @Test
+ public void testGetBookByArrayQuery() throws Exception {
+ getAndCompareAsStrings("http://localhost:9080/bookstore/bookidarray?"
+ + "id=1&id=2&id=3",
+ "resources/expected_get_book123.txt",
+ "application/xml", 200);
+ }
+
@Test
public void testNoRootResourceException() throws Exception {
getAndCompare("http://localhost:9080/nobookstore/webappexception",