繁体   English   中英

Apache Camel中的Http-Request

[英]Http-Request in Apache Camel

我想从本地主机(json数据)保存内容,例如:

"id": 1,
    "prename": "Noel",
    "surname": "Reyes",
    "dateOfBirth": "1988-09-07",
    "birthPlace": "Bad Ems",
    "gender": "M"}

)放在txt.file(Example.txt中的C:\\ inputFolder)中。 那就是我的代码:

from("timer://foo?period=5s")
  .to("http4://localhost:8091/customers/")
  .log("Test3 ${body}")
   .to("file:C:/inputFolder/Example.txt")

;

但是:我的route1已启动,并且正在从localhost使用,但未将其保存在文本文件中。

main] DefaultCamelContext            INFO  Apache Camel 2.22.2 (CamelContext: camel-1) is starting
[                          main] ManagedManagementStrategy      INFO  JMX is enabled
[                          main] DefaultTypeConverter           INFO  Type converters loaded (core: 195, classpath: 15)
[                          main] HttpComponent                  INFO  Created ClientConnectionManager org.apache.http.impl.conn.PoolingHttpClientConnectionManager@24c4ddae
[                          main] DefaultCamelContext            INFO  StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[                          main] DefaultCamelContext            INFO  Route: route1 started and consuming from: timer://foo?period=5s
[                          main] DefaultCamelContext            INFO  Total 1 routes, of which 1 are started
[                          main] DefaultCamelContext            INFO  Apache Camel 2.22.2 (CamelContext: camel-1) started in 2.945 seconds

Process finished with exit code 0

你能帮助我吗?

我认为您的代码一切都很好。 可能这是文本文件中没有数据的原因。 http操作之后,您正在记录正文,并且一旦记录的正文内容消失了。

from("timer://foo?period=5s")
  .to("http4://localhost:8091/customers/")
   .convertBodyTo(String.class)
    .log("Test3 ${body}")
     .to("file:C:/inputFolder/Example.txt")

我认为通过在记录之前将主体转换为字符串convertBodyTo(String.class)可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM