Hi
On Wed, Mar 23, 2011 at 8:45 AM, Pratyush Chandra
<[email protected]>wrote:
> I tried using AuthenticationHandler extending RequestHandler...where i
> write
> authentication logic...
> but I donnot know how to access username in my service implementation
>
> So, I tried instead having a ServiceImpl class where I have a :
>
> @Context MessageContext mc;
>
> public void getInfo() {
> AuthorizationPolicy policy =
> (AuthorizationPolicy)mc.get(AuthorizationPolicy.class.getName());
> String userName = policy.getUserName();
> String password = policy.getPassword();
> logger.error(userName+" "+password);
> }
>
> public Response serviceMethod() {
> //do something
> getInfo();
> }
>
> I am able to access the username and password..
> My concern is whether MessageContext is set per service request and is
> value
> of MessageContext jumbled up with value of some other service call (or
> remains steady per request). In that case I will have to pass it as service
> function parameter.
>
>
>
> All @Context annotated fields are thread-safe. You can actually do the same
in the RequestHandler, but use a current Message instead of MessageContext;
contexts can also be injected in handlers...
Cheers, Sergey