Java 如何使用springXD发送http客户端post请求

Java 如何使用springXD发送http客户端post请求,java,spring,spring-xd,Java,Spring,Spring Xd,我在本地的rest客户机上实现了一个RESTFullWebService项目,我可以发送请求,也可以得到响应。 下面是rest客户端“Post请求”: 答复: {"address":{"type1":"abc","email":"tata@gmail.com"}} 这些是标题 Content-Type:application/json 下面是我的本地java项目API URL: http://localhost:8080/test/test1 现在我正在尝试学习SpringXD如何使用Sp

我在本地的rest客户机上实现了一个RESTFullWebService项目,我可以发送请求,也可以得到响应。 下面是rest客户端“Post请求”:

答复:

{"address":{"type1":"abc","email":"tata@gmail.com"}}
这些是标题

Content-Type:application/json
下面是我的本地java项目API URL:

http://localhost:8080/test/test1
现在我正在尝试学习SpringXD如何使用SpringXD发送请求。我已经在本地安装了SpringXD和RabbitMQ


请帮助我如何使用这些json请求从Spring XD发送post请求。

因为您使用的是Spring,也许您可以使用类
org.springframework.web.clientRestTemplate
来请求API:

RestTemplate restTemplate = new RestTemplate();
HttpEntity<MailContact> request = new HttpEntity<>(new MailContact("contact@mail.net"));
Contact contact = restTemplate.postForObject("http://localhost:8080/test/test1", request, Contact.class);
RestTemplate RestTemplate=new RestTemplate();
HttpEntity请求=新HttpEntity(新邮件联系人(“contact@mail.net"));
Contact Contact=restTemplate.postForObject(“http://localhost:8080/test/test1“、请求、联系人、类);

希望这会有所帮助。

使用
httpMethod
属性

--httpMethod=POST

mappedRequestHeaders
添加自定义头,但它将得到一个
X-
前缀。您将需要使用自定义头映射器自定义处理器以删除它。

让我们给您举个例子。如果您希望SpringXD成为webservice客户端,从周一到周五的上午8点到下午5点,每分钟都会收到响应,并将结果转储到文件中, 请使用xd shell运行下面的命令

stream create --name my_rest_client --definition "trigger --cron='0 * 8-17 * * 1-5' | http-client --url='''http://localhost:8080/test/test1''' --replyTimeout=2000 --httpMethod=GET --outputType=text/plain | file" --deploy
触发器模块将发送“”字符作为默认请求,若要更改此行为,您可以通过添加负载参数来定义确切的字符串,如:
触发器--payload='yourRequestMessage'--cron='0*8-17**1-5'

使用spring,我可以发送请求并获得响应。我正在尝试SpringXD。如何使用Spring XDSo发送带有标题的请求可能会有所帮助。您可以使用Spring Integration为XD创建自定义组件。我想尝试POST方法,还需要发送请求正文,而不是GET方法
stream create --name my_rest_client --definition "trigger --cron='0 * 8-17 * * 1-5' | http-client --url='''http://localhost:8080/test/test1''' --replyTimeout=2000 --httpMethod=GET --outputType=text/plain | file" --deploy