简体   繁体   English

如何在Camel中将非编组对象设置为交换属性

[英]How to set an unmarshalled object to an exchange property in Camel

I am new to Camel and I am stuck at a point which seems to be simple. 我是骆驼的新手,我被困在一个似乎很简单的地方。 I have a requirement of unmarshalling 2 xml's that are in my exchange and then pass the corresponding POJO's to a processor. 我需要解组交换中的2个xml,然后将相应的POJO传递给处理器。 I am thinking if I could unmarshall one xml, set it to a property in exchange and repeat same for another xml. 我在想是否可以解组一个XML,将它设置为一个属性,以交换另一个XML的属性。 Finally in processor I will retrieve the properties and can perform the needed logic in processor. 最后,在处理器中,我将检索属性并可以在处理器中执行所需的逻辑。 I am able to successfully unmarshall the xml's and also get the last POJO in exchange.in.body. 我能够成功地将xml解组,并在exchange.in.body中获得最后一个POJO。 But can anyone tell me what is the correct way to set the result of unmarshalled object in exchange property? 但是谁能告诉我在交换属性中设置未编组对象结果的正确方法是什么? I tried below but it doesnt work : 我在下面尝试过,但是没有用:

    <setProperty propertyName="foo">
        <unmarshall ref="modelref" id="model_id"" />
    </setProperty>

here modelref is a ref to bean of org.apache.camel.model.dataformat.JAXBDataFormat class from camel. 这里的modelref是骆驼对org.apache.camel.model.dataformat.JAXBDataFormat类的bean的引用。

Can anyone give me some pointers to fix this? 谁能给我一些指导以解决此问题?

Unmarshal is not a valid child-element of the setProperty-element. Unmarshal不是setProperty元素的有效子元素。 Provided that you've already performed some sort of split and now want to unmarshal one of your XMLs and set as a header you'd do something like this: 前提是您已经执行了某种拆分,并且现在想要解组一个XML并将其设置为标头,则可以执行以下操作:

<unmarshal ref="modelref" id="model_id" />
<setProperty propertyName="foo">
    <simple>${body}</simple>
</setProperty>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM