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 2013/07/23 18:38:08 UTC
svn commit: r1506150 - in /cxf/branches/2.7.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/
rt/frontend/...
Author: sergeyb
Date: Tue Jul 23 16:38:07 2013
New Revision: 1506150
URL: http://svn.apache.org/r1506150
Log:
Merged revisions 1506144 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1506144 | sergeyb | 2013-07-23 17:19:22 +0100 (Tue, 23 Jul 2013) | 1 line
[CXF-5146] More work to do with having Typevariables recognized by Jackson
........
Modified:
cxf/branches/2.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1506144
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Tue Jul 23 16:38:07 2013
@@ -24,7 +24,6 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
@@ -594,11 +593,9 @@ public class ClientProxyImpl extends Abs
return r;
}
- Type genericType = method.getGenericReturnType();
- if (genericType instanceof TypeVariable) {
- genericType = InjectionUtils.getSuperType(method.getDeclaringClass(),
- (TypeVariable<?>)genericType);
- }
+ Type genericType =
+ InjectionUtils.processGenericTypeIfNeeded(method.getDeclaringClass(),
+ method.getGenericReturnType());
return readBody(r,
outMessage,
@@ -657,6 +654,8 @@ public class ClientProxyImpl extends Abs
if (bodyType != null) {
paramType = bodyType;
}
+ paramType = InjectionUtils.processGenericTypeIfNeeded(method.getDeclaringClass(),
+ paramType);
writeBody(body, outMessage, bodyClass, paramType,
anns, os);
} else {
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Tue Jul 23 16:38:07 2013
@@ -485,7 +485,7 @@ public class WebClient extends AbstractC
public <T> Collection<? extends T> invokeAndGetCollection(String httpMethod, Object body,
Class<T> memberClass) {
Response r = doInvoke(httpMethod, body, null,
- Collection.class, new ParameterizedCollectionType<T>(memberClass));
+ Collection.class, new ParameterizedCollectionType(memberClass));
return CastUtils.cast((Collection<?>)r.getEntity(), memberClass);
}
@@ -496,7 +496,7 @@ public class WebClient extends AbstractC
* @return JAX-RS Response
*/
public <T> Response postCollection(Object collection, Class<T> memberClass) {
- return doInvoke("POST", collection, new ParameterizedCollectionType<T>(memberClass),
+ return doInvoke("POST", collection, new ParameterizedCollectionType(memberClass),
Response.class, Response.class);
}
@@ -509,7 +509,7 @@ public class WebClient extends AbstractC
*/
public <T1, T2> T2 postCollection(Object collection, Class<T1> memberClass,
Class<T2> responseClass) {
- Response r = doInvoke("POST", collection, new ParameterizedCollectionType<T1>(memberClass),
+ Response r = doInvoke("POST", collection, new ParameterizedCollectionType(memberClass),
responseClass, responseClass);
return responseClass.cast(responseClass == Response.class ? r : r.getEntity());
}
@@ -524,8 +524,8 @@ public class WebClient extends AbstractC
public <T1, T2> Collection<? extends T2> postAndGetCollection(Object collection,
Class<T1> memberClass,
Class<T2> responseClass) {
- Response r = doInvoke("POST", collection, new ParameterizedCollectionType<T1>(memberClass),
- Collection.class, new ParameterizedCollectionType<T2>(responseClass));
+ Response r = doInvoke("POST", collection, new ParameterizedCollectionType(memberClass),
+ Collection.class, new ParameterizedCollectionType(responseClass));
return CastUtils.cast((Collection<?>)r.getEntity(), responseClass);
}
@@ -539,7 +539,7 @@ public class WebClient extends AbstractC
public <T> Collection<? extends T> postObjectGetCollection(Object body,
Class<T> responseClass) {
Response r = doInvoke("POST", body, null, Collection.class,
- new ParameterizedCollectionType<T>(responseClass));
+ new ParameterizedCollectionType(responseClass));
return CastUtils.cast((Collection<?>)r.getEntity(), responseClass);
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Tue Jul 23 16:38:07 2013
@@ -1242,16 +1242,25 @@ public final class InjectionUtils {
// to invoked.getReturnType(); same applies to the case when a method returns Response
type = targetObject.getClass();
} else {
- type = invoked.getGenericReturnType();
- if (type instanceof TypeVariable) {
- type = InjectionUtils.getSuperType(invoked.getDeclaringClass(),
- (TypeVariable<?>)type);
- }
+ type = processGenericTypeIfNeeded(invoked.getDeclaringClass(), invoked.getGenericReturnType());
+
}
return type;
}
+ public static Type processGenericTypeIfNeeded(Class<?> cls, Type type) {
+ if (type instanceof TypeVariable) {
+ return InjectionUtils.getSuperType(cls, (TypeVariable<?>)type);
+ } else if (type instanceof ParameterizedType
+ && ((ParameterizedType)type).getActualTypeArguments()[0] instanceof TypeVariable
+ && isSupportedCollectionOrArray(getRawType(type))) {
+ return new ParameterizedCollectionType(InjectionUtils.getActualType(type, 0));
+ } else {
+ return type;
+ }
+ }
+
public static Object getEntity(Object o) {
return o instanceof GenericEntity ? ((GenericEntity<?>)o).getEntity() : o;
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Jul 23 16:38:07 2013
@@ -27,7 +27,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -724,21 +723,20 @@ public final class JAXRSUtils {
Method method = ori.getMethodToInvoke();
- Class<?>[] parameterTypes = method.getParameterTypes();
- Parameter[] paramsInfo = ori.getParameters().toArray(new Parameter[ori.getParameters().size()]);
Method annotatedMethod = ori.getAnnotatedMethod();
- Type[] genericParameterTypes = annotatedMethod == null ? method.getGenericParameterTypes()
- : annotatedMethod.getGenericParameterTypes();
- Annotation[][] anns = annotatedMethod == null ? null : annotatedMethod.getParameterAnnotations();
+ Method actualMethod = annotatedMethod == null ? method : annotatedMethod;
+
+ Class<?>[] parameterTypes = actualMethod.getParameterTypes();
+ Parameter[] paramsInfo = ori.getParameters().toArray(new Parameter[ori.getParameters().size()]);
+
+ Type[] genericParameterTypes = actualMethod.getGenericParameterTypes();
+ Annotation[][] anns = actualMethod.getParameterAnnotations();
List<Object> params = new ArrayList<Object>(parameterTypes.length);
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> param = parameterTypes[i];
- Type genericParam = genericParameterTypes[i];
- if (genericParam instanceof TypeVariable) {
- genericParam = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),
- (TypeVariable<?>)genericParam);
- }
+ Type genericParam = InjectionUtils.processGenericTypeIfNeeded(
+ ori.getClassResourceInfo().getServiceClass(), genericParameterTypes[i]);
if (param == Object.class) {
param = (Class<?>)genericParam;
} else if (genericParam == Object.class) {
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterizedCollectionType.java Tue Jul 23 16:38:07 2013
@@ -23,11 +23,11 @@ import java.lang.reflect.ParameterizedTy
import java.lang.reflect.Type;
import java.util.Collection;
-public final class ParameterizedCollectionType<T> implements ParameterizedType {
- private final Class<T> collectionMemberClass;
+public final class ParameterizedCollectionType implements ParameterizedType {
+ private final Class<?> collectionMemberClass;
private final Type[] typeArgs;
- public ParameterizedCollectionType(Class<T> collectionMemberClass) {
+ public ParameterizedCollectionType(Class<?> collectionMemberClass) {
this.collectionMemberClass = collectionMemberClass;
this.typeArgs = new Type[] {collectionMemberClass};
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java Tue Jul 23 16:38:07 2013
@@ -407,7 +407,7 @@ public class JAXBElementProviderTest ext
TagVO2 tag = new TagVO2("a", "b");
List<TagVO2> tags = Collections.singletonList(tag);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- provider.writeTo(tags, List.class, new ParameterizedCollectionType<TagVO2>(TagVO2.class),
+ provider.writeTo(tags, List.class, new ParameterizedCollectionType(TagVO2.class),
new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
assertTrue(bos.toString().contains("prefix:thetag"));
assertFalse(bos.toString().contains("ns1:thetag"));
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Jul 23 16:38:07 2013
@@ -141,7 +141,8 @@ public class JAXRSUtilsTest extends Asse
headers.putSingle("Content-Type", ct);
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals("2 form params should've been identified", 2, params.size());
assertEquals("First Form Parameter not matched correctly",
@@ -794,7 +795,8 @@ public class JAXRSUtilsTest extends Asse
MessageImpl messageImpl = new MessageImpl();
messageImpl.put(Message.QUERY_STRING, "query=24&query2");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(4, params.size());
@@ -811,7 +813,8 @@ public class JAXRSUtilsTest extends Asse
MessageImpl messageImpl = new MessageImpl();
messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -827,7 +830,8 @@ public class JAXRSUtilsTest extends Asse
MessageImpl messageImpl = new MessageImpl();
messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -845,7 +849,8 @@ public class JAXRSUtilsTest extends Asse
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING,
"query2=query2Value&query2=query2Value2&query3=1&query3=2&query4");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(6, params.size());
@@ -890,7 +895,8 @@ public class JAXRSUtilsTest extends Asse
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.add("Cookie", "c1=c1Value");
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(params.size(), 2);
@@ -909,7 +915,8 @@ public class JAXRSUtilsTest extends Asse
headers.add("Cookie", "c1=c1Value; c2=c2Value");
headers.add("Cookie", "c3=c3Value");
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(params.size(), 3);
@@ -925,7 +932,8 @@ public class JAXRSUtilsTest extends Asse
UUID u = UUID.randomUUID();
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "p1=" + u.toString() + "&p2=1&p3=2");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(3, params.size());
@@ -941,7 +949,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testFromValueParam", argType);
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "p1=Europe%2FLondon");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -958,7 +967,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testCustomerParam", argType);
messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry&p3=Jack&p4=John");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(3, params.size());
@@ -988,7 +998,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testLocaleParam", argType);
messageImpl.put(Message.QUERY_STRING, "p1=en_us");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -1006,7 +1017,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testGenericObjectParam", argType);
messageImpl.put(Message.QUERY_STRING, "p1=thequery");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -1024,7 +1036,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testGenericObjectParam", argType);
messageImpl.put(Message.QUERY_STRING, "p1=thequery");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -1042,7 +1055,8 @@ public class JAXRSUtilsTest extends Asse
Method m = Customer.class.getMethod("testCustomerParam", argType);
messageImpl.put(Message.QUERY_STRING, "p3=jack");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(3, params.size());
@@ -1058,7 +1072,8 @@ public class JAXRSUtilsTest extends Asse
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),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals(1, params.size());
@@ -1074,9 +1089,10 @@ public class JAXRSUtilsTest extends Asse
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "p1=1");
try {
- JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
- null,
- messageImpl);
+ JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
+ null,
+ messageImpl);
fail("HashMap can not be handled as parameter");
} catch (WebApplicationException ex) {
assertEquals(500, ex.getResponse().getStatus());
@@ -1094,9 +1110,10 @@ public class JAXRSUtilsTest extends Asse
MessageImpl messageImpl = new MessageImpl();
messageImpl.put(Message.QUERY_STRING, "p1=3");
try {
- JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
- null,
- messageImpl);
+ JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
+ null,
+ messageImpl);
fail("CustomerGender have no instance with name 3");
} catch (WebApplicationException ex) {
assertEquals(404, ex.getResponse().getStatus());
@@ -1131,7 +1148,8 @@ public class JAXRSUtilsTest extends Asse
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "a=aValue");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals(1, params.size());
@@ -1146,7 +1164,8 @@ public class JAXRSUtilsTest extends Asse
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "a=aValue");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals(1, params.size());
@@ -1161,7 +1180,8 @@ public class JAXRSUtilsTest extends Asse
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "a=aValue");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals(1, params.size());
@@ -1256,7 +1276,8 @@ public class JAXRSUtilsTest extends Asse
String body = "a=aValue&b=123&cb=true";
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals("Bean should be created", 1, params.size());
@@ -1306,7 +1327,8 @@ public class JAXRSUtilsTest extends Asse
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
String body = "g.b=1&g.b=2";
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null,
messageImpl);
assertEquals("Bean should be created", 1, params.size());
@@ -1325,7 +1347,8 @@ public class JAXRSUtilsTest extends Asse
MessageImpl simpleMessageImpl,
MultivaluedMap<String, String> complexValues,
MessageImpl complexMessageImpl) throws Exception {
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
simpleValues,
simpleMessageImpl);
assertEquals("Bean should be created", 1, params.size());
@@ -1335,9 +1358,10 @@ public class JAXRSUtilsTest extends Asse
assertEquals("aValue", cb.getA());
assertEquals(new Long(123), cb.getB());
- params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
- complexValues,
- complexMessageImpl);
+ params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
+ complexValues,
+ complexMessageImpl);
assertEquals("Bean should be created", 1, params.size());
Customer.CustomerBean cb1 = (Customer.CustomerBean)params.get(0);
assertNotNull(cb1);
@@ -1416,7 +1440,8 @@ public class JAXRSUtilsTest extends Asse
messageImpl.put(Message.QUERY_STRING,
"query=first&query2=second&query3=3&query4=true&query5");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals("First Query Parameter of multiple was not matched correctly", "first",
params.get(0));
@@ -1439,7 +1464,8 @@ public class JAXRSUtilsTest extends Asse
MessageImpl messageImpl = new MessageImpl();
messageImpl.put(Message.REQUEST_URI, "/foo;p4=0;p3=3/bar;p1=1;p2/baz;p4=4;p4=5;p5");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals("5 Matrix params should've been identified", 6, params.size());
@@ -1468,7 +1494,8 @@ public class JAXRSUtilsTest extends Asse
messageImpl.put(Message.REQUEST_URI, "/bar%20foo;p4=0%201");
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
values.add("ps", "bar%20foo;p4=0%201");
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
values,
messageImpl);
assertEquals("2 params should've been identified", 2, params.size());
@@ -1503,7 +1530,8 @@ public class JAXRSUtilsTest extends Asse
}
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
null, messageImpl);
assertEquals("2 form params should've been identified", 2, params.size());
@@ -1534,7 +1562,8 @@ public class JAXRSUtilsTest extends Asse
}
});
- List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
+ new ClassResourceInfo(Customer.class)),
new MetadataMap<String, String>(), messageImpl);
assertEquals("3 params should've been identified", 3, params.size());
Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Tue Jul 23 16:38:07 2013
@@ -21,7 +21,9 @@ package org.apache.cxf.systest.jaxrs;
import java.io.ByteArrayOutputStream;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
@@ -111,6 +113,16 @@ public class BookStoreSpring {
}
@SuppressWarnings("unchecked")
+ @GET
+ @Path("/books/superbooks")
+ @Produces("application/json")
+ public <T extends Book> List<T> getSuperBookCollectionJson() {
+ SuperBook book = new SuperBook("SuperBook", 999L);
+
+ return Collections.singletonList((T)book);
+ }
+
+ @SuppressWarnings("unchecked")
@POST
@Path("/books/superbook")
@Consumes("application/json")
@@ -119,6 +131,18 @@ public class BookStoreSpring {
return (T)(SuperBook)book;
}
+ @SuppressWarnings("unchecked")
+ @POST
+ @Path("/books/superbooks")
+ @Consumes("application/json")
+ @Produces("application/json")
+ public <T extends Book> List<T> echoSuperBookCollectionJson(List<T> book) {
+ if (book.get(0) instanceof SuperBook) {
+ return book;
+ }
+ throw new WebApplicationException(400);
+ }
+
@POST
@Path("/books/xsitype")
@Produces("application/xml")
Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1506150&r1=1506149&r2=1506150&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java Tue Jul 23 16:38:07 2013
@@ -24,6 +24,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
@@ -75,6 +76,29 @@ public class JAXRSClientServerResourceJa
}
@Test
+ public void testGetSuperBookCollectionProxy() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/store2";
+ BookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, BookStoreSpring.class,
+ Collections.singletonList(new JacksonJsonProvider()));
+ List<SuperBook> books = proxy.getSuperBookCollectionJson();
+ assertEquals(999L, books.get(0).getId());
+ }
+
+ @Test
+ public void testEchoSuperBookCollectionProxy() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/store2";
+ BookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, BookStoreSpring.class,
+ Collections.singletonList(new JacksonJsonProvider()));
+ List<SuperBook> books =
+ proxy.echoSuperBookCollectionJson(Collections.singletonList(new SuperBook("Super", 124L)));
+ assertEquals(124L, books.get(0).getId());
+ }
+
+ @Test
public void testEchoSuperBookProxy() throws Exception {
String endpointAddress =
@@ -98,6 +122,20 @@ public class JAXRSClientServerResourceJa
Book book = collection.iterator().next();
assertEquals(123L, book.getId());
}
+
+ @Test
+ public void testGetCollectionOfSuperBooks() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/store2/books/superbooks";
+ WebClient wc = WebClient.create(endpointAddress,
+ Collections.singletonList(new JacksonJsonProvider()));
+ wc.accept("application/json");
+ Collection<? extends Book> collection = wc.getCollection(Book.class);
+ assertEquals(1, collection.size());
+ Book book = collection.iterator().next();
+ assertEquals(999L, book.getId());
+ }
private String getStringFromInputStream(InputStream in) throws Exception {