Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

https://issues.jboss.org/browse/JBPAPP-7871 #35

Closed
wants to merge 1 commit into from

2 participants

@liweinan
Collaborator

Section 3.3.1 of JAX-RS 1.1. standard:


3.3.1 Visibility
Only public methods may be exposed as resource methods. An implementation SHOULD warn users if a non-public method carries a method designator or @Path annotation.

@liweinan liweinan https://issues.jboss.org/browse/JBPAPP-7871
Section 3.3.1 of JAX-RS 1.1. standard:

<cite>
3.3.1 Visibility
Only public methods may be exposed as resource methods. An implementation SHOULD warn users if a non-public method carries a method designator or @Path annotation.
</cite>
8cb7e31
@patriot1burke
Collaborator

A better approach is just to check the visibility of the method via a simple reflection call instead of looking up the method

@liweinan
Collaborator

Thank you for your advice Bill :-) I'll work on this one after I've finished my work at hand.

@liweinan
Collaborator

Hi Bill, I've tried to use reflection to check method's reflection and seems it doesn't work:

public class Foo {

    private static class Bar {
        public void method1() {}
        private void method2() {}
        public static void method3() {}
    }
    public static void main(String[] args) throws NoSuchMethodException {
        System.out.println(Bar.class.getMethod("method1", null).isAccessible());
        System.out.println(Bar.class.getDeclaredMethod("method2", null).isAccessible());
        System.out.println(Bar.class.getDeclaredMethod("method3", null).isAccessible());
    }
}

Here is the output:

false
false
false

From the explanation in javadoc:

isAccessible() 
          Get the value of the accessible flag for this object.

Seem it just check the accessible flag no matter the method is public or not. Unless we setAccessible(true) it will always return false.

Maybe you are referring on alternative ways to check the non-public methods that I don't know. Could you please help on this one?

@patriot1burke
Collaborator

Use

java.lang.reflect.Modifer.isPublic(method.getModifiers()))

This is basic Java. Please do a little more research next time. Also, you need to patch 2.3 as well, i'll send you how to do that.

@liweinan
Collaborator

Thank you for help Bill :-) Next time I'll do more researches on the APIs I haven't used before.

@liweinan liweinan closed this
@liweinan liweinan deleted the liweinan:JBPAPP-7871-revised branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2012
  1. @liweinan

    https://issues.jboss.org/browse/JBPAPP-7871

    liweinan authored
    Section 3.3.1 of JAX-RS 1.1. standard:
    
    <cite>
    3.3.1 Visibility
    Only public methods may be exposed as resource methods. An implementation SHOULD warn users if a non-public method carries a method designator or @Path annotation.
    </cite>
This page is out of date. Refresh to see the latest.
View
21 jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java
@@ -1,15 +1,12 @@
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.GetRestful;
import org.jboss.resteasy.util.IsHttpMethod;
import org.jboss.resteasy.util.Types;
@@ -32,6 +29,8 @@
protected ResteasyProviderFactory providerFactory;
protected RootSegment rootSegment = new RootSegment();
+ private final static Logger logger = Logger.getLogger(ResourceMethodRegistry.class);
+
public ResourceMethodRegistry(ResteasyProviderFactory providerFactory)
{
this.providerFactory = providerFactory;
@@ -125,6 +124,18 @@ public void addResourceFactory(ResourceFactory ref, String base, Class<?> clazz)
processMethod(ref, base, clazz, method);
}
+
+ // https://issues.jboss.org/browse/JBPAPP-7871
+ for (Method method : clazz.getDeclaredMethods()) {
+ Method _method = findAnnotatedMethod(clazz, method);
+ if (_method != null) {
+ try {
+ clazz.getMethod(_method.getName(), _method.getParameterTypes());
+ } catch (NoSuchMethodException e) {
+ logger.warn("JAX-RS annotations found at non-public method: " + method.getDeclaringClass().getName() + "." + method.getName() + "(); Only public methods may be exposed as resource methods.");
+ }
+ }
+ }
}
private Method findAnnotatedInterfaceMethod(Class<?> root, Class<?> iface, Method implementation)
Something went wrong with that request. Please try again.