You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by navigator09 <ga...@gmail.com> on 2009/04/09 17:07:53 UTC

How to access ComponentContext inside servicemix-camel

Hi,

I am trying to access ComponentContext inside servicemix-camel. I tried the
following two approaches 

1. created the following property inside the class which implements the
route builder

 private javax.jbi.component.ComponentContext context;

   public void setContext(ComponentContext context) {
		this.context = context;
	}
 Expecting the dependency to be injected into the class extending the route
builder as suggested by some forums. But it did not work.

 2. I tried the following configuration with the xbean.xml of the camel 

 <bean id="JobPollerService" class="poller.service.JobPollerService">
     <property name="servicemixclient" ref="client" /> 
  </bean>
  
  <bean id="client"
class="org.apache.servicemix.client.DefaultServiceMixClient">
     <constructor-arg ref="jbi" />
  </bean>

and in the camel router I implemented the following method

public static DefaultServiceMixClient client;
	public void setContext(DefaultServiceMixClient client) {
		log.debug("Injecting component context");
		this.client= client;
	}

here it failed to create the bean client saying that the constructor is
incorrect. what is the right way to access ComponentContext or to create
servicemixclient inside the servicemix-camel component.

Regards,
Ganesh
-- 
View this message in context: http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22972903.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: How to access ComponentContext inside servicemix-camel

Posted by navigator09 <ga...@gmail.com>.
Gert,

  I used the producer templete to send messages into the nmr. Thank you.

  For others, the code goes as follows

   ProducerTemplate template =
exchange.getContext().createProducerTemplate();
   template.sendBody("direct:jmsroute", "<response>job
response</response>");

  

  in the route the following routes were added

    from("direct:jmsroute")
	
.to("jbi:endpoint:http://www.jobsubmission/service/esi-india/jms/provider");


   This is how one can access NMR within servicemix-camel without using
servicemixclient.

Regards,
Ganesh
 

Gert Vanthienen wrote:
> 
> Ganesh,
> 
> Ok, so it looks like the syntax without the # comes closer to what we
> want.  Could you try adding a type or index as is indicated by the
> error message there?
> (cfr.
> http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-ctor-arguments-type
> -- § 3.3.2.1 and § 3.3.2.2)
> 
> As a workaround, I still think you can use the secondary route as I
> mentioned in my previous post.  Instead of using the ServiceMix client
> in the loop to send messages to the NMR directly, you could just grab
> a Camel ProducerTemplate to send Camel messages to the direct endpoint
> and let that take care of interacting with the NMR.
> 
> Regards,
> 
> Gert Vanthienen
> ------------------------
> Open Source SOA: http://fusesource.com
> Blog: http://gertvanthienen.blogspot.com/
> 
> 
> 
> 2009/4/10 navigator09 <ga...@gmail.com>:
>>
>> Hi Gert,
>>
>>   I tried injecting dependency using #jbi. This also fails with the stack
>> trace mentioned in servicemix_#jbi.log attached to the mail.
>>
>>  The stack trace caused by dependency injection using 'jbi' is available
>> in
>> servicemix_jbi.log .
>>
>>  In servicemix 3.2.2. the camel routes dont have the looping based on a
>> condition ( like for loops) capability. This logic has been added inside
>> a
>> processor. The logic requires access to nmr based on certain status. So I
>> am
>> using servicemixclient for the purpose.
>>
>> Regards,
>> Ganesh http://www.nabble.com/file/p22984089/servicemix_jbi.log
>> servicemix_jbi.log
>> http://www.nabble.com/file/p22984089/servicemix_%2523jbi.log
>> servicemix_%23jbi.log
>>
>>
>>
>> Gert Vanthienen wrote:
>>>
>>> Ganesh,
>>>
>>> Injecting the client the way you are doing should work.  The only
>>> thing I can think of: could you try with #jbi instead of jbi in the
>>> client declaration?  If that still doesn't work, could you post us the
>>> stacktrace that you're seeing?
>>>
>>> Second question though: why do you want to inject a ServiceMix client
>>> in there?  If you want to access another service, wouldn't it be much
>>> easier to just create a second route in your Camel routebuilder
>>> (from("direct:b").to("jbi:endpoint:...") and then send a Camel
>>> exchange to the "direct:b" endpoint?
>>>
>>> Regards,
>>>
>>> Gert Vanthienen
>>> ------------------------
>>> Open Source SOA: http://fusesource.com
>>> Blog: http://gertvanthienen.blogspot.com/
>>>
>>>
>>>
>>> 2009/4/9 navigator09 <ga...@gmail.com>:
>>>>
>>>> Hi,
>>>>
>>>> I am trying to access ComponentContext inside servicemix-camel. I tried
>>>> the
>>>> following two approaches
>>>>
>>>> 1. created the following property inside the class which implements the
>>>> route builder
>>>>
>>>>  private javax.jbi.component.ComponentContext context;
>>>>
>>>>   public void setContext(ComponentContext context) {
>>>>                this.context = context;
>>>>        }
>>>>  Expecting the dependency to be injected into the class extending the
>>>> route
>>>> builder as suggested by some forums. But it did not work.
>>>>
>>>>  2. I tried the following configuration with the xbean.xml of the camel
>>>>
>>>>  <bean id="JobPollerService" class="poller.service.JobPollerService">
>>>>     <property name="servicemixclient" ref="client" />
>>>>  </bean>
>>>>
>>>>  <bean id="client"
>>>> class="org.apache.servicemix.client.DefaultServiceMixClient">
>>>>     <constructor-arg ref="jbi" />
>>>>  </bean>
>>>>
>>>> and in the camel router I implemented the following method
>>>>
>>>> public static DefaultServiceMixClient client;
>>>>        public void setContext(DefaultServiceMixClient client) {
>>>>                log.debug("Injecting component context");
>>>>                this.client= client;
>>>>        }
>>>>
>>>> here it failed to create the bean client saying that the constructor is
>>>> incorrect. what is the right way to access ComponentContext or to
>>>> create
>>>> servicemixclient inside the servicemix-camel component.
>>>>
>>>> Regards,
>>>> Ganesh
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22972903.html
>>>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>> -----
>>> ---
>>> Gert Vanthienen
>>> http://gertvanthienen.blogspot.com
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22984089.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -----
> ---
> Gert Vanthienen
> http://gertvanthienen.blogspot.com
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p23018362.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: How to access ComponentContext inside servicemix-camel

Posted by Gert Vanthienen <ge...@gmail.com>.
Ganesh,

Ok, so it looks like the syntax without the # comes closer to what we
want.  Could you try adding a type or index as is indicated by the
error message there?
(cfr. http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-ctor-arguments-type
-- § 3.3.2.1 and § 3.3.2.2)

As a workaround, I still think you can use the secondary route as I
mentioned in my previous post.  Instead of using the ServiceMix client
in the loop to send messages to the NMR directly, you could just grab
a Camel ProducerTemplate to send Camel messages to the direct endpoint
and let that take care of interacting with the NMR.

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/4/10 navigator09 <ga...@gmail.com>:
>
> Hi Gert,
>
>   I tried injecting dependency using #jbi. This also fails with the stack
> trace mentioned in servicemix_#jbi.log attached to the mail.
>
>  The stack trace caused by dependency injection using 'jbi' is available in
> servicemix_jbi.log .
>
>  In servicemix 3.2.2. the camel routes dont have the looping based on a
> condition ( like for loops) capability. This logic has been added inside a
> processor. The logic requires access to nmr based on certain status. So I am
> using servicemixclient for the purpose.
>
> Regards,
> Ganesh http://www.nabble.com/file/p22984089/servicemix_jbi.log
> servicemix_jbi.log
> http://www.nabble.com/file/p22984089/servicemix_%2523jbi.log
> servicemix_%23jbi.log
>
>
>
> Gert Vanthienen wrote:
>>
>> Ganesh,
>>
>> Injecting the client the way you are doing should work.  The only
>> thing I can think of: could you try with #jbi instead of jbi in the
>> client declaration?  If that still doesn't work, could you post us the
>> stacktrace that you're seeing?
>>
>> Second question though: why do you want to inject a ServiceMix client
>> in there?  If you want to access another service, wouldn't it be much
>> easier to just create a second route in your Camel routebuilder
>> (from("direct:b").to("jbi:endpoint:...") and then send a Camel
>> exchange to the "direct:b" endpoint?
>>
>> Regards,
>>
>> Gert Vanthienen
>> ------------------------
>> Open Source SOA: http://fusesource.com
>> Blog: http://gertvanthienen.blogspot.com/
>>
>>
>>
>> 2009/4/9 navigator09 <ga...@gmail.com>:
>>>
>>> Hi,
>>>
>>> I am trying to access ComponentContext inside servicemix-camel. I tried
>>> the
>>> following two approaches
>>>
>>> 1. created the following property inside the class which implements the
>>> route builder
>>>
>>>  private javax.jbi.component.ComponentContext context;
>>>
>>>   public void setContext(ComponentContext context) {
>>>                this.context = context;
>>>        }
>>>  Expecting the dependency to be injected into the class extending the
>>> route
>>> builder as suggested by some forums. But it did not work.
>>>
>>>  2. I tried the following configuration with the xbean.xml of the camel
>>>
>>>  <bean id="JobPollerService" class="poller.service.JobPollerService">
>>>     <property name="servicemixclient" ref="client" />
>>>  </bean>
>>>
>>>  <bean id="client"
>>> class="org.apache.servicemix.client.DefaultServiceMixClient">
>>>     <constructor-arg ref="jbi" />
>>>  </bean>
>>>
>>> and in the camel router I implemented the following method
>>>
>>> public static DefaultServiceMixClient client;
>>>        public void setContext(DefaultServiceMixClient client) {
>>>                log.debug("Injecting component context");
>>>                this.client= client;
>>>        }
>>>
>>> here it failed to create the bean client saying that the constructor is
>>> incorrect. what is the right way to access ComponentContext or to create
>>> servicemixclient inside the servicemix-camel component.
>>>
>>> Regards,
>>> Ganesh
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22972903.html
>>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>> -----
>> ---
>> Gert Vanthienen
>> http://gertvanthienen.blogspot.com
>>
>
> --
> View this message in context: http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22984089.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: How to access ComponentContext inside servicemix-camel

Posted by navigator09 <ga...@gmail.com>.
Hi Gert,

   I tried injecting dependency using #jbi. This also fails with the stack
trace mentioned in servicemix_#jbi.log attached to the mail. 

  The stack trace caused by dependency injection using 'jbi' is available in
servicemix_jbi.log .

  In servicemix 3.2.2. the camel routes dont have the looping based on a
condition ( like for loops) capability. This logic has been added inside a
processor. The logic requires access to nmr based on certain status. So I am
using servicemixclient for the purpose.

Regards,
Ganesh http://www.nabble.com/file/p22984089/servicemix_jbi.log
servicemix_jbi.log 
http://www.nabble.com/file/p22984089/servicemix_%2523jbi.log
servicemix_%23jbi.log 

  

Gert Vanthienen wrote:
> 
> Ganesh,
> 
> Injecting the client the way you are doing should work.  The only
> thing I can think of: could you try with #jbi instead of jbi in the
> client declaration?  If that still doesn't work, could you post us the
> stacktrace that you're seeing?
> 
> Second question though: why do you want to inject a ServiceMix client
> in there?  If you want to access another service, wouldn't it be much
> easier to just create a second route in your Camel routebuilder
> (from("direct:b").to("jbi:endpoint:...") and then send a Camel
> exchange to the "direct:b" endpoint?
> 
> Regards,
> 
> Gert Vanthienen
> ------------------------
> Open Source SOA: http://fusesource.com
> Blog: http://gertvanthienen.blogspot.com/
> 
> 
> 
> 2009/4/9 navigator09 <ga...@gmail.com>:
>>
>> Hi,
>>
>> I am trying to access ComponentContext inside servicemix-camel. I tried
>> the
>> following two approaches
>>
>> 1. created the following property inside the class which implements the
>> route builder
>>
>>  private javax.jbi.component.ComponentContext context;
>>
>>   public void setContext(ComponentContext context) {
>>                this.context = context;
>>        }
>>  Expecting the dependency to be injected into the class extending the
>> route
>> builder as suggested by some forums. But it did not work.
>>
>>  2. I tried the following configuration with the xbean.xml of the camel
>>
>>  <bean id="JobPollerService" class="poller.service.JobPollerService">
>>     <property name="servicemixclient" ref="client" />
>>  </bean>
>>
>>  <bean id="client"
>> class="org.apache.servicemix.client.DefaultServiceMixClient">
>>     <constructor-arg ref="jbi" />
>>  </bean>
>>
>> and in the camel router I implemented the following method
>>
>> public static DefaultServiceMixClient client;
>>        public void setContext(DefaultServiceMixClient client) {
>>                log.debug("Injecting component context");
>>                this.client= client;
>>        }
>>
>> here it failed to create the bean client saying that the constructor is
>> incorrect. what is the right way to access ComponentContext or to create
>> servicemixclient inside the servicemix-camel component.
>>
>> Regards,
>> Ganesh
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22972903.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -----
> ---
> Gert Vanthienen
> http://gertvanthienen.blogspot.com
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22984089.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: How to access ComponentContext inside servicemix-camel

Posted by Gert Vanthienen <ge...@gmail.com>.
Ganesh,

Injecting the client the way you are doing should work.  The only
thing I can think of: could you try with #jbi instead of jbi in the
client declaration?  If that still doesn't work, could you post us the
stacktrace that you're seeing?

Second question though: why do you want to inject a ServiceMix client
in there?  If you want to access another service, wouldn't it be much
easier to just create a second route in your Camel routebuilder
(from("direct:b").to("jbi:endpoint:...") and then send a Camel
exchange to the "direct:b" endpoint?

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/4/9 navigator09 <ga...@gmail.com>:
>
> Hi,
>
> I am trying to access ComponentContext inside servicemix-camel. I tried the
> following two approaches
>
> 1. created the following property inside the class which implements the
> route builder
>
>  private javax.jbi.component.ComponentContext context;
>
>   public void setContext(ComponentContext context) {
>                this.context = context;
>        }
>  Expecting the dependency to be injected into the class extending the route
> builder as suggested by some forums. But it did not work.
>
>  2. I tried the following configuration with the xbean.xml of the camel
>
>  <bean id="JobPollerService" class="poller.service.JobPollerService">
>     <property name="servicemixclient" ref="client" />
>  </bean>
>
>  <bean id="client"
> class="org.apache.servicemix.client.DefaultServiceMixClient">
>     <constructor-arg ref="jbi" />
>  </bean>
>
> and in the camel router I implemented the following method
>
> public static DefaultServiceMixClient client;
>        public void setContext(DefaultServiceMixClient client) {
>                log.debug("Injecting component context");
>                this.client= client;
>        }
>
> here it failed to create the bean client saying that the constructor is
> incorrect. what is the right way to access ComponentContext or to create
> servicemixclient inside the servicemix-camel component.
>
> Regards,
> Ganesh
> --
> View this message in context: http://www.nabble.com/How-to-access-ComponentContext-inside-servicemix-camel-tp22972903p22972903.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>