Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 756
Anthony O. Avatar asked Jun 10 '14 15:06

Anthony O.


1 Answers

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();
    }

}
like image 137
lefloh Avatar answered Sep 18 '22 23:09

lefloh