【问题标题】:How to add an trailing slash to the camel http component of camel如何在camel的camel http组件中添加斜杠
【发布时间】:2022-09-23 21:19:24
【问题描述】:

我正在尝试从我的骆驼路线呼叫休息邮政服务。 其余服务部署在https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag/。 如果尾部有斜杠(在 verteileauftrag 之后),则从 VS Code 之类的 Rest 客户端调用服务可以工作。

在我的骆驼路线中,我配置了以下内容:

restConfiguration().host(\"https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1\").component(\ "http\").bindingMode(RestBindingMode.json);

然后稍后使用配置: .to(\"rest:post:verteileauftrag?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType\")

如果我执行代码,我会从后端收到 404 HTTP 错误,因为使用的 URL 是
https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag。所以没有尾随斜杠。 我试图像 .to(\"rest:post:verteileauftrag/?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType\") 这样添加它

但没有成功。 您知道如何告诉其余配置中的 http 组件如何添加斜杠吗? 非常感谢。 使用redhat fuse 7_10_2。

问候米歇尔

    标签: apache-camel


    【解决方案1】:

    阿帕奇骆驼REST-DLS不是用于调用外部 Rest 服务。它用于使用 Apache Camel 使用诸如 jetty、undertow 或 netty 之类的 Web 服务器之一来制作 Rest 服务。

    如果你想调用外部休息服务,你可以使用http-component

    例子:

    from("direct:requrestDataFromAPI")
        .routeId("requrestDataFromAPI")
        .to("http://localhost:3001/api/test?throwExceptionOnFailure=false")
        .filter(header(Exchange.HTTP_RESPONSE_CODE).isGreaterThanOrEqualTo(300))
            .log(LoggingLevel.ERROR, "Failed to request data from API.\n" 
                + " ResponseBody: ${body}\nResponseCode ${headers.CamelHttpResponseCode}")
            .stop()
        .end()
        .log("Succefully requested data from API: ${body}")
    ;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2014-11-20
      • 2015-07-27
      相关资源
      最近更新 更多