java - how to call an external api from spring mvc controller -


hello controller is

@controller public class homecontroller{  @requestmapping(value = "/instring={name}", method = requestmethod.get)        public @responsebody string getgreeting(@pathvariable string name, string result) {        //below url has given.i want pass name string below url input_text parameter       //http://ipaddress/input?input_text=tell me something&target_val=hi;         result=the_result_provided_from_the_above_url ;          return result; } } 

i able pathvariable name.now want pass name url returns string , string returned controller.i tried have not been able call url controller.

you can call servlet using apache's httpclient. example:

... private static final string servleturl = "http://ipaddress/input?input_text=tell"; closeablehttpclient httpclient = httpclients.createdefault(); httpget httpget = new httpget(servleturl); closeablehttpresponse response = httpclient.execute(httpget); httpentity entity = response.getentity(); string responsebody = getstringfrominputstream(response.getentity().getcontent()); //processing here entityutils.consume(entity); ... 

Comments