Hi

No there is a caveart when you use Exchange as parameter in your POJO
- if using Exchange your method should be void, and you should
"return" by setting the OUT body of the exchange.
      exchange.getIOut).setBody("what you want to return");

However if I understand your use case is that you want to return a new
filename that Camel should move the file to? If that is so, then you
need to set a HEADER with the filename so Camel knows what the
filename should be: The key is org.apache.camel.file.name. And there
is a constant on FileComponent.
        exchange.getOut().setHeader("org.apache.camel.file.name", newFilename);

Note: If you want to use the same body as the IN you can just alter
the IN instead as Camel will use IN if there is no OUT set. So you
just change the filename on the IN header
        exchange.getIn().setHeader("org.apache.camel.file.name", newFilename);

And Camel should write the file using the new filename instead of the
original filename


But you said that you wanted to use plain POJO and not depend on camel
classes, so you can use pure bean binding instead of Exchange.
http://activemq.apache.org/camel/parameter-binding-annotations.html

public void doSomething(@Headers Map headers) {
   headers.put("org.apache.camel.file.name", newFilename);
}

You can add more parameters if you need for instance the file body
public void doSomething(@Headers Map headers, @Body String body) {
}






/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Thu, Dec 4, 2008 at 8:04 AM, Franklin Antony
<[EMAIL PROTECTED]> 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
>>>>
>>>>
>>>
>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Transformation-task-in-Spring-tp18647141s22882p20828353.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Reply via email to