Equivalent to servlet filter for Jersey / JAX-RS / REST resources?

In a regular web application, I can assign a filter chain to various paths for aspects such as authentication, authorization, errors, logging, etc.

The advantage is that I write servlets to focus on core functions without worrying about infrastructure aspects. I can write orthogonal, end-to-end filters for authentication, authorization, etc. Then I can bind them in web.xml. Viewing web.xml is enough to assure me that there are no holes in my application.

Is this possible in JAX-RS or Jersey? If not, what is my best bet?

+7
source share
1 answer

As long as it is not identical to servlet filters, Jersey supports ContainerResponseFilter and ContainerRequestFilter. These calls are called for all requests, so you need to execute any URL in the code.

ResourceFilter has been removed in Jersey 2.

+2
source

All Articles