【问题标题】:Apache Camel - http Producer don't use GET-Method with enrich PatternApache Camel - http Producer 不使用 GET-Method 和丰富模式
【发布时间】:2013-11-12 13:46:26
【问题描述】:

我有一个 RESTful Web 服务,我想将它与 Camel-Route 中的内容丰富器一起使用。 请参阅此类似代码:

from("direct:in") // Here comes XML
    .to("validator:something.xsd") // validate it
    .unmarshal("something-jaxb") // put it into a POJO
    .setHeader(Exchange.HTTP_URI, simple("http://localhost:12345/restws/${header.foo}")) // Create the dynamic URI with simple
    .setHeader(Exchange.HTTP_METHOD, constant("GET")) // set the HTTP-Method to use
    .enrich("http://dummy", new MyAggregator()) // fetch some Information from a Restful Webservice
    .to("direct:out"); // send the Message to another route

如果我运行它,我会收到以下错误:

No type converter available to convert from type: de.my.Class to the required type: java.io.InputStream with value de.my.Class@620ee765.

在我看来,他试图将 Exchange 的主体发送到 http-Endpoint,尽管我将 HTTP-Method 设置为 GET。我已阅读文档 (https://camel.apache.org/http.html) 和下面的 使用 GET 或 POST 调用 它描述了选择方法的算法首先查看标题(1. 使用标题中提供的方法)。

我找到了一些解决方法,其中描述了如何将正文移动到 Exchange 属性并在 Webservice-Call 之后再次将其移回,但这不可能......


编辑:

  • 像 Claus Ibsen 提到的丰富不支持动态 uri。在示例中修复了这个问题!

【问题讨论】:

    标签: java rest apache-camel


    【解决方案1】:

    rich 和 pollEnrich 都不支持其端点的动态 uri。除了使用丰富,您可以使用支持动态uri的收件人列表,以及聚合策略。

    【讨论】:

    • 你是绝对正确的。我修复了它(见上文),但问题仍然存在:(。
    【解决方案2】:

    如果它是“充满列表”的资源,听起来你会想要拆分列表并获取每个资源

    【讨论】:

    • 没有。我只想在消息头中使用 foo 值执行 ONE HTTP-Request。此请求的响应应与请求后的正文合并。
    • 所以你想传递一个资源列表?你可以这样做,但你的 API 必须支持它。
    【解决方案3】:

    pojo 里有什么?您的 GET 参数应该是资源标识符和查询参数。这需要一个自定义转换器。

    http://fusesource.com/docs/esb/4.2/rest/RESTIntro.html

    也许可以考虑改用restlet...我认为它更容易。

    http://camel.apache.org/restlet.html

    【讨论】:

    • Pojo 充满了更多 Pojo 的列表:)。此 Http-Request 中没有查询参数,我认为端点使用了我刚刚写入“丰富”方法 (http://localhost:12345/restws/${header.foo}) 的资源标识符。
    猜你喜欢
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2018-05-26
    • 2011-08-08
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多