Repository: cxf Updated Branches: refs/heads/2.7.x-fixes ebe561f18 -> 9d671444d
[CXF-6078] Checking service class interfaces if one of its non-interface super classes has no expected JAX-RS annotated method Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/9d671444 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9d671444 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9d671444 Branch: refs/heads/2.7.x-fixes Commit: 9d671444d3e677e6e7f5b5e86f13fc3d46b535a0 Parents: ebe561f Author: Sergey Beryozkin <[email protected]> Authored: Wed Nov 5 11:18:11 2014 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Wed Nov 5 11:25:55 2014 +0000 ---------------------------------------------------------------------- .../apache/cxf/jaxrs/utils/AnnotationUtils.java | 83 +++++++++++--------- .../apache/cxf/jaxrs/utils/ResourceUtils.java | 5 +- .../jaxrs/utils/AnnotationTestUtilsTest.java | 4 +- .../apache/cxf/jaxrs/utils/JAXRSUtilsTest.java | 2 +- .../JAXRSClientServerProxySpringBookTest.java | 16 ++++ .../resources/jaxrs_proxy/WEB-INF/beans.xml | 3 +- 6 files changed, 72 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java index e902512..5d3cbf3 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java @@ -203,52 +203,65 @@ public final class AnnotationUtils { return null; } - public static Method getAnnotatedMethod(Method m) { - Method annotatedMethod = doGetAnnotatedMethod(m); + public static Method getAnnotatedMethod(Class<?> serviceClass, Method m) { + Method annotatedMethod = doGetAnnotatedMethod(serviceClass, m); return annotatedMethod == null ? m : annotatedMethod; } - private static Method doGetAnnotatedMethod(Method m) { + private static Method doGetAnnotatedMethod(Class<?> serviceClass, Method m) { - if (m == null) { - return m; - } - - for (Annotation a : m.getAnnotations()) { - if (AnnotationUtils.isMethodAnnotation(a)) { - return m; + if (m != null) { + for (Annotation a : m.getAnnotations()) { + if (AnnotationUtils.isMethodAnnotation(a)) { + return m; + } } - } - for (Annotation[] paramAnnotations : m.getParameterAnnotations()) { - if (isValidParamAnnotations(paramAnnotations)) { - LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName() - + " has no JAX-RS Path or HTTP Method annotations"); - return m; + for (Annotation[] paramAnnotations : m.getParameterAnnotations()) { + if (isValidParamAnnotations(paramAnnotations)) { + LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName() + + " has no JAX-RS Path or HTTP Method annotations"); + return m; + } } - } - - Class<?> superC = m.getDeclaringClass().getSuperclass(); - if (superC != null && Object.class != superC) { - try { - Method method = doGetAnnotatedMethod(superC.getMethod(m.getName(), m.getParameterTypes())); - if (method != null) { - return method; + + Class<?> declaringClass = m.getDeclaringClass(); + Class<?> superC = declaringClass.getSuperclass(); + if (superC != null && Object.class != superC) { + try { + Method method = doGetAnnotatedMethod(serviceClass, + superC.getMethod(m.getName(), m.getParameterTypes())); + if (method != null) { + return method; + } + } catch (NoSuchMethodException ex) { + // ignore } - } catch (NoSuchMethodException ex) { - // ignore } - } - for (Class<?> i : m.getDeclaringClass().getInterfaces()) { - try { - Method method = doGetAnnotatedMethod(i.getMethod(m.getName(), m.getParameterTypes())); - if (method != null) { - return method; + for (Class<?> i : declaringClass.getInterfaces()) { + try { + Method method = doGetAnnotatedMethod(serviceClass, + i.getMethod(m.getName(), m.getParameterTypes())); + if (method != null) { + return method; + } + } catch (NoSuchMethodException ex) { + // ignore } - } catch (NoSuchMethodException ex) { - // ignore + } + if (declaringClass != serviceClass && !declaringClass.isInterface()) { + for (Class<?> i : serviceClass.getInterfaces()) { + try { + Method method = doGetAnnotatedMethod(serviceClass, + i.getMethod(m.getName(), m.getParameterTypes())); + if (method != null) { + return method; + } + } catch (NoSuchMethodException ex) { + // ignore + } + } } } - return null; } http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java index 98a94cd..3c5cd10 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java @@ -273,9 +273,10 @@ public final class ResourceUtils { private static void evaluateResourceClass(ClassResourceInfo cri, boolean enableStatic) { MethodDispatcher md = new MethodDispatcher(); - for (Method m : cri.getServiceClass().getMethods()) { + Class<?> serviceClass = cri.getServiceClass(); + for (Method m : serviceClass.getMethods()) { - Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(m); + Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m); String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod); Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class); http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java index 35e17a1..c0daf3a 100644 --- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java +++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java @@ -42,7 +42,7 @@ public class AnnotationTestUtilsTest extends Assert { new Class[]{UriInfo.class}); assertEquals(0, m.getAnnotations().length); assertEquals(0, m.getParameterAnnotations()[0].length); - Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(m); + Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(Customer.class, m); assertNotSame(m, annotatedMethod); assertEquals(1, annotatedMethod.getParameterAnnotations()[0].length); } @@ -54,7 +54,7 @@ public class AnnotationTestUtilsTest extends Assert { Customer.class.getMethod("getContextResolver", new Class[]{}); assertEquals(0, m.getAnnotations().length); - Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(m); + Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(Customer.class, m); assertSame(m, annotatedMethod); } http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java index b707952..3311172 100644 --- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java +++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java @@ -1677,7 +1677,7 @@ public class JAXRSUtilsTest extends Assert { new Class[]{UriInfo.class}); OperationResourceInfo ori = new OperationResourceInfo(methodToInvoke, - AnnotationUtils.getAnnotatedMethod(methodToInvoke), cri); + AnnotationUtils.getAnnotatedMethod(Customer.class, methodToInvoke), cri); ori.setHttpMethod("GET"); Message m = new MessageImpl(); http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java index f933e6a..011a763 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java @@ -143,6 +143,22 @@ public class JAXRSClientServerProxySpringBookTest extends AbstractBusClientServe assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); } + @Test + public void testGetName() throws Exception { + String endpointAddress = "http://localhost:" + PORT + "/test/v1/names/1"; + WebClient wc = WebClient.create(endpointAddress); + wc.accept("application/json"); + String name = wc.get(String.class); + assertEquals("{\"name\":\"Barry\"}", name); + } + @Test + public void testPutName() throws Exception { + String endpointAddress = "http://localhost:" + PORT + "/test/v1/names/1"; + WebClient wc = WebClient.create(endpointAddress); + wc.type("application/json").accept("application/json"); + String id = wc.put(null, String.class); + assertEquals("1", id); + } @Test public void testGetBookWithRequestScope() { http://git-wip-us.apache.org/repos/asf/cxf/blob/9d671444/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml index 4ac3fc0..d67c9b2 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml @@ -24,6 +24,7 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"--> +<<<<<<< HEAD <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" @@ -53,6 +54,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> <jaxrs:serviceBeans> <ref bean="bookstore"/> <ref bean="bookstoreInterface"/> + <bean class="org.apache.cxf.systest.jaxrs.NameServiceImpl"/> </jaxrs:serviceBeans> <jaxrs:providers> <ref bean="exceptionMapper"/> @@ -136,7 +138,6 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> </aop:config> <bean id="simpleLogger" class="org.apache.cxf.systest.jaxrs.SimpleLoggingAspect"/> - </beans> <!-- END SNIPPET: beans -->
