问题
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