如何在 Camel 路由中调用 ${body} 上的 setter 方法? [英] How to call setter method on ${body} in a Camel route?
问题描述
我试图在 Java bean 的主体上设置一个属性,该属性构成通过 Camel 路由传输的消息.我尝试了各种方法,例如
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>
这篇关于如何在 Camel 路由中调用 ${body} 上的 setter 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!