如何在apache camel中附加速度文件内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在apache camel中附加速度文件内容相关的知识,希望对你有一定的参考价值。
我试图在Apache-camel速度上写一个简单的示例:)。它应该拾取一个文件并将其内容插入预先写好的文本(在.vm文件中)。但它只是将文件名放在那里。这是我的脚本。
blueprint.xml
<camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
</camelContext>
这是我的.vm文件内容
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${in}
Best regards
${headers.senderPersonalName}
而不是$ {in},我也尝试了$ {body},它没有用。
答案
尝试从URI文件中检索内容后将正文转换为字符串。
可能这项工作,你的路线将是这样的
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<convertBodyTo id="_convertBodyFileContent" type="java.lang.String"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
这是你的.vm文件内容
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${body}
Best regards
${headers.senderPersonalName}
以上是关于如何在apache camel中附加速度文件内容的主要内容,如果未能解决你的问题,请参考以下文章
如何在Apache Camel Aggregator关联中加入多个标头
Apache Camel使用spring DSL比较字符串与引号,如何逃脱?