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

允我心安 提交于 2019-12-30 18:26:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8738366/equivalent-of-servlet-filter-for-jersey-jax-rs-rest-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!