You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Ryan Moquin <fr...@gmail.com> on 2007/11/13 17:38:29 UTC

ComponentContext for CXFSE

I was looking at the unit tests for the CXFSE component since I wanted
to get back to getting the ComponentContext from within a CXF service.
 I noticed that in the configuration for the context injection, there
is no declaration for anything regarding the ComponentContext.  The
actual test itself doesn't appear to do anything regarding the
ComponentContext either.  Do you just put a property like:

private ComponentContext context = null;

into your service, along with a setter and it will automatically be
set?  I tried this, but it didn't appear to work.  Is this how it's
meant to work?

Re: ComponentContext for CXFSE

Posted by Freeman Fang <fr...@iona.com>.
Hi Ryan,

Yes, you needn't do anything in your configuration file for the context 
injection.

Just put
private ComponentContext context;
and
public void setContext(ComponentContext context) { // it must be public 
setter
        this.context = context;
    }
in your pojo, you could get the context injection.

You can see the pojo
trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java

And the test
trunk/deployables/serviceengines/servicemix-cxf-se//src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java

Other comment inline
Best Regards

Freeman

Ryan Moquin wrote:
> I was looking at the unit tests for the CXFSE component since I wanted
> to get back to getting the ComponentContext from within a CXF service.
>  I noticed that in the configuration for the context injection, there
> is no declaration for anything regarding the ComponentContext.  The
> actual test itself doesn't appear to do anything regarding the
> ComponentContext either.  Do you just put a property like:
>   
I assume the test you mentioned here is CxfSeContextInjectionTest, 
actuallly it do test the ComponentContext injection here,
it invoke
public String greetMe(String me) {
of  pojo 
trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java
Which has ComponentContext injection, and this greetMe method
return "Hello " + me  + " " + context.getComponentName();

And in the test, we assert the return is  "Hello ffang 
servicemix-cxfse", in which "servicemix-cxfse" == 
context.getComponentName(), so you can see the ComponentContext get injected
> private ComponentContext context = null;
>
> into your service, along with a setter and it will automatically be
> set?  I tried this, but it didn't appear to work.  Is this how it's
> meant to work?
>
>