如何在骆驼路线中调用 ${body} 上的 setter 方法? [英] How to call setter method on ${body} in a Camel route?

查看:12
本文介绍了如何在骆驼路线中调用 ${body} 上的 setter 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在构成通过 Camel 路由传输的消息的 Java bean 的主体上设置一个属性.我尝试了各种方法,例如

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>

在这种特殊情况下,${body} 是一个具有 setLabel(String label) 方法和 ${property.label} 在另一条路线中通过其他方式设置.在这个例子中,结果不是我们想要的(我明白为什么),即在转换之后,消息的正文被替换为 ${body.label} = ${property.label} 字符串.

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.

我目前的解决方法是将转换器手动编码为 Spring bean,并在代码中设置 Java bean 的标签属性,但我想知道是否有更简单/更智能的方法来实现这一点,最好是在 XML 中我用的是什么DSL?

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?

问候,奥拉

推荐答案

我不确定 simple 是否可行,但你可以使用 groovy 来实现:

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>

这篇关于如何在骆驼路线中调用 ${body} 上的 setter 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆