How does one intercept a request during the Jersey lifecycle?

I’ve found the answer.

First, create a class that implements ContainerRequestFilter. The interface specifies the following method, in which the filtering takes place. The ContainerRequest object contains information about the current request.

public ContainerRequest filter(ContainerRequest req);

After that, include the following XML in the servlet configuration in web.xml

<init-param>
  <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
  <param-value>path.to.filtering.class</param-value>
</init-param>

Sources:

http://jersey.576304.n2.nabble.com/ContainerRequestFilter-and-Resources-td4419975.html
http://markmail.org/message/p7yxygz4wpakqno5

Leave a Comment