英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论