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 2015/07/23 13:09:47 UTC
cxf git commit: [CXF-6450] Applying a patch on behalf of Vladimir
Kulev, re-enabling the test
Repository: cxf
Updated Branches:
refs/heads/master 829cd5c41 -> b4316048d
[CXF-6450] Applying a patch on behalf of Vladimir Kulev, re-enabling the test
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b4316048
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b4316048
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b4316048
Branch: refs/heads/master
Commit: b4316048d6de7a6fa79260762419f6eaed9cfb3e
Parents: 829cd5c
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Thu Jul 23 14:09:29 2015 +0300
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Thu Jul 23 14:09:29 2015 +0300
----------------------------------------------------------------------
.../apache/cxf/jaxrs/utils/InjectionUtils.java | 54 ++++++++++++++------
.../cxf/jaxrs/utils/InjectionUtilsTest.java | 33 +++++++++++-
...ServerResourceJacksonSpringProviderTest.java | 2 -
3 files changed, 71 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/b4316048/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index 9491129..36ee7f2 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -24,6 +24,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -116,34 +117,57 @@ public final class InjectionUtils {
return !cls.isInterface() && !Modifier.isAbstract(cls.getModifiers());
}
+ private static ParameterizedType findGenericDeclaration(GenericDeclaration declaration, Type scope) {
+ if (scope instanceof ParameterizedType) {
+ ParameterizedType type = (ParameterizedType) scope;
+ if (type.getRawType() == declaration) {
+ return type;
+ } else {
+ scope = type.getRawType();
+ }
+ }
+ if (scope instanceof Class) {
+ Class<?> classScope = (Class<?>)scope;
+ ParameterizedType result = findGenericDeclaration(declaration, classScope.getGenericSuperclass());
+ if (result == null) {
+ for (Type type : classScope.getGenericInterfaces()) {
+ result = findGenericDeclaration(declaration, type);
+ if (result != null) {
+ break;
+ }
+ }
+ }
+ return result;
+ }
+ return null;
+ }
+
public static Type getSuperType(Class<?> serviceClass, TypeVariable<?> var) {
int pos = 0;
- TypeVariable<?>[] vars = var.getGenericDeclaration().getTypeParameters();
+ GenericDeclaration genericDeclaration = var.getGenericDeclaration();
+ TypeVariable<?>[] vars = genericDeclaration.getTypeParameters();
for (; pos < vars.length; pos++) {
if (vars[pos].getName().equals(var.getName())) {
break;
}
}
- Type genericSubtype = serviceClass.getGenericSuperclass();
- if (!(genericSubtype instanceof ParameterizedType)) {
- Type[] genInterfaces = serviceClass.getGenericInterfaces();
- for (Type t : genInterfaces) {
- genericSubtype = t;
- break;
- }
+ ParameterizedType genericSubtype = findGenericDeclaration(genericDeclaration, serviceClass);
+ Type result = null;
+ if (genericSubtype != null) {
+ result = genericSubtype.getActualTypeArguments()[pos];
}
- if (!(genericSubtype instanceof ParameterizedType)) {
- genericSubtype = null;
+ if (result instanceof TypeVariable) {
+ result = getSuperType(serviceClass, (TypeVariable<?>) result);
}
- Type result = InjectionUtils.getActualType(genericSubtype, pos);
if (result == null || result == Object.class) {
- Type[] bounds = var.getBounds();
- int boundPos = bounds.length > pos ? pos : 0;
- if (bounds.length > boundPos && bounds[boundPos] != Object.class) {
- result = bounds[boundPos];
+ for (Type bound : var.getBounds()) {
+ if (bound != Object.class) {
+ result = bound;
+ break;
+ }
}
}
return result;
http://git-wip-us.apache.org/repos/asf/cxf/blob/b4316048/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
index 2f65c5b..90bccbc 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
@@ -18,7 +18,10 @@
*/
package org.apache.cxf.jaxrs.utils;
+import java.io.Serializable;
import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -42,6 +45,7 @@ import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.easymock.EasyMock;
+
import org.junit.Assert;
import org.junit.Test;
@@ -145,6 +149,17 @@ public class InjectionUtilsTest extends Assert {
assertEquals("Type is wrong", CarType.AUDI, carType);
}
+ @Test
+ public void testGenericInterfaceType() throws NoSuchMethodException {
+ Type str = InjectionUtils.getGenericResponseType(GenericInterface.class.getMethod("get"),
+ TestService.class, "", String.class, new ExchangeImpl());
+ assertEquals(String.class, str);
+ ParameterizedType list = (ParameterizedType) InjectionUtils.getGenericResponseType(
+ GenericInterface.class.getMethod("list"), TestService.class,
+ new ArrayList<String>(), ArrayList.class, new ExchangeImpl());
+ assertEquals(String.class, list.getActualTypeArguments()[0]);
+ }
+
static class CustomerBean1 {
private String a;
private Long b;
@@ -304,5 +319,21 @@ public class InjectionUtilsTest extends Assert {
}
}
-
+ interface GenericInterface<A> {
+ A get();
+ List<A> list();
+ }
+ interface ServiceInterface extends Serializable, GenericInterface<String> {
+ }
+ public static class TestService implements Serializable, ServiceInterface {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public String get() {
+ return "";
+ }
+ @Override
+ public List<String> list() {
+ return new ArrayList<>();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/b4316048/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
index 768e6ec..d7a674b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
@@ -44,7 +44,6 @@ import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
public class JAXRSClientServerResourceJacksonSpringProviderTest extends AbstractBusClientServerTestBase {
@@ -190,7 +189,6 @@ public class JAXRSClientServerResourceJacksonSpringProviderTest extends Abstract
}
@Test
- @Ignore
public void testGetGenericSuperBookInt2() throws Exception {
String endpointAddress =