Apache Camel:如何对一个目录中的文件进行简单修改,然后将输出存储在另一个目录中?

发布于 2024-12-09 01:12:25 字数 838 浏览 0 评论 0原文

看起来很简单,但我无法让它工作。我想要做的是获取放置在“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2024-12-16 01:12:25

如果要修改文件内容,则需要将处理器放在“from”和“to”端点之间。

If you want to modify the file content, you need to put the processor between the "from" and "to" endpoints.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文