What is a Jersey Filter?

meisam picture meisam · May 3, 2011 · Viewed 16.5k times · Source

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?

Answer

Eyal picture Eyal · May 1, 2012

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.