【问题标题】:Camel-Restlet producer message body is nullCamel-Restlet 生产者消息正文为空
【发布时间】:2018-01-10 22:48:53
【问题描述】:

使用 camel-restlet 调用休息端点时,未设置帖子正文。 这是我的 blueprint.xml

<camelContext id="blueprint-bean-context-SF"
    xmlns="http://camel.apache.org/schema/blueprint">

    <route id="Camel-Restlet-Client">

        <from uri="timer://example?repeatCount=1&amp;period=1000" />
        <setHeader headerName="Content-Type">
            <constant>application/json</constant>
        </setHeader>
        <setHeader headerName="api-key">
            <constant>{{drupal-api-key}}</constant>
        </setHeader>
        <setBody><constant>{name: "paul rudd", movies: ["I Love You Man", "Role Models"]}</constant></setBody>
        <log message="Request: ${headers} \n ${body}" />
        <to uri="restlet:https://reqres.in/api/users?restletMethod=POST" />
        <log message="Response: ${headers} \n ${body}" />
    </route>

</camelContext>

我正在使用骆驼 2.20.1。任何帮助表示赞赏?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    我自己是 cmel 新手,但我猜问题出在您使用的 setHeader 上。因为 setHeader 设置了 Camel-Message 的标头,而不是通过网络发送的 http-request 的标头。您需要在消息上设置一个标题,restlet 会知道该标题。并且restlet会将setheader的值传输到http-request的theader。

    抱歉,我不知道该怎么做。以下编码工作,使用 Header 进行身份验证:

    restConfiguration("restlet").bindingMode(RestBindingMode.json); // use json for all
    
    from("timer://example?repeatCount=1&period=1000")
    .setHeader("CamelRestletLogin", constant("xxx"))
    .setHeader("CamelRestletPassword", constant("xxx"))
    .to("restlet:https://xxx.hana.ondemand.com:443/ain/services/api/v1/models")
    

    对不起,我帮不上忙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      相关资源
      最近更新 更多