开发者

What is a Jersey Filter?

I want to know basical开发者_开发百科ly 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?


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.

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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜