如何在Apache骆驼中以速度附加文件内容

时间:2018-07-16 12:25:07

标签: apache-camel jbossfuse

我正在尝试编写有关Apache骆驼速度的简单示例:)。应该选择一个文件并将其内容插入预写的文本(在.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} 

我还尝试了$ {body}而不起作用,而不是$ {in}。

1 个答案:

答案 0 :(得分:0)

从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}