3

I am trying to inject MessageContext in an Interceptor with the Phase as READ as follows

@Context
org.apache.cxf.jaxrs.ext.MessageContext.MessageContext messageContext;

But this is not getting initialized and remains null. Is it possible to inject org.apache.cxf.jaxrs.ext.MessageContext.MessageContext in Interceptor?

Thanks

Mike
  • 58,961
  • 76
  • 175
  • 221
user325643
  • 353
  • 1
  • 8
  • 20

1 Answers1

3

You might need to add <aop:scoped-proxy/> into the cxf configuration file:

<jaxrs:server id="example" address="/">
    <jaxrs:serviceBeans>
         <bean class="org.apache.cxf.systest.jaxrs.CustomerService">
              <aop:scoped-proxy />
         </bean>
    </jaxrs:serviceBeans>
</jaxrs:server>

Also you have to create a setter method for your messageContext (this should be in your service class - here it is "org.apache.cxf.systest.jaxrs.CustomerService"):

private MessageContext messageContext;

@Context
public void setMessageContext(MessageContext messageContext) {
    this.messageContext = messageContext;
}

Consider also this documentation link:
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring