Use a ContainerRequestFilter with a plain old servlet?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Use a ContainerRequestFilter with a plain old servlet?

terris
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use a ContainerRequestFilter with a plain old servlet?

Pavel Bucek-2
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.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Use a ContainerRequestFilter with a plain old servlet?

terris
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+[hidden email]]
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.
NAML
Loading...