Hi

On Thu, Mar 31, 2011 at 12:14 PM, Pratyush Chandra <[email protected]
> wrote:

> I can inject @Context in my service implementation and get say locale from
> http headers. I want to pass this information something like this :
>
>  serviceimpl -> managerimpl -> daoimpl
>
> I want locale to be available to managerimpl and daoimpl as well. Is their
> a
> way to pass this information to other layers apart from service impl,
> without passing it through function parameters. Something like
> servletcontext or global variables per request ?
>
>
>
Can serviceimpl, managerimpl and daoimpl all act as JAX-RS subresources ? In
principle, injecting contexts into subresources is possible, the problem is
that JAX-RS runtime does not know if a given subresource is a singleton or
created on every new request, so injecting thread-safe contexts can be
problematic. That said, it may be done, but with the help of the contextual
properties. For example, if a message property is set specifying that
subresources are singletons then the JAX-RS runtime will synchronize when
accessing a given subresources otherwise it will inject a given context
directly

Alternatively you can access a current message using this code:
PhaseInterceptorChain.getCurrentMessage() and then get HttpServletRequest
from it, using AbstractHttpDestination.HTTP_REQUEST property

Cheers, Sergey

Reply via email to