Search code examples
jax-rsresteasyintrospection

How to get target method of a given JAX-RS request?


Is there a way to obtain the java.lang.reflect.Method of the method (which is annotated with @Path) which will be called for a given HttpServletRequest?

Here is my use case : I'm in a Java EE Filter and want to know if the method which will be invoked later is annotated with another specific annotations.

(I'm using RESTEasy 3.0.7)


Solution

  • It's easy if you can use a ContainerRequestFilter instead of a normal Servlet Filter.

    @Provider
    public class SomeFilter implements ContainerRequestFilter {
    
        @Context
        private ResourceInfo resourceInfo;
    
        @Override
        public void filter(ContainerRequestContext requestContext) throws IOException {
            Method method = resourceInfo.getResourceMethod();
        }
    
    }