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 2014/11/05 12:19:32 UTC

[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

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 <sb...@talend.com>
Authored: Wed Nov 5 11:18:11 2014 +0000
Committer: Sergey Beryozkin <sb...@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"/>


[2/2] git commit: [CXF-6078] Checking service class interfaces if one of its non-interface super classes has no expected JAX-RS annotated method

Posted by se...@apache.org.
[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/de0524a8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/de0524a8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/de0524a8

Branch: refs/heads/master
Commit: de0524a874be14a6bd5d9fac98a513169d7a4a7a
Parents: 30390cc
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Nov 5 11:19:04 2014 +0000
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Nov 5 11:19:04 2014 +0000

----------------------------------------------------------------------
 .../systest/jaxrs/AbstractNameServiceImpl.java  | 30 ++++++++++++++
 .../apache/cxf/systest/jaxrs/NameService.java   | 43 ++++++++++++++++++++
 .../cxf/systest/jaxrs/NameServiceImpl.java      | 31 ++++++++++++++
 3 files changed, 104 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/de0524a8/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractNameServiceImpl.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractNameServiceImpl.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractNameServiceImpl.java
new file mode 100644
index 0000000..a8d7c01
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractNameServiceImpl.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.ws.rs.core.Response;
+
+public abstract class AbstractNameServiceImpl {
+
+    public Response set(String id) {
+        return Response.ok(id).build();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/de0524a8/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameService.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameService.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameService.java
new file mode 100644
index 0000000..5302b90
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameService.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+@Path("/v1/names/")
+@Produces({ "application/xml", "application/json" })
+@Consumes({ "application/xml", "application/json" })
+public interface NameService {
+
+    @GET
+    @Path("/{id}")
+    Response get(@PathParam("id") String id);
+
+    @PUT
+    @Path("/{id}")
+    Response set(@PathParam("id") String id);
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/de0524a8/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameServiceImpl.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameServiceImpl.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameServiceImpl.java
new file mode 100644
index 0000000..6f3f087
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NameServiceImpl.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.ws.rs.core.Response;
+
+public class NameServiceImpl extends AbstractNameServiceImpl implements NameService {
+
+    @Override
+    public Response get(String id) {
+        return Response.ok("{\"name\":\"Barry\"}").build();
+    }
+
+}