문제

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.

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top