Spring Integration将路径变量和post body组合在有效负载表达式中

时间:2013-09-19 15:25:25

标签: java spring spring-integration spring-el

使用http inbound-gateway我可以使用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构造函数中添加一个额外的参数,它是实际的帖子体(很明显我会更改方法)并将它序列化为相应的类型。

这可能吗?提前谢谢。

1 个答案:

答案 0 :(得分:6)

是的,有可能。 payload-expression 使用 EvaluationContext HttpEntity 作为 rootObject #requestParams #pathVariables 变量。 因此,如果您将其更改为POST,您可以获得一个正文!:

 payload-expression="new RequestDTO(
                         #pathVariables.product,
                         #pathVariables.id,
                         #requestParams['optionalParam'],
                         headers.get('headerKey'),
                         body)" 

这只是因为 HttpEntity 有吸气剂!