【问题标题】:Spring Integration combine path variables and post body in payload expressionSpring Integration 在有效负载表达式中结合路径变量和帖子正文
【发布时间】:2013-09-24 18:46:09
【问题描述】:

使用 http 入站网关,我可以使用 SPEL 指定有效负载表达式,该表达式将访问标头、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 构造函数添加一个附加参数,即实际的帖子正文(显然我会更改方法)并将其序列化为适当的类型。

这可能吗?提前致谢。

【问题讨论】:

    标签: java spring spring-integration spring-el


    【解决方案1】:

    是的,这是可能的。 payload-expression 使用 EvaluationContextHttpEntity 作为 rootObject#requestParams#pathVariables 变量。 所以,如果你把它改成 POST 你可以得到一个身体!:

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

    只是因为HttpEntity有那个getter!

    【讨论】:

    • Artem,谢谢,这不仅能清理身体。我从来不明白有效载荷表达式使用什么上下文。我确定这是我在文档中多次浏览的内容,只是没有点击。感谢您的完整回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多