cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6943] Ignoring invalid AsyncResponse resource methods
Date Tue, 21 Jun 2016 11:19:54 GMT
Repository: cxf
Updated Branches:
  refs/heads/master e4ed06328 -> 574322687


[CXF-6943] Ignoring invalid AsyncResponse resource methods


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/57432268
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/57432268
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/57432268

Branch: refs/heads/master
Commit: 5743226879b65f900b9f1d11df6367aec1add972
Parents: e4ed063
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Jun 21 12:19:35 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Jun 21 12:19:35 2016 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  4 +-
 .../apache/cxf/jaxrs/utils/Messages.properties  |  2 +
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 44 +++++++++++++++++---
 3 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/57432268/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 4a8d761..4ffc16d 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -60,7 +60,6 @@ import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.container.ResourceInfo;
-import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Cookie;
@@ -811,8 +810,7 @@ public final class JAXRSUtils {
 
         if (parameter.getType() == ParameterType.REQUEST_BODY) {
             
-            if (parameterClass == AsyncResponse.class 
-                && AnnotationUtils.getAnnotation(parameterAnns, Suspended.class)
!= null) {
+            if (parameterClass == AsyncResponse.class) {
                 return new AsyncResponseImpl(message);
             }
             

http://git-wip-us.apache.org/repos/asf/cxf/blob/57432268/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
index d7f181b..9b998ab 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
@@ -21,6 +21,8 @@
 NO_SERVLET_API=No Java Servlet API is available on the runtime classpath
 NO_RESOURCE_OP_EXC=No resource methods have been found for resource class {0}
 NOT_RESOURCE_METHOD={0}#{1} method is not a valid JAX-RS method as it has no Path and HttpMethod
annotations
+NOT_SUSPENDED_ASYNC_METHOD={0}#{1} method is not a valid JAX-RS AsyncResponse method as it
has no Suspended annotation
+NO_VOID_RETURN_ASYNC_METHOD={0}#{1} method is not a valid JAX-RS AsyncResponse method as
it has a non-void response type
 GET_INSTEAD_OF_HEAD=Resource class {0} does not support HEAD http method, method {1} supporting
GET http method will be invoked
 NO_CONTENT_TYPE_SPECIFIED=No Content-Type specified for HTTP {0}
 METHOD_INJECTION_FAILURE=Method {0} injection failure

http://git-wip-us.apache.org/repos/asf/cxf/blob/57432268/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 92fdf1a..2125869 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
@@ -55,6 +55,8 @@ import javax.ws.rs.MatrixParam;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
@@ -106,6 +108,9 @@ public final class ResourceUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(ResourceUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ResourceUtils.class);
     private static final String CLASSPATH_PREFIX = "classpath:";
+    private static final String NOT_RESOURCE_METHOD_MESSAGE_ID = "NOT_RESOURCE_METHOD";
+    private static final String NOT_SUSPENDED_ASYNC_MESSAGE_ID = "NOT_SUSPENDED_ASYNC_METHOD";
+    private static final String NO_VOID_RETURN_ASYNC_MESSAGE_ID = "NO_VOID_RETURN_ASYNC_METHOD";
     private static final Set<String> SERVER_PROVIDER_CLASS_NAMES;
     static {
         SERVER_PROVIDER_CLASS_NAMES = new HashSet<String>();
@@ -293,7 +298,6 @@ public final class ResourceUtils {
         MethodDispatcher md = new MethodDispatcher();
         Class<?> serviceClass = cri.getServiceClass();
         
-        boolean isFineLevelLoggable = LOG.isLoggable(Level.FINE);
         for (Method m : serviceClass.getMethods()) {
             
             Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m);
@@ -302,6 +306,10 @@ public final class ResourceUtils {
             Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
             
             if (httpMethod != null || path != null) {
+                if (!checkAsyncResponse(m)) {
+                    continue;
+                }
+                
                 md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m);
                 if (httpMethod == null) {
                     // subresource locator
@@ -320,16 +328,40 @@ public final class ResourceUtils {
                         }
                     }
                 }
-            } else if (isFineLevelLoggable) {
-                LOG.fine(new org.apache.cxf.common.i18n.Message("NOT_RESOURCE_METHOD", 
-                                                                 BUNDLE, 
-                                                                 m.getDeclaringClass().getName(),
-                                                                 m.getName()).toString());
+            } else {
+                reportInvalidResourceMethod(m, NOT_RESOURCE_METHOD_MESSAGE_ID);
             }
         }
         cri.setMethodDispatcher(md);
     }
     
+    private static void reportInvalidResourceMethod(Method m, String messageId) {
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine(new org.apache.cxf.common.i18n.Message(messageId, 
+                                                             BUNDLE, 
+                                                             m.getDeclaringClass().getName(),
+                                                             m.getName()).toString());
+        }
+        
+    }
+    private static boolean checkAsyncResponse(Method m) {
+        Class<?>[] types = m.getParameterTypes();
+        for (int i = 0; i < types.length; i++) {
+            if (types[i] == AsyncResponse.class) { 
+                if (AnnotationUtils.getAnnotation(m.getParameterAnnotations()[i], Suspended.class)
== null) {
+                    reportInvalidResourceMethod(m, NOT_SUSPENDED_ASYNC_MESSAGE_ID);
+                    return false;
+                }
+                if (m.getReturnType() == Void.TYPE || m.getReturnType() == Void.class) {
+                    return true;
+                } else {
+                    reportInvalidResourceMethod(m, NO_VOID_RETURN_ASYNC_MESSAGE_ID);
+                    return false;
+                }
+            }    
+        }
+        return true;
+    }
     private static ClassResourceInfo getAncestorWithSameServiceClass(ClassResourceInfo parent,
Class<?> subClass) {
         if (parent == null) {
             return null;


Mime
View raw message