阿帕奇骆驼和码头

Apache Camel & Jetty

我想从本地主机保存内容({ 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 已启动并从本地主机使用,但未将其保存在 text.file 中。 你能帮帮我吗?

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

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

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

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