相当于Jersey / JAX-RS / REST资源的Servlet过滤器? [英] Equivalent of Servlet Filter for Jersey / JAX-RS / REST resources?

查看:132
本文介绍了相当于Jersey / JAX-RS / REST资源的Servlet过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在常规Web应用程序中,我可以为各种路径分配一系列过滤器,用于验证,授权,错误,记录等方面。

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.

优势是我编写servlet以专注于核心功能而不必担心基础架构方面。我可以编写正交,横切过滤器来进行身份验证,授权等。然后我可以在web.xml中编织它们。查看web.xml足以让我确信我的应用程序中没有漏洞。

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.

这在JAX-RS或Jersey中是否可行?如果没有,我最好的选择是什么?

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

推荐答案

虽然与servlet过滤器不同,但Jersey支持ContainerResponseFilter和ContainerRequestFilter。这些被称为所有请求,因此您必须在代码中进行任何URL匹配。

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.

在Jersey 2中删除了ResourceFilter。

The ResourceFilter was removed in Jersey 2.

这篇关于相当于Jersey / JAX-RS / REST资源的Servlet过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆