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

狂风中的少年 提交于 2019-12-10 16:19:13

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/20404110/how-to-call-setter-method-on-body-in-a-camel-route

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!