users@jersey.java.net

[Jersey] Re: Jersey1 to Jersey2 upgrade: injecting _at_Context into CDI interceptor.

From: Pavel <pagrus_at_gmail.com>
Date: Mon, 12 Jan 2015 13:45:13 +0300

FWIW, for now I ended up adding a pair of
ContainerRequest/ContainerResponse filters which store
ContainerRequestContext in a ThreadLocal storage. And then a custom CDI
producer would produce request-scoped UriInfo, HttpHeaders, etc off that
TheadLocal storage, so these are injectable into pure CDI components with
@Inject.

On Fri, Jan 9, 2015 at 10:22 AM, Pavel <pagrus_at_gmail.com> wrote:

> While upgrading a Jersey1 + Weld 1.1 to Jersey2 + Weld 2.2 I faced one
> interesting difference:
>
>
>
> With Jersey1 it was possible to inject @Context fields into pure CDI
> components like interceptors.
>
> e.g.
>
>
>
> @Auth
>
> @Interceptor
>
> public class AuthInterceptor {
>
>
>
> @Context
>
> private UriInfo uriInfo;
>
>
>
> @Context
>
> private HttpServletRequest request;
>
>
>
> @Context
>
> private HttpHeaders headers;
>
>
>
> @AroundInvoke
>
> public Object process(final InvocationContext ctx) throws Exception {
>
> …
>
> }
>
> }
>
>
>
> With Jersey2 it looks like the @Context injection works fine for the
> resource classes, but not for interceptors.
>
>
>
> I have two questions here:
>
> 1. Is there an easy way to enable @Context injection on CDI
> interceptors with Jersey 2?
>
> 2. If not, is there a programmatic way of getting the "current"
> (thread-local?) http headers, request, etc?
>
>
> Thanks,
> Pavel
>



-- 
Best regards,
Pavel