I have a little bit understanding about Spring Integration and so far i have used JMS and File outbound adapters and now i want to introduce the HTTP out bound adapter for Spring REST support. So far so good an i was able to call external REST api with outany issue as below.
Spring Integration Config
<int-http:outbound-gateway id="outbound.gateway"
request-channel="get.request.channel" url="https://jsonplaceholder.typicode.com/posts/1"
http-method="GET" expected-response-type="com.cst.entity.Post"
charset="UTF-8" reply-timeout="5000" reply-channel="reply.channel">
</int-http:outbound-gateway>
Outbound gateway invokation
public void restTest() throws Exception{
Message<?> message = MessageBuilder.withPayload().build();
getRequestChannel.send(message);
Message<?> receivedMsg = receivedChannel.receive();
Post post = (Post) receivedMsg.getPayload();
System.out.println("############## ServerMsg ##############");
System.out.println(post.toString());
System.out.println("############## Done! ##############");
}
However i want to develop a framework where developers can invoke any REST url with any method and expect different types of response types. I found a way of dynamically setting the URL as below by introducing
<int-http:outbound-gateway id="outbound.gateway"
request-channel="get.request.channel" url="{fhirurl}"
http-method="GET" expected-response-type="com.bst.pages.crm.web.Post"
charset="UTF-8" reply-timeout="5000" reply-channel="reply.channel">
</int-http:outbound-gateway>
with
public void restTest() throws Exception{
FHIRInput input = new FHIRInput();
input.setUrl(url);
Message<?> message = MessageBuilder.withPayload(input).build();
getRequestChannel.send(message);
Message<?> receivedMsg = receivedChannel.receive();
Post post = (Post) receivedMsg.getPayload();
System.out.println("############## ServerMsg ##############");
System.out.println(post.toString());
System.out.println("############## Done! ##############");
}
Then i tried to implement dynamic HTTP methods with dynamic response types using the above method and it didn't work and it looks like we can handle only the URL using <int-http:uri-variable/>
.
What would be the ideal solution for this. appreciate your help
Thanks, Keth
EDIT
After following below comments i was able to implement a framework where developers can call use dynamic URL s based on the payload content. below is my configuration for HTTP outbound adapter.
<int-http:outbound-gateway id="outbound.gateway"
request-channel="get.request.channel" url="{fhirurl}"
http-method-expression="payload.getHttpMethod()" expected-response-type-expression="payload.getResponseType()"
charset="UTF-8" reply-timeout="5000" reply-channel="reply.channel">
<int-http:uri-variable name="fhirurl" expression="payload.getUrl()"/>
</int-http:outbound-gateway>
However im still looking for a way to pass a dynamic request body as a POST parameter. Since we use payload to carry the URL, http method and expected response type i can not pass the request body.