How to call setter method on ${body} in a Camel route?

apache-camel

Solution

I'm not sure if it's possible with `simple`, but you could do it using `groovy`:

<setBody>
    <groovy>request.body.label = exchange.getProperty('label')
            return request.body
    </groovy>
</setBody>

Problem

I have tried to set a property on the body of a Java bean constituting the message in transit through a Camel route. I have tried various approaches e.g. ``` <route> ... .. <transform> <simple>${body.label} = ${property.label}</simple> </transform> ... .. </route> ``` in this particular case the `${body}` is a Java bean with a `setLabel(String label)` method and the `${property.label}` is set by other means in another route. In this example the result is not the desired (and I understand why), i.e. after the transform the body of the message is replaced with the `${body.label} = ${property.label}` string. My current work-around is to manually code a transformer as a Spring bean and set the label property of the Java bean in code but I like to find out if there is a simpler/smarter way to achieve this, preferably in XML DSL which is what I use? Regards, Ola

Original source