meisam
meisam

Reputation: 11836

What is a Jersey Filter?

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?

Upvotes: 23

Views: 18563

Answers (2)

Zeemee
Zeemee

Reputation: 10704

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.

Upvotes: 18

Eyal
Eyal

Reputation: 3513

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.

Upvotes: 22

Related Questions