spring-integration: how to pass post request parameters to http-outbound

一个人想着一个人 提交于 2019-12-08 07:58:03

问题


I need to pass a post request parameters to an int-http:outbound-gateway and can't find any simple way to do this. What I have to do is issue a http request to a couch db fetching multiple documents with a single request as described in the couch db documentation:

curl -d '{"keys":["bar","baz"]}' -X POST http://127.0.0.1:5984/foo/_all_docs?include_docs=true

So how do I pass the param with the name 'keys' to the int-http:outbound-gateway? (I have all the data I need in the payload of the message)

<int-http:outbound-gateway request-channel="requestChannel" 
                     url="http://127.0.0.1:5984/foo/_all_docs?include_docs=true" 
                     http-method="POST"
                     expected-response-type="java.lang.String"/>

回答1:


The payload of the inbound message becomes the body of the POST; selected headers are mapped and you can control that with a number of header mapping options; see the documentation.

If you need to transform some java object to the JSON above, you can add a transformer upstream of the gateway, or configure a custom MessageConverter into the gateway itself.

Your curl command is sending the JSON as the body of the POST; the gateway will do the same thing.



来源:https://stackoverflow.com/questions/20083604/spring-integration-how-to-pass-post-request-parameters-to-http-outbound

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