Author: rmannibucau
Date: Thu Jul 26 07:06:21 2012
New Revision: 1365896

URL: http://svn.apache.org/viewvc?rev=1365896&view=rev
Log:
TOMEE-260 some more jaxrs validation

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckRestMethodArePublic.java
    
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckRestMethodArePublic.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckRestMethodArePublic.java?rev=1365896&r1=1365895&r2=1365896&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckRestMethodArePublic.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckRestMethodArePublic.java
 Thu Jul 26 07:06:21 2012
@@ -103,13 +103,28 @@ public class CheckRestMethodArePublic im
             return; // managed elsewhere
         }
 
+        int publicMethodNumber = 0;
+        int nonPublicMethods = 0;
         while (!Object.class.equals(clazz) && clazz != null) {
             for (Method mtd : clazz.getDeclaredMethods()) {
-                if (mtd.getAnnotation(Path.class) != null && 
!Modifier.isPublic(mtd.getModifiers())) {
-                    validation.warn(mtd.toGenericString(), 
"rest.method.visibility", "JAX-RS methods should be public");
+                boolean isPublic = Modifier.isPublic(mtd.getModifiers());
+                if (mtd.getAnnotation(Path.class) != null && !isPublic) {
+                    final String name = mtd.toGenericString();
+                    validation.warn(name, "rest.method.visibility", name);
+                }
+                if (isPublic) {
+                    publicMethodNumber++;
+                } else {
+                    nonPublicMethods++;
                 }
             }
             clazz = clazz.getSuperclass();
         }
+
+        if (publicMethodNumber == 0 && nonPublicMethods > 0) {
+            validation.warn(classname, "no.method.in.rest.class", classname);
+        } else if (publicMethodNumber == 0 && nonPublicMethods == 0) {
+            validation.warn(classname, "no.rest.resource.method", classname);
+        }
     }
 }

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1365896&r1=1365895&r2=1365896&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
 Thu Jul 26 07:06:21 2012
@@ -902,4 +902,12 @@ public interface {0} extends {2}'{}'
 
 1.rest.method.visibility = JAX-RS Method [{0}} should be public.
 2.rest.method.visibility = JAX-RS Method [{0}} should be public.
-3.rest.method.visibility = JAX-RS Method [{0}} should be public.
\ No newline at end of file
+3.rest.method.visibility = JAX-RS Method [{0}} should be public.
+
+1.no.method.in.rest.class = No method in REST class [{0}]
+2.no.method.in.rest.class = No method in REST class [{0}].
+3.no.method.in.rest.class = No method in REST class [{0}]. To make your 
service available ensure it contains at least one public method.
+
+1.no.rest.resource.method = No public method in REST class [{0}]
+2.no.rest.resource.method = No public method in REST class [{0}]. You should 
probably ensure your service gets at least one public method.
+3.no.rest.resource.method = No public method in REST class [{0}]. To make your 
service available ensure it contains at least one public method.


Reply via email to