users@jax-rs-spec.java.net

[jax-rs-spec users] Re: custom _at_Context injection

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Wed, 17 Dec 2014 14:21:41 +0000

On 17/12/14 14:15, Bill Burke wrote:
> Currently there is no way to pass information from a filter to a
> resource. It would be cool if there was a method on
> ContainerRequestContext (or something) that could register a value that
> could be injected via @Context. For example:
>
> containerRequestContext.pushContext(IDToken.class, token);
>
>
> @Path
> public class Resource {
> @Context IDToken token;
> }
>
Sounds good
> I wish I had suggested this in JAX-RS 2.0 :( as I use this pattern with
> a proprietary API all the time. I can't believe I forgot to suggest it!
>
>
> Also, it might be interesting to allow injection of the
> ContainerRequestContext instance into resource classes as well:
>
> @Path
> public class Resource {
>
> @Context ContainerRequestContext context;
>
> }
>
> Not sure about this one. The reasoning would be to add/extract property
> metadata from the context. Haven't had a need for this one yet.
I've had users asking about it and had to recommend injecting
HttpServletRequest/Response which is not cool.
ContainerRequestContext has too many properties which are not relevant
in scope of the application code; updating Request and ResponseBuilder
interfaces might be a bit cleaner

Thanks, Sergey

>
>
>
>