spring-integration:如何将 post 请求参数传递给 http-outbound [英] spring-integration: how to pass post request parameters to http-outbound

查看:57
本文介绍了spring-integration:如何将 post 请求参数传递给 http-outbound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 post 请求参数传递给 int-http:outbound-gateway,但找不到任何简单的方法来执行此操作.我必须做的是向沙发数据库发出 http 请求,使用单个请求获取多个文档,如沙发数据库文档中所述:

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

那么如何将名为keys"的参数传递给 int-http:outbound-gateway?(我在消息的有效负载中有我需要的所有数据)

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

推荐答案

入站消息的payload成为POST的主体;选定的标头被映射,您可以使用许多标头映射选项来控制它;请参阅文档.

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.

如果你需要将一些java对象转换为上面的JSON,你可以在网关上游添加一个转换器,或者在网关本身中配置一个自定义的MessageConverter.

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.

您的 curl 命令正在发送 JSON 作为 POST 正文;网关会做同样的事情.

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

这篇关于spring-integration:如何将 post 请求参数传递给 http-outbound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆