Skip to content

Instantly share code, notes, and snippets.

@liweinan
Created February 27, 2012 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liweinan/1923743 to your computer and use it in GitHub Desktop.
Save liweinan/1923743 to your computer and use it in GitHub Desktop.
diff --git a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java
index 2106862..bf32ea0 100644
--- a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java
+++ b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java
@@ -1,20 +1,19 @@
package org.jboss.resteasy.core;
import org.jboss.resteasy.core.registry.RootSegment;
+import org.jboss.resteasy.logging.Logger;
import org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory;
import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory;
import org.jboss.resteasy.plugins.server.resourcefactory.SingletonResource;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.InjectorFactory;
-import org.jboss.resteasy.spi.Registry;
-import org.jboss.resteasy.spi.ResourceFactory;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.jboss.resteasy.spi.*;
+import org.jboss.resteasy.util.FindAnnotation;
import org.jboss.resteasy.util.GetRestful;
import org.jboss.resteasy.util.IsHttpMethod;
import org.jboss.resteasy.util.Types;
import javax.ws.rs.Path;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
@@ -27,6 +26,8 @@ import java.util.Set;
*/
public class ResourceMethodRegistry implements Registry
{
+ final static Logger logger = Logger.getLogger(ResourceMethodRegistry.class);
+
protected int size;
protected ResteasyProviderFactory providerFactory;
@@ -203,6 +204,19 @@ public class ResourceMethodRegistry implements Registry
Method method = findAnnotatedMethod(clazz, implementation);
if (method != null)
{
+
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ int notAnnotatedParamCount = 0;
+ for (Annotation[] paramAnnotation : paramAnnotations) {
+ if (FindAnnotation.findJaxRSAnnotations(paramAnnotation).length == 0) {
+ notAnnotatedParamCount++;
+ if (notAnnotatedParamCount > 1) {
+ logger.warn(implementation.getDeclaringClass().getName() + "." + implementation.getName() + "(): Resource methods MUST NOT have more than one parameter that is not annotated with one of the JAX-RS Annotations.");
+ return;
+ }
+ }
+ }
+
Path path = method.getAnnotation(Path.class);
Set<String> httpMethods = IsHttpMethod.getHttpMethods(method);
diff --git a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/util/FindAnnotation.java b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/util/FindAnnotation.java
index 3442cbf..1f67761 100644
--- a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/util/FindAnnotation.java
+++ b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/util/FindAnnotation.java
@@ -1,10 +1,6 @@
package org.jboss.resteasy.util;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
@@ -30,7 +26,8 @@ public final class FindAnnotation
CookieParam.class,
PathParam.class,
MatrixParam.class,
- Context.class
+ Context.class,
+ FormParam.class
};
private static final Class[] findJaxRSAnnotations_TYPE = new Class[]{};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment