首页 > 解决方案 > 阿帕奇骆驼和码头

问题描述

我想保存来自本地主机的内容({ enter code here

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

) 在 txt.file 中。但:

public void configure() throws Exception {
      from("jetty:http://localhost:8091/customers/")
              .setHeader(Exchange.HTTP_METHOD, constant("POST"))
              .convertBodyTo(String.class)
               .log("Test3 ${body}")
              .to("file:dest")
                .end();

我的 route1 开始并从 localhost 使用,但它没有将其保存在 text.file 中。你能帮助我吗?

标签: apachelocalhostjetty

解决方案


您的路线不会从本地主机消耗。实际上,您使用 jetty 作为消费者(from),这意味着您提供了端点,以便以后可以从浏览器中调用它。

我认为您想创建一个生产者(to)来调用该服务。这可以通过 camel-http4 组件来完成。

因此,您需要一个开始的路线,比如说通过一个计时器(每 5 秒),并且您需要调用您的端点:

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

推荐阅读