Apache camel apachecamel 2.23.1:to(文件)创建一个空文件

Apache camel apachecamel 2.23.1:to(文件)创建一个空文件,apache-camel,Apache Camel,[JDK 8/11,Camel 2.23.1,Spring Boot 2.1.3] 嗨, 我目前正在学习骆驼,我无法克服一个奇怪的问题 我想下载一个URL到一个文件 URL有效,例如显示“11:59:00”。 目标文件已创建,但为空。为什么? @Component public class DownloadRoute extends RouteBuilder { @Override public void configure() throws Exception {

[JDK 8/11,Camel 2.23.1,Spring Boot 2.1.3]

嗨, 我目前正在学习骆驼,我无法克服一个奇怪的问题

我想下载一个URL到一个文件

URL有效,例如显示“11:59:00”。 目标文件已创建,但为空。为什么?

@Component
public class DownloadRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        String timer1 = "timer://foo?fixedRate=true&period=10000&delay=5000";
        String url = "http://localhost:8888/date";
        String file = "file:target/date";
        from(timer1).to(url).log("${id}->${body}").to(file);  // ID-Laptop-1551464093962-0-2->11:59:00, that's ok
    }
}
记录器输出正确的内容,例如:

2019-03-01 19:15:00.421信息2984---[3-timer://foo]路由1
:ID-Laptop-1551464093962-0-2->11:59:00

但生成的文件(例如target/date/ID-Laptop-1551464093962-0-2)为空

有什么想法吗

解决方案(感谢Tache):

    from(timer1).to(url).to(file);  // without logging


http端点()的输出可能是使用InputStream读取的流。这样的流只能读取一次。 可能的解决办法:

  • 删除日志语句
  • 在Camel上下文或路由中启用流缓存
  • 将消息正文转换为字符串(
    .convertBodyTo(string.class)
    ),然后将其记录并发送到文件

    • http端点()的输出可能是使用InputStream读取的流。这样的流只能读取一次。 可能的解决办法:

      • 删除日志语句
      • 在Camel上下文或路由中启用流缓存
      • 将消息正文转换为字符串(
        .convertBodyTo(string.class)
        ),然后将其记录并发送到文件
          from(timer1).to(url).convertBodyTo(String.class).log("${id}->${body}").to(file);    // with logging