Here is a note, if your method take the exchange as the parameter, the
return type must be void.

Spring configuration example
<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring";>
  <from url="COSUME_XML_URL"/>
   <to url="bean:bar?method=doSomething"/>
     <to url="mail:xxx"/>
</camelContext>

<bean id="bar" class="xxx.Bar" />

Java example, you need bind "bar" with the Bar's new instance in the
JndiContext, or you create a SpringCamelContext to load
<bean id="bar" class="xxx.Bar" />, then add the route rule with below code.

from("COSUME_XML_URL")
   .to("bean:bar?method=doSomething")
    .to("mail:xxx");

You can find more bean unit tests here[1]

[1]
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean

Willem


Franklin Antony wrote:
> But if I had a method as follows
> 
> public class Bar {
> 
>     public String doSomething(Exchange exchange) {
>       // process the exchange
>       String newFileName=SprringService.generateFileName();
> 
>       exchange.getIn().setBody("Bye World");
>       
>        return newFileName;
> 
>    }
> }
> 
> Would this be possible?
> 
> If so how would the route be written in Java and XML ??
> 
> Thanks,
> Franklin.
> 
> 
> 
> 
> 
> willem.jiang wrote:
>> Hi Frank
>>
>> Basically if you want to set the result object back into message body,
>> you just need to return that result object in your method, camel-bean
>> will take care of it.
>>
>> BTW, you can also pass the Exchange into your bean's method like this
>> so you can set the result object yourself.
>> public class Bar {
>>
>>     public void doSomething(Exchange exchange) {
>>       // process the exchange
>>       exchange.getIn().setBody("Bye World");
>>    }
>> }
>>
>> You can find more information about how to use bean in camel here [1][2]
>> [1] http://activemq.apache.org/camel/bean.html
>> [2] http://activemq.apache.org/camel/bean-binding.html
>>
>> Willem
>>
>> Franklin Antony wrote:
>>> Thanks Willem. It did clear the confusion. 
>>>
>>> My having my own spring bean I can decouple from Camel code and this I
>>> would
>>> prefer.
>>>
>>> However is it possible that I can get back a ResultObject from
>>> "mySpringBean" which I would like to pass on to another <to> location?
>>>
>>> Thanks,
>>> Franklin.
>>>
>>>
>>> willem.jiang wrote:
>>>> I think Claus just show two ways to combine your transformation business
>>>> logic with the spring xml configuration.
>>>> The spring configuration could be
>>>> <from url="COSUME_XML_URL"/>
>>>>  <to url="bean:mySpringBean?method=transformation"/>
>>>>    <to url="mail:xxx"/>
>>>> or
>>>> <from url="COSUME_XML_URL"/>
>>>>  <process ref="mySpringBeanThatImplementsProcessor"/>
>>>>    <to url="mail:xxx"/>
>>>>
>>>>
>>>> mySpringBeanThatImplementsProcessor and mySpringBean have nothing to
>>>> relate. They just implement the same transformation business logic.
>>>>
>>>> Willem
>>>>
>>>> Franklin Antony wrote:
>>>>> And the processor as:
>>>>> <process ref="mySpringBeanThatImplementsProcessor"/>
>>>>>
>>>>> And then you need the regular spring beans configuration in spring as
>>>>> well
>>>>> to link to the actual class file
>>>>> <bean id="mySpringBeanThatImplementsProcessor" class="xxx.yyy"/>
>>>>> <bean id="mySpringBean" class="xxx.yyy.zzz"/>
>>>>>
>>>>> mySpringBean is just a regular POJO that doesn't have to have import
>>>>> any
>>>>> camel classes.
>>>>>
>>>>>
>>>>>
>>>>> How is mySpringBeanThatImplementsProcessor and mySpringBean related ??
>>>>>
>>>>> Thanks,
>>>>> Franklin
>>>>
>>
>>
> 

Reply via email to