Anthony O.
Anthony O.

Reputation: 24297

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)

Upvotes: 6

Views: 2672

Answers (1)

lefloh
lefloh

Reputation: 10961

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

}

Upvotes: 10

Related Questions