【问题标题】:Http-Request in Apache CamelApache Camel 中的 Http 请求
【发布时间】:2018-11-29 18:53:28
【问题描述】:

我想保存来自本地主机的内容(json 数据) 示例:

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

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

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

你能帮帮我吗?

【问题讨论】:

    标签: json apache apache-camel localhost http4s


    【解决方案1】:

    我认为你的代码一切都很好。这可能是文本文件中没有数据的原因。在 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) 可以解决此问题。

    【讨论】:

    • 让我知道生成的文件是否包含空白内容?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多