users@jersey.java.net

[Jersey] Re: Use a ContainerRequestFilter with a plain old servlet?

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 7 Sep 2016 23:00:49 +0200

Hi Terri,

there is no simple way how to do that without involving Jersey, also it
doesn't really make sense.

What you could do is to register Jersey as a Servlet Filter and do
implement your filter there, as pre-matching. Then don't add any
resource into the filter (you might need to add a fake one, maybe there
is a condition that the Application cannot be empty - I'm not sure now,
you'll need to test it by yourself.

Then make sure that FILTER_FORWARD_ON_404 [1] is set to true. Your
pre-matching filter will be invoked, but all "passing" invocations of
the stack should result in 404, which would let Servlet impl continue
with another item on the process chain (that would be your JAX-RS-less
Servlet).

Hope it helps,
Pavel

[1]
https://jersey.java.net/apidocs/2.23/jersey/org/glassfish/jersey/servlet/ServletProperties.html#FILTER_FORWARD_ON_404

On 07/09/16 18:17, terris wrote:
> I have a Jersey 2.x rest service and a ContainerRequestFilter doing custom
> authentication. I have another servlet (not implemented with Jersey/jax-rs)
> that I recently added to the web application, at a different base url than
> the one that jersey is handling, and I would like to use the same
> authentication for the endpoints in this servlet. How can I use a Jersey
> ContainerRequestFilter with a plain old servlet ?
>
> Terri
>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Use-a-ContainerRequestFilter-with-a-plain-old-servlet-tp7583865.html
> Sent from the Jersey mailing list archive at Nabble.com.