You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jeff Wang <je...@plutom.com> on 2012/04/02 23:43:33 UTC

proper way to inject Context objects?

I'm running CXF 2.5.2 with Spring 3.1.1

I declare my beans via

@Service
public class FooImpl implements IFooService {
}

inside FooImpl, @Autowired fields work just fine.  However, @Context
UriInfo gave me a IllegalArgumentException for trying to set a $Proxy
to a UriInfo.  I then added a <aop:aspectj-autoproxy
proxy-target-class="true"/> to my spring file.  This worked (I think)
but a @Context mc gave a null pointer exception when I try to access
it.  adding setters and moving the @Context annotation to the setters
did not help.  heck,

	@Context
	public void setMc(org.apache.cxf.jaxrs.ext.MessageContext mc) {
		System.out.println("***mc is set");
		this.mc = mc;
	}

did not result in the println being executed.

Finally, when I put the @Context MessageContext mc as a method
parameter, the injection works fine.  Am I doing anything that's
unexpected with regard to MessageContext?

thanks
Jeff

Re: proper way to inject Context objects?

Posted by Jeff Wang <je...@plutom.com>.
the injection worked with the setter of the full name.

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

thanks.

Jeff

On Tue, Apr 3, 2012 at 1:29 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi Jeff
>
> On 03/04/12 00:43, Jeff Wang wrote:
>>
>> I'm running CXF 2.5.2 with Spring 3.1.1
>>
>> I declare my beans via
>>
>> @Service
>> public class FooImpl implements IFooService {
>> }
>>
>> inside FooImpl, @Autowired fields work just fine.  However, @Context
>> UriInfo gave me a IllegalArgumentException for trying to set a $Proxy
>> to a UriInfo.  I then added a<aop:aspectj-autoproxy
>> proxy-target-class="true"/>  to my spring file.  This worked (I think)
>> but a @Context mc gave a null pointer exception when I try to access
>> it.  adding setters and moving the @Context annotation to the setters
>> did not help.  heck,
>>
>>        @Context
>>        public void setMc(org.apache.cxf.jaxrs.ext.MessageContext mc) {
>>                System.out.println("***mc is set");
>>                this.mc = mc;
>>        }
>>
>> did not result in the println being executed.
>>
>
> the part after 'set' in the method name must match the name of the context
> class, example,
>
> setMessageContext
> setUriInfo
> etc
>
>
> If the injection is still not working then it is only due to a fairly
> complex proxification involved so introducing a dedicated utility interface
> such as
>
> public interface Contexts {
> @Context
> void setMessageContext(MessageContext mc);
> }
>
> and having FooImpl implementing it should help
>
> Cheers, Sergey
>
>
>> Finally, when I put the @Context MessageContext mc as a method
>> parameter, the injection works fine.  Am I doing anything that's
>> unexpected with regard to MessageContext?
>>
>> thanks
>> Jeff
>
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com

Re: proper way to inject Context objects?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Jeff
On 03/04/12 00:43, Jeff Wang wrote:
> I'm running CXF 2.5.2 with Spring 3.1.1
>
> I declare my beans via
>
> @Service
> public class FooImpl implements IFooService {
> }
>
> inside FooImpl, @Autowired fields work just fine.  However, @Context
> UriInfo gave me a IllegalArgumentException for trying to set a $Proxy
> to a UriInfo.  I then added a<aop:aspectj-autoproxy
> proxy-target-class="true"/>  to my spring file.  This worked (I think)
> but a @Context mc gave a null pointer exception when I try to access
> it.  adding setters and moving the @Context annotation to the setters
> did not help.  heck,
>
> 	@Context
> 	public void setMc(org.apache.cxf.jaxrs.ext.MessageContext mc) {
> 		System.out.println("***mc is set");
> 		this.mc = mc;
> 	}
>
> did not result in the println being executed.
>

the part after 'set' in the method name must match the name of the 
context class, example,

setMessageContext
setUriInfo
etc


If the injection is still not working then it is only due to a fairly 
complex proxification involved so introducing a dedicated utility 
interface such as

public interface Contexts {
@Context
void setMessageContext(MessageContext mc);
}

and having FooImpl implementing it should help

Cheers, Sergey

> Finally, when I put the @Context MessageContext mc as a method
> parameter, the injection works fine.  Am I doing anything that's
> unexpected with regard to MessageContext?
>
> thanks
> Jeff


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com