2016-04-01 146 views
0

我已经在本地实现了一个restfull webservice项目来自rest-client我可以发送请求,并且我也得到了回复。 下面是其余的客户 “发布采购信息”:如何通过springXD发送http-client发布请求

{"address":{"type1":"abc","email":"[email protected]"}} 

响应:

{"address":{"type1":"abc","email":"[email protected]"}} 

而这些标题。

Content-Type:application/json 

下面一个是我的本地Java API项目网址:

http://localhost:8080/test/test1 

现在我试着学习春天XD我怎么能带弹簧XD发送请求。我已经在我的本地安装了Spring XD和RabbitMQ。

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

+0

您可以使用Spring集成 –

回答

0

由于您使用的春天,也许你可以使用类org.springframework.web.clientRestTemplate要求您API:

RestTemplate restTemplate = new RestTemplate(); 
HttpEntity<MailContact> request = new HttpEntity<>(new MailContact("[email protected]")); 
Contact contact = restTemplate.postForObject("http://localhost:8080/test/test1", request, Contact.class); 

希望这会有所帮助。

+0

使用Spring为XD创建自定义组件,我可以发送请求并获得响应。我正在尝试Spring XD。如何使用Spring-XD发送带有标头的请求 –

+0

因此,也许[this](http://stackoverflow.com/questions/28118990/passing-http-request-header-to-restapi-from-springxd-using-http-client处理器)可以提供帮助。 – cdelmas

0

使用httpMethod属性...

--httpMethod=POST 

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

0

让我们来举个例子。如果你想SpringXD是Web服务客户端获得响应从周一的每分钟至周五的上午8点到下午5点,和转储结果之间的文件, 请在下面的命令与运行XD壳

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 

触发模块将发送''char作为默认请求,为了改变这种行为,你可以通过添加有效载荷参数来定义精确的字符串,如: trigger --payload ='yourRequestMessage'--cron ='0 * 8-17 * * 1-5'

+0

我想尝试POST方法,并且需要发送请求体而不是GET方法。 –

+0

abccccccccccccccccccccccc –

相关问题