java - How to establish communication between 2 restful apps? -
i have 2 webapps designed expose restful services via json, being both written in java using springmvc + jackson.
the first app works more proxy, , forwards requests second app, holds real business logic (unfortunately, i'm not allowed give either 1 of them).
the restful endpoints pretty this:
@controller @requestmapping("rest") public class proxycontroller { @requestmapping(value = "download", method = requestmethod.post, produces="application/json", consumes="application/json") @responsebody public downloadresponse download() { // invoke backendcontroller mean } } @controller @requestmapping("rest") public class backendcontroller { @requestmapping(value = "download", method = requestmethod.post, produces="application/json", consumes="application/json") @responsebody public downloadresponse download() { // business logic return new downloadresponse(); } }
my first idea use httpclient fire post proxycontroller backendcontroller, , guess pretty work.
i wondering if come better idea. know whether springmvc might make life little bit easier?
thanks lot comments
i went jb nizet's suggestion , looks way better! lot suggestion!
here's final code:
public class proxycontroller { public downloadresponse download() { resttemplate template = new resttemplate(); return template.postforobject("http://<backend-url>/rest/download.do", request, downloadresponse.class); } }
Comments
Post a Comment