cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [1/2] git commit: [CXF-6078] Checking service class interfaces if one of its non-interface super classes has no expected JAX-RS annotated method
Date Wed, 05 Nov 2014 11:19:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/master b916b1b7a -> de0524a87


[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/30390cc7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/30390cc7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/30390cc7

Branch: refs/heads/master
Commit: 30390cc755f58eab3b346dc7b035e6286d6662b8
Parents: b916b1b
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Nov 5 11:18:11 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Nov 5 11:18:11 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   | 18 ++++-
 .../resources/jaxrs_proxy/WEB-INF/beans.xml     |  1 +
 6 files changed, 72 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/30390cc7/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 345fa7c..27f8caf 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
@@ -151,52 +151,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/30390cc7/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 52098aa..0cc88a0 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
@@ -274,9 +274,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/30390cc7/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/30390cc7/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 614a536..ac670b2 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
@@ -1675,7 +1675,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/30390cc7/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 7c2a809..7141218 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
@@ -68,7 +68,7 @@ public class JAXRSClientServerProxySpringBookTest extends AbstractBusClientServe
         List<Element> resourceEls = 
             DOMUtils.getChildrenWithName(resourcesEl, 
                                          WadlGenerator.WADL_NS, "resource");
-        assertEquals(2, resourceEls.size());
+        assertEquals(3, resourceEls.size());
     }
     
     @Test
@@ -170,6 +170,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/30390cc7/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 88c583e..49cad1a 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
@@ -37,6 +37,7 @@
         <jaxrs:serviceBeans>
             <ref bean="bookstore"/>
             <ref bean="bookstoreInterface"/>
+            <bean class="org.apache.cxf.systest.jaxrs.NameServiceImpl"/>
         </jaxrs:serviceBeans>
         <jaxrs:providers>
             <ref bean="exceptionMapper"/>


Mime
View raw message