You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Shashank Rachamalla <sh...@hexagrid.com> on 2011/05/13 12:01:05 UTC
Accessing MessageContext when spring AOP is enabled
Hi
I have been trying to get a reference to MessageContext through @Context
annotation. However, when spring AOP is enabled I see the following
exception being thrown. any clues ?
Caused by: java.lang.IllegalArgumentException: Can not set
org.apache.cxf.jaxrs.ext.MessageContext field
com.hexagrid.vxappstore.webservice.impl.AppstoreApplianceWebServiceImpl.mcto
$Proxy87
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at
sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
at java.lang.reflect.Field.set(Field.java:657)
at
org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:162)
at java.security.AccessController.doPrivileged(Native Method)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:158)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:815)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
... 44 more
I tried using a setter with @Context annotation but no luck.
--
Regards,
Shashank Rachamalla
Re: Accessing MessageContext when spring AOP is enabled
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 15/06/12 16:10, gigi2 wrote:
> Hi, Sergey,
>
> Thank you very much. I have that figured out. You are right. A setter should
> resolve the problem.
>
> But now I have run into another similar but different situation. Trying to
> autowire a jax-rs message object into my Spring AOP, here is how the message
> bean is defined in my config
>
> <bean id="currentMessage" class="org.apache.cxf.phase.PhaseInterceptorChain"
> factory-method="getCurrentMessage" scope="request">
> <aop:scoped-proxy/>
> </bean>
>
> my Spring AOP is of singleton scope. When I deploy, i got a
> IllegalArgumentException. I've added the RequestContextListener to my
> web.xml. Still the same.
>
Not sure why that is the case. But why would you want to do it if you
can now inject a jaxrs MessageContext ?
Cheers, Sergey
> May I have some hints? Very grateful for your kind helps
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p5709877.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Accessing MessageContext when spring AOP is enabled
Posted by gigi2 <gg...@gmail.com>.
Hi, Sergey,
Thank you very much. I have that figured out. You are right. A setter should
resolve the problem.
But now I have run into another similar but different situation. Trying to
autowire a jax-rs message object into my Spring AOP, here is how the message
bean is defined in my config
<bean id="currentMessage" class="org.apache.cxf.phase.PhaseInterceptorChain"
factory-method="getCurrentMessage" scope="request">
<aop:scoped-proxy/>
</bean>
my Spring AOP is of singleton scope. When I deploy, i got a
IllegalArgumentException. I've added the RequestContextListener to my
web.xml. Still the same.
May I have some hints? Very grateful for your kind helps
--
View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p5709877.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Accessing MessageContext when spring AOP is enabled
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 14/06/12 18:53, gigi2 wrote:
> Hi, Sergey,
>
> I am not using request scoped service end points. It is singleton scope. But
> still, after I wrap my resource class with a Spring AOP, the injected
> MessageContext is no longer accessible. is there a solution posted for that?
>
A number of users have asked about it, please check the archives,
usually it works with adding a setter and perhaps introducing an
interface. If you have test maven war project then I can have a look too
Thanks, Sergey
> Thanks a lot
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p5709820.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Accessing MessageContext when spring AOP is enabled
Posted by gigi2 <gg...@gmail.com>.
Hi, Sergey,
I am not using request scoped service end points. It is singleton scope. But
still, after I wrap my resource class with a Spring AOP, the injected
MessageContext is no longer accessible. is there a solution posted for that?
Thanks a lot
--
View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p5709820.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Accessing MessageContext when spring AOP is enabled
Posted by Sergey Beryozkin <sb...@gmail.com>.
I think all the users who have reported the issue have got it
resolved. The documented solution
works in CXF 2.4.1, in earlier versions please consider using
PhaseInterceptorChain.getCurrentMessage()...
Cheers, Sergey
> entire solution (including XML and code), in order that other users can
> quickly implement the fix?
>
> Thanks!
>
> Nick
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p4694331.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
http://sberyozkin.blogspot.com
Talend - http://www.talend.com
Re: Accessing MessageContext when spring AOP is enabled
Posted by bytesphere <ns...@bytesphere.com>.
I'm having the same exact problem as well. Could you be so kind to post your
entire solution (including XML and code), in order that other users can
quickly implement the fix?
Thanks!
Nick
--
View this message in context: http://cxf.547215.n5.nabble.com/Accessing-MessageContext-when-spring-AOP-is-enabled-tp4392702p4694331.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Accessing MessageContext when spring AOP is enabled
Posted by Shashank Rachamalla <sh...@hexagrid.com>.
Hi
you were right. I was working with request scope. I have made the necessary
changes and things work as expected now. Thanks a lot.
On Fri, May 13, 2011 at 5:01 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
> What bean scope you are using ?
> Is it "request" or "session" by any chance ?
>
> Please check this section as well:
>
>
> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring
>
> Cheers, Sergey
>
> On Fri, May 13, 2011 at 12:28 PM, Shashank Rachamalla
> <sh...@hexagrid.com> wrote:
> > Hi
> >
> > Thanks for replying. I have tried with a dedicated interface but no luck.
> I
> > see the following exception now:
> >
> > Caused by: javax.ws.rs.WebApplicationException
> > at
> >
> org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:390)
> > at
> >
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:255)
> > at
> >
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:810)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
> >
> >
> > On Fri, May 13, 2011 at 4:01 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
> >
> >> Hi - it has to be a setter and you need to have a dedicated interface
> >> with methods like
> >> setMessageContext which the root resource will implement, that should
> help
> >>
> >> Cheers, Sergey
> >>
> >> On Fri, May 13, 2011 at 11:01 AM, Shashank Rachamalla
> >> <sh...@hexagrid.com> wrote:
> >> > Hi
> >> >
> >> > I have been trying to get a reference to MessageContext through
> @Context
> >> > annotation. However, when spring AOP is enabled I see the following
> >> > exception being thrown. any clues ?
> >> >
> >> > Caused by: java.lang.IllegalArgumentException: Can not set
> >> > org.apache.cxf.jaxrs.ext.MessageContext field
> >> >
> >>
> com.hexagrid.vxappstore.webservice.impl.AppstoreApplianceWebServiceImpl.mcto
> >> > $Proxy87
> >> > at
> >> >
> >>
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
> >> > at
> >> >
> >>
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
> >> > at
> >> >
> >>
> sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
> >> > at
> >> >
> >>
> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
> >> > at java.lang.reflect.Field.set(Field.java:657)
> >> > at
> >> >
> org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:162)
> >> > at java.security.AccessController.doPrivileged(Native Method)
> >> > at
> >> >
> >>
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:158)
> >> > at
> >> >
> >>
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:815)
> >> > at
> >> >
> >>
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
> >> > at
> >> >
> >>
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
> >> > at
> >> >
> >>
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
> >> > ... 44 more
> >> >
> >> > I tried using a setter with @Context annotation but no luck.
> >> >
> >> > --
> >> > Regards,
> >> > Shashank Rachamalla
> >> >
> >>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> Application Integration Division of Talend
> >> http://sberyozkin.blogspot.com
> >>
> >
> >
> >
> > --
> > Regards,
> > Shashank Rachamalla
> >
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend
> http://sberyozkin.blogspot.com
>
--
Regards,
Shashank Rachamalla
Re: Accessing MessageContext when spring AOP is enabled
Posted by Sergey Beryozkin <sb...@gmail.com>.
What bean scope you are using ?
Is it "request" or "session" by any chance ?
Please check this section as well:
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring
Cheers, Sergey
On Fri, May 13, 2011 at 12:28 PM, Shashank Rachamalla
<sh...@hexagrid.com> wrote:
> Hi
>
> Thanks for replying. I have tried with a dedicated interface but no luck. I
> see the following exception now:
>
> Caused by: javax.ws.rs.WebApplicationException
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:390)
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:255)
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:810)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
>
>
> On Fri, May 13, 2011 at 4:01 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
>
>> Hi - it has to be a setter and you need to have a dedicated interface
>> with methods like
>> setMessageContext which the root resource will implement, that should help
>>
>> Cheers, Sergey
>>
>> On Fri, May 13, 2011 at 11:01 AM, Shashank Rachamalla
>> <sh...@hexagrid.com> wrote:
>> > Hi
>> >
>> > I have been trying to get a reference to MessageContext through @Context
>> > annotation. However, when spring AOP is enabled I see the following
>> > exception being thrown. any clues ?
>> >
>> > Caused by: java.lang.IllegalArgumentException: Can not set
>> > org.apache.cxf.jaxrs.ext.MessageContext field
>> >
>> com.hexagrid.vxappstore.webservice.impl.AppstoreApplianceWebServiceImpl.mcto
>> > $Proxy87
>> > at
>> >
>> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
>> > at
>> >
>> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
>> > at
>> >
>> sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
>> > at
>> >
>> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
>> > at java.lang.reflect.Field.set(Field.java:657)
>> > at
>> > org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:162)
>> > at java.security.AccessController.doPrivileged(Native Method)
>> > at
>> >
>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:158)
>> > at
>> >
>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:815)
>> > at
>> >
>> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
>> > at
>> >
>> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
>> > at
>> >
>> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
>> > ... 44 more
>> >
>> > I tried using a setter with @Context annotation but no luck.
>> >
>> > --
>> > Regards,
>> > Shashank Rachamalla
>> >
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Application Integration Division of Talend
>> http://sberyozkin.blogspot.com
>>
>
>
>
> --
> Regards,
> Shashank Rachamalla
>
--
Sergey Beryozkin
Application Integration Division of Talend
http://sberyozkin.blogspot.com
Re: Accessing MessageContext when spring AOP is enabled
Posted by Shashank Rachamalla <sh...@hexagrid.com>.
Hi
Thanks for replying. I have tried with a dedicated interface but no luck. I
see the following exception now:
Caused by: javax.ws.rs.WebApplicationException
at
org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:390)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:255)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:810)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
On Fri, May 13, 2011 at 4:01 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
> Hi - it has to be a setter and you need to have a dedicated interface
> with methods like
> setMessageContext which the root resource will implement, that should help
>
> Cheers, Sergey
>
> On Fri, May 13, 2011 at 11:01 AM, Shashank Rachamalla
> <sh...@hexagrid.com> wrote:
> > Hi
> >
> > I have been trying to get a reference to MessageContext through @Context
> > annotation. However, when spring AOP is enabled I see the following
> > exception being thrown. any clues ?
> >
> > Caused by: java.lang.IllegalArgumentException: Can not set
> > org.apache.cxf.jaxrs.ext.MessageContext field
> >
> com.hexagrid.vxappstore.webservice.impl.AppstoreApplianceWebServiceImpl.mcto
> > $Proxy87
> > at
> >
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
> > at
> >
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
> > at
> >
> sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
> > at
> >
> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
> > at java.lang.reflect.Field.set(Field.java:657)
> > at
> > org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:162)
> > at java.security.AccessController.doPrivileged(Native Method)
> > at
> >
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:158)
> > at
> >
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:815)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
> > at
> >
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
> > ... 44 more
> >
> > I tried using a setter with @Context annotation but no luck.
> >
> > --
> > Regards,
> > Shashank Rachamalla
> >
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend
> http://sberyozkin.blogspot.com
>
--
Regards,
Shashank Rachamalla
Re: Accessing MessageContext when spring AOP is enabled
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi - it has to be a setter and you need to have a dedicated interface
with methods like
setMessageContext which the root resource will implement, that should help
Cheers, Sergey
On Fri, May 13, 2011 at 11:01 AM, Shashank Rachamalla
<sh...@hexagrid.com> wrote:
> Hi
>
> I have been trying to get a reference to MessageContext through @Context
> annotation. However, when spring AOP is enabled I see the following
> exception being thrown. any clues ?
>
> Caused by: java.lang.IllegalArgumentException: Can not set
> org.apache.cxf.jaxrs.ext.MessageContext field
> com.hexagrid.vxappstore.webservice.impl.AppstoreApplianceWebServiceImpl.mcto
> $Proxy87
> at
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
> at
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
> at
> sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
> at
> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
> at java.lang.reflect.Field.set(Field.java:657)
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:162)
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:158)
> at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:815)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:324)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:350)
> at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:120)
> ... 44 more
>
> I tried using a setter with @Context annotation but no luck.
>
> --
> Regards,
> Shashank Rachamalla
>
--
Sergey Beryozkin
Application Integration Division of Talend
http://sberyozkin.blogspot.com