Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Servlet Filter for Jersey / JAX-RS / REST resources?

In a regular Web Application, I can assign a chain of Filters to various paths for aspects such as Authentication, Authorization, Errors, Logging and more.

The advantage is that I write servlets to focus on core functionality without worrying about infrastructure aspects. I can write orthogonal, cross-cutting Filters to authenticate, authorize, etc. Then I can weave them in web.xml. Looking at 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?

like image 218
necromancer Avatar asked Jan 05 '12 06:01

necromancer


1 Answers

While not identical to servlet filters, Jersey supports ContainerResponseFilter and ContainerRequestFilter. These get called for all requests, so you have to do any URL matching in code.

The ResourceFilter was removed in Jersey 2.

like image 177
Jon Nichols Avatar answered Sep 28 '22 11:09

Jon Nichols