You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Esteban Wagner <wa...@gmail.com> on 2013/01/17 18:05:51 UTC

@Context instantiation

Hi,

I am using Jax-RS I am not understading how the Message Context injection
works. I have looked at the documentation but its still not clear.

>From doing some tests I ve seen that the messageContext only get injected
when the resource lifecyle its configured as "prototype". Is this correct?
Can I get the message context injected using "singleton" scope?

Using the singleton scope I am able to get the MessageContext injected as a
method parameter, but not as a field. Is this Correct?

Many Thanks,

Service class was something like this:

@Path("/user")
*public class UserRestfulService { *

*
*

* private @Context MessageContext messageContext;*

*
*
*
         @GET
@Produces("application/json")
*

* public User getUser() {*

* *
                         messageContext.someMethod();

* }*
*
*
*
*
*
*

Re: @Context instantiation

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 17/01/13 23:41, Esteban Wagner wrote:
> Sergey thanks for the response.
>
> One more thing if you can clarify about @Context injection.
>
> If the service bean is configured as a SINGLETON, and I have a field of
> this service injected like this:
>
> private @Context MessageContext mc;
>
> How is that for example 2 concurrent calls to the same service will manage
> to have 2 different Message Contexts? If the underlying instance of the
> service will be the same (As its singleton)
>
Singletons have thread safe proxies injected, hence it is thread-safe
HTH, Sergey

> I am missing something here?
>
>
> Many Thanks,
>
>
>
>
> On Thu, Jan 17, 2013 at 9:39 PM, Sergey Beryozkin<sb...@gmail.com>wrote:
>
>> Hi
>>
>> On Thu, Jan 17, 2013 at 5:05 PM, Esteban Wagner
>> <wa...@gmail.com>  wrote:
>>> Hi,
>>>
>>> I am using Jax-RS I am not understading how the Message Context injection
>>> works. I have looked at the documentation but its still not clear.
>>>
>>>  From doing some tests I ve seen that the messageContext only get injected
>>> when the resource lifecyle its configured as "prototype". Is this
>> correct?
>>> Can I get the message context injected using "singleton" scope?
>>>
>>> Using the singleton scope I am able to get the MessageContext injected
>> as a
>>> method parameter, but not as a field. Is this Correct?
>>>
>> Sometimes the field-level injection due to Spring proxies hiding the
>> fields, but message-level injection usually works.
>> Have a look here please for more info:
>>
>> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring
>>
>> Cheers, Sergey
>>
>>> Many Thanks,
>>>
>>> Service class was something like this:
>>>
>>> @Path("/user")
>>> *public class UserRestfulService { *
>>>
>>> *
>>> *
>>>
>>> * private @Context MessageContext messageContext;*
>>>
>>> *
>>> *
>>> *
>>>           @GET
>>> @Produces("application/json")
>>> *
>>>
>>> * public User getUser() {*
>>>
>>> * *
>>>                           messageContext.someMethod();
>>>
>>> * }*
>>> *
>>> *
>>> *
>>> *
>>> *
>>> *
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> http://sberyozkin.blogspot.com
>> Talend - http://www.talend.com
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: @Context instantiation

Posted by Esteban Wagner <wa...@gmail.com>.
Sergey thanks for the response.

One more thing if you can clarify about @Context injection.

If the service bean is configured as a SINGLETON, and I have a field of
this service injected like this:

private @Context MessageContext mc;

How is that for example 2 concurrent calls to the same service will manage
to have 2 different Message Contexts? If the underlying instance of the
service will be the same (As its singleton)

I am missing something here?


Many Thanks,




On Thu, Jan 17, 2013 at 9:39 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> On Thu, Jan 17, 2013 at 5:05 PM, Esteban Wagner
> <wa...@gmail.com> wrote:
> > Hi,
> >
> > I am using Jax-RS I am not understading how the Message Context injection
> > works. I have looked at the documentation but its still not clear.
> >
> > From doing some tests I ve seen that the messageContext only get injected
> > when the resource lifecyle its configured as "prototype". Is this
> correct?
> > Can I get the message context injected using "singleton" scope?
> >
> > Using the singleton scope I am able to get the MessageContext injected
> as a
> > method parameter, but not as a field. Is this Correct?
> >
> Sometimes the field-level injection due to Spring proxies hiding the
> fields, but message-level injection usually works.
> Have a look here please for more info:
>
> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring
>
> Cheers, Sergey
>
> > Many Thanks,
> >
> > Service class was something like this:
> >
> > @Path("/user")
> > *public class UserRestfulService { *
> >
> > *
> > *
> >
> > * private @Context MessageContext messageContext;*
> >
> > *
> > *
> > *
> >          @GET
> > @Produces("application/json")
> > *
> >
> > * public User getUser() {*
> >
> > * *
> >                          messageContext.someMethod();
> >
> > * }*
> > *
> > *
> > *
> > *
> > *
> > *
>
>
>
> --
> Sergey Beryozkin
>
> http://sberyozkin.blogspot.com
> Talend - http://www.talend.com
>

Re: @Context instantiation

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Thu, Jan 17, 2013 at 5:05 PM, Esteban Wagner
<wa...@gmail.com> wrote:
> Hi,
>
> I am using Jax-RS I am not understading how the Message Context injection
> works. I have looked at the documentation but its still not clear.
>
> From doing some tests I ve seen that the messageContext only get injected
> when the resource lifecyle its configured as "prototype". Is this correct?
> Can I get the message context injected using "singleton" scope?
>
> Using the singleton scope I am able to get the MessageContext injected as a
> method parameter, but not as a field. Is this Correct?
>
Sometimes the field-level injection due to Spring proxies hiding the
fields, but message-level injection usually works.
Have a look here please for more info:
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring

Cheers, Sergey

> Many Thanks,
>
> Service class was something like this:
>
> @Path("/user")
> *public class UserRestfulService { *
>
> *
> *
>
> * private @Context MessageContext messageContext;*
>
> *
> *
> *
>          @GET
> @Produces("application/json")
> *
>
> * public User getUser() {*
>
> * *
>                          messageContext.someMethod();
>
> * }*
> *
> *
> *
> *
> *
> *



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com