How to get resource method matched to URI before Jersey invokes it?

后端 未结 4 1254
感动是毒
感动是毒 2020-12-08 15:35

I\'m trying to implement a ContainerRequestFilter that does custom validation of a request\'s parameters. I need to look up the resource method that will be matched to the U

4条回答
  •  甜味超标
    2020-12-08 16:27

    Actually, you should try to inject ResourceInfo into your custom request filter. I have tried it with RESTEasy and it works there. The advantage is that you code against the JSR interfaces and not the Jersey implementation.

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

提交回复
热议问题