Spring Integration combine path variables and post body in payload expression

旧城冷巷雨未停 提交于 2019-12-23 13:05:34

问题


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')) />

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.

Is this possible? Thanks in advance.


回答1:


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)" 

It is just because HttpEntity has that getter!



来源:https://stackoverflow.com/questions/18898816/spring-integration-combine-path-variables-and-post-body-in-payload-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!