使用 http 入站网关,我能够使用 SPEL 指定有效载荷表达式,它将访问 header 、requestParams 和 pathVariables。我如何还包含 POST 中的正文?我目前拥有的一个例子是
<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 构造函数添加一个额外的参数,它是实际的帖子正文(显然我会更改方法)并将其序列化为适当的类型。
这可能吗?提前致谢。
最佳答案
是的,这是可能的。 payload-expression 使用 EvaluationContext 和 HttpEntity 作为 rootObject, #requestParams 和 #pathVariables 变量。 所以,如果你把它改成 POST 你可以得到一个 body !:
payload-expression="new RequestDTO(
#pathVariables.product,
#pathVariables.id,
#requestParams['optionalParam'],
headers.get('headerKey'),
body)"
只是因为 HttpEntity 有那个 getter!
关于java - Spring Integration 在有效负载表达式中组合路径变量和发布主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18898816/