Apache Camel:如何对一个目录中的文件进行简单修改,然后将输出存储在另一个目录中?
看起来很简单,但我无法让它工作。我想要做的是获取放置在“from”路径中的任何文件,修改其内容,然后将修改后的文件放置在“to”路径中(带有 .txt 扩展名)。这就是我所拥有的:
this.context.addRoutes(new RouteBuilder() {
public void configure() {
from( "file:" + getFromPath() + getOptions() )
.to( "file:" + getToPath() + "?fileName=${file:name.noext}.txt")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String name = (String) exchange.getIn().getHeader("CamelFileName");
File body = exchange.getIn().getBody(File.class);
String parsedText = modifyFile(body);
exchange.getOut().setBody(parsedText);
}
})
;}
});
输出文件正在创建,但内容与输入文件完全相同。即,该文件没有被修改。我确认“modifyFile”方法正在返回我想要的内容,但无法让它将这些内容写入输出(“to”)路径。
感谢您的帮助!
Seems simple, but I can't get it working. What I want to do is take any files that are placed in the "from" path, modify their contents, and place the modified file in the "to" path (with a .txt extension). Here's what I have:
this.context.addRoutes(new RouteBuilder() {
public void configure() {
from( "file:" + getFromPath() + getOptions() )
.to( "file:" + getToPath() + "?fileName=${file:name.noext}.txt")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String name = (String) exchange.getIn().getHeader("CamelFileName");
File body = exchange.getIn().getBody(File.class);
String parsedText = modifyFile(body);
exchange.getOut().setBody(parsedText);
}
})
;}
});
The output file is getting created, but the contents are exactly the same as the input file. I.e, the file is not getting modified. I confirmed that the "modifyFile" method is returning what I want it to, but can't get it to write those contents to the output ("to") path.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要修改文件内容,则需要将处理器放在“from”和“to”端点之间。
If you want to modify the file content, you need to put the processor between the "from" and "to" endpoints.