Spring Integration 在负载表达式中组合路径变量和 post body [英] Spring Integration combine path variables and post body in payload expression
问题描述
使用 http 入站网关,我可以使用 SPEL 指定有效负载表达式,该表达式将访问标头、请求参数和路径变量.我如何还包括来自 POST 的正文?我目前拥有的一个例子是
Using an http inbound-gateway I am able to specify a payload-expression using SPEL that will access header, requestParams, and pathVariables. How do I also include the body from a POST? An example of what I currently have is
<int-http:inbound-gateway path="/document/{product}/{id}/blah"
supported-methods="GET"
request-channel="documentService.blah"
reply-channel="httpReplyChannel"
message-converters="jsonMessageConverter"
header-mapper="defaultHttpHeaderMapper"
payload-expression="new RequestDTO(
#pathVariables.product,
#pathVariables.id,
#requestParams['optionalParam'],
headers.get('headerKey')) />
这工作正常,但是我想在 RequestDTO 构造函数中添加一个额外的参数,该参数是实际的帖子正文(显然我将更改该方法)并将其序列化为适当的类型.
That works fine, however I want to add an additional parameter to the RequestDTO constructor that is the actual post body (obviously I will change the method) and have it serialized into the appropriate type.
这可能吗?提前致谢.
推荐答案
是的,这是可能的.payload-expression 使用 EvaluationContext 和 HttpEntity 作为 rootObject,#requestParams 和 #pathVariables 变量.因此,如果您将其更改为 POST,您可以获得一个正文!:
Yes, it is possible. payload-expression uses an EvaluationContext with HttpEntity as rootObject, #requestParams and #pathVariables variables. So, if you change it to POST you can get a body!:
payload-expression="new RequestDTO(
#pathVariables.product,
#pathVariables.id,
#requestParams['optionalParam'],
headers.get('headerKey'),
body)"
这只是因为 HttpEntity 有那个 getter!
It is just because HttpEntity has that getter!
这篇关于Spring Integration 在负载表达式中组合路径变量和 post body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!