如何在 apache camel 中以 velocity 附加文件内容
how to append file content in velocity in apache camel
我正在尝试编写一个关于 Apache-camel velocity 的简单示例 :)。它应该获取一个文件并将其内容插入到预先编写的文本中(在 .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},但没有用。
从文件的 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 velocity 的简单示例 :)。它应该获取一个文件并将其内容插入到预先编写的文本中(在 .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},但没有用。
从文件的 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}