驼峰体在发送到HTTP后为空。

huangapple go评论70阅读模式
英文:

Camel body empty after sending to HTTP

问题

使用HTTP组件,Camel似乎会将消息体替换为HTTP响应体。我想要在发送后记录我发送的消息体。使用streamCaching()的以下代码似乎不起作用,并且似乎被响应体替换:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${body}")

我还尝试了ignoreResponseBody,但结果相同:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint?ignoreResponseBody=true")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${body}")

最后,由于Camel的文档说它使用http响应体设置了exchange.out的消息体,我尝试了${in.body},但结果仍然相同:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint?ignoreResponseBody=true")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${in.body}")

有人可以帮助解释一下吗?

英文:

Using the HTTP component, Camel seems to replace the body with the HTTP response body. I want to log the body I sent after sending it. The following with streamCaching() doesn't work and seems to be replaced with the response body:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${body}")

Also tried ignoreResponseBody. Same result:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint?ignoreResponseBody=true")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${body}")

Finally, since Camel's documentation says it sets exchange.out's body with the http response body, I tried ${in.body} with the same result:

from("direct:in")
    .streamCaching()
    .to("https://myEndpoint?ignoreResponseBody=true")
    .log(LoggingLevel.INFO, LOG, EVENT_SENT_MARKER, "body - ${in.body}")

Can anyone help shed some light on this?

答案1

得分: 1

你可以将请求体存储在头部,类似这样:

from("direct:in")
    .streamCaching()
    .setProperty("MyBody").body()
    .to("https://httpbin.org/post")
    .log("${exchangeProperty.MyBody}")

这样你就可以访问你发送的请求体以及来自服务的响应。

英文:

You can store the bod in an header, something like:

from("direct:in")
    .streamCaching()
    .setProperty("MyBody").body()
    .to("https://httpbin.org/post")
    .log("${exchangeProperty.MyBody}")

So you can have access to the body you sent and the answer from your service.

huangapple
  • 本文由 发表于 2020年9月16日 04:59:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63909775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定