I tried to make a POST restful api call from Spring Integration with http:outbound-gateway. But I couldn't figure out how to pass the request JSON object to the restful API. Can someone show me how to do it? Thanks !
Here is my spring-integration-config.xml
<si:channel id="request.channel" />
<si:channel id="response.channel">
<si:queue capacity="10" />
</si:channel>
<int-http:outbound-gateway id="employeeinfoGateway"
request-channel="request.channel"
url="http://localhost:8080/EmployeeInfo"
http-method="POST"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="5000"
reply-channel="response.channel">
</int-http:outbound-gateway>
Here is my Java code:
MessageChannel request = (MessageChannel) context.getBean("request.channel");
JSONObject obj = new JSONObject();
obj.put("empId", "100");
request.send(MessageBuilder.withPayload(obj).setHeader("content-type","application/json").build());
Here is the error message I received:
Could not write request: no suitable HttpMessageConverter found for request type [org.json.JSONObject] and content type [application/json], failedMessage=GenericMessage [payload={"empId":"100"}, headers={content-type=application/json, id=a0aba65f-3f49-4dfc-2431-51983666772b, timestamp=1521419315405}]