You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kiren Pillay <ki...@gmail.com> on 2014/12/08 13:02:36 UTC

Inject MessageContext into Aspect

Hi

I need to inject the MessageContext into an Aspect that sits around my
Service. Is there maybe sample code that illustrates how to do this?

I've tried to inject the MessageContext into the Aspect but it comes out as
nul for some reason.

Regards
Kiren

Re: Inject MessageContext into Aspect

Posted by Kiren Pillay <ki...@gmail.com>.
I managed to get this working with scope prototype, as this was at my app
startup and there wasn't a web application thread in scope.:

<bean id="currentMessage" class="org.apache.cxf.phase.PhaseInterceptorChain"
        factory-method="getCurrentMessage" scope="prototype">
        <aop:scoped-proxy />
    </bean>

Thanks
Kiren

On Mon, Dec 8, 2014 at 2:21 PM, Kiren Pillay <ki...@gmail.com> wrote:

> Okay thanks Sergey.
>
> For reference for others I'm using the following aspect config.
>
>  <beans:bean id="currentMessage" class=
> "org.apache.cxf.phase.PhaseInterceptorChain" factory-method=
> "getCurrentMessage" scope="request"> <aop:scoped-proxy/> </beans:bean>
>
>
> On Mon, Dec 8, 2014 at 2:16 PM, Sergey Beryozkin <sb...@gmail.com>
> wrote:
>
>> Hi
>>
>> On 08/12/14 12:02, Kiren Pillay wrote:
>>
>>> Hi
>>>
>>> I need to inject the MessageContext into an Aspect that sits around my
>>> Service. Is there maybe sample code that illustrates how to do this?
>>>
>>> I've tried to inject the MessageContext into the Aspect but it comes out
>>> as
>>> nul for some reason.
>>>
>>>  this aspect code is not visible to CXF, so you'd need to get a current
>> message using PhaseInterceptorChain.getCurrentMessage() inside the
>> aspect code and use it to initialize a context
>>
>> Cheers, Sergey
>>
>>  Regards
>>> Kiren
>>>
>>>
>>
>

Re: Inject MessageContext into Aspect

Posted by Kiren Pillay <ki...@gmail.com>.
Okay thanks Sergey.

For reference for others I'm using the following aspect config.

 <beans:bean id="currentMessage" class=
"org.apache.cxf.phase.PhaseInterceptorChain" factory-method=
"getCurrentMessage" scope="request"> <aop:scoped-proxy/> </beans:bean>


On Mon, Dec 8, 2014 at 2:16 PM, Sergey Beryozkin <sb...@gmail.com>
wrote:

> Hi
>
> On 08/12/14 12:02, Kiren Pillay wrote:
>
>> Hi
>>
>> I need to inject the MessageContext into an Aspect that sits around my
>> Service. Is there maybe sample code that illustrates how to do this?
>>
>> I've tried to inject the MessageContext into the Aspect but it comes out
>> as
>> nul for some reason.
>>
>>  this aspect code is not visible to CXF, so you'd need to get a current
> message using PhaseInterceptorChain.getCurrentMessage() inside the aspect
> code and use it to initialize a context
>
> Cheers, Sergey
>
>  Regards
>> Kiren
>>
>>
>

Re: Inject MessageContext into Aspect

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 08/12/14 12:02, Kiren Pillay wrote:
> Hi
>
> I need to inject the MessageContext into an Aspect that sits around my
> Service. Is there maybe sample code that illustrates how to do this?
>
> I've tried to inject the MessageContext into the Aspect but it comes out as
> nul for some reason.
>
this aspect code is not visible to CXF, so you'd need to get a current 
message using PhaseInterceptorChain.getCurrentMessage() inside the 
aspect code and use it to initialize a context

Cheers, Sergey

> Regards
> Kiren
>