2016-04-23 32 views
0


我已安排其解组XML文件到Java对象(com.sample.Order)以下骆驼路线:速度报告对象

<route> 
    <from uri="file:/data/in?fileName=order.xml&amp;noop=true"/> 
    <unmarshal ref="transform-xml"/> 
    <to uri="velocity:etc/MailBody.vm"/> 
    <to uri="file:/data/out"/> 
    </route> 

这里是MailBody.vm:

#set($order = $body.get(0).get('com.sample.Order')) 

Order status: 
- Id: $order.id 
- Price: $order.price 

Tax: $order.tax 

Details: 
$order.description 

当执行Camel路径时,生成的XML文件不会解析$ order字段。有没有我想念的东西,或者这可能不适合我的骆驼版本(2.15.3)? 感谢

回答

1

尝试修改模板像图所示:

#set($order = ${body.get(0).get("com.sample.Order")}) 

Order status: 
- Id: ${order.id} 
- Price: ${order.price} 

Tax: ${order.tax} 

Details: 
${order.description} 
+0

谢谢,但没有奏效。输出仍包含$ {order}变量。 – Carla

+0

我想,这意味着'body.get(0).get(“com.sample.Order”)'为空。 'body'变量包含什么对象(可以使用** log **组件追踪它)? –

+0

我已检查过正文,它包含com.sample.Order类,但是通过增加日志级别,将打印以下调试:#set语句的DEBUG RHS为空。上下文将不会被修改。 org.apache.camel.component.velocity.VelocityEndpoint [line 2,column 1] VelocityEndpoint DEBUG空引用[template'org.apache.camel.component.velocity.VelocityEndpoint',line 5,column 7]:$ {order。 id}无法解析。 。 。 。 – Carla