Spring Integration Combines Path Variables and Message Body in a Payload Expression

Using an http inbound gateway, I can specify a payload expression using SPEL, which will access the header, requestParams and pathVariables. How to enable body from POST? An example of what I have now,

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

This works fine, however I want to add an extra parameter to the RequestDTO constructor, which is the actual body of the message (obviously, I will change the method) and serialize it to the appropriate type.

Is it possible? Thanks in advance.

+4
source share
1 answer

Yes it is possible. the payload uses an EvaluationContext with HttpEntity as rootObject , #requestParams and #pathVariables . So, if you change it to POST, you can get the body !:

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

Precisely because HttpEntity has this getter!

+6
source

All Articles