java 什么是泽西过滤器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5865922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:11:59  来源:igfitidea点击:

What is a Jersey Filter?

javaweb-servicesjerseyservlet-filters

提问by meisam

I want to know basically what a Jersey filter is and how is it related to a servlet filter? Are they the same? What are the main patterns of using a Jersey Filter?

我想基本上知道 Jersey 过滤器是什么以及它与 servlet 过滤器有什么关系?他们是一样的吗?使用泽西过滤器的主要模式是什么?

采纳答案by Zeemee

The first part of your question may be answered in the Jersey documentation. A Jersey filter is not the same as a servlet filter. There are two filters included in Jersey, a filter for logging requests and one for compression (GZip). Another use case for a custom filter would be authentication or authorization.

您的问题的第一部分可能会在Jersey 文档中得到解答。Jersey 过滤器与 servlet 过滤器不同。Jersey 中包含两个过滤器,一个用于记录请求的过滤器,一个用于压缩 (GZip)。自定义过滤器的另一个用例是身份验证或授权。

回答by Eyal

Technically, a Jersey filter is not a servlet filter. However, you can use a Jersey filter for many of the same things that you would use a servlet filter for - cross-cutting concerns that affect all (or some, or most) the services that Jersey exposes.

从技术上讲,Jersey 过滤器不是 servlet 过滤器。但是,您可以将 Jersey 过滤器用于许多与使用 servlet 过滤器相同的事情 - 影响 Jersey 公开的所有(或部分或大部分)服务的横切关注点。

As the previous answer states, Jersey comes with two filters, but you can usefully implement the Jersey interfaces ContainerRequestFilteror/and ContainerResponseFilterif you don't want to extend them. You're not limited to these two.

正如前面的答案所述,Jersey 带有两个过滤器,但您可以有效地实现 Jersey 接口ContainerRequestFilter或/和ContainerResponseFilter如果您不想扩展它们。你不仅限于这两个。

Another Jersey interface to keep in mind is ResourceFilter- this interface can be implemented for a filter that affects only some of the services.

要记住的另一个 Jersey 接口是ResourceFilter- 可以为仅影响某些服务的过滤器实现此接口。