users@jersey.java.net

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

From: terris <terri_at_sdsc.edu>
Date: Wed, 7 Sep 2016 18:03:47 -0700 (MST)

Thanks Pavel. Sounds like it might be simpler for me to create a separate filter for the servlet and refactor as much of the authentication code as possible into a class that the 2 filters share.

Terri
________________________________
From: Pavel Bucek-2 [via Jersey] [ml-node+s576304n7583866h53_at_n2.nabble.com]
Sent: Wednesday, September 07, 2016 1:57 PM
To: Schwartz, Terri
Subject: Re: Use a ContainerRequestFilter with a plain old servlet?

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.



________________________________
If you reply to this email, your message will be added to the discussion below:
http://jersey.576304.n2.nabble.com/Use-a-ContainerRequestFilter-with-a-plain-old-servlet-tp7583865p7583866.html
To unsubscribe from Use a ContainerRequestFilter with a plain old servlet?, click here<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7583865&code=dGVycmlAc2RzYy5lZHV8NzU4Mzg2NXwxNjM2NTMzODc=>.
NAML<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://jersey.576304.n2.nabble.com/Use-a-ContainerRequestFilter-with-a-plain-old-servlet-tp7583865p7583867.html
Sent from the Jersey mailing list archive at Nabble.com.