I have a controller action where I need to call 3rd party web services.
My problem is that I am not calling one web service. I need to chain between 4 to 5 web services. Each web service I call returns a JSON object which I need to process and based on some logic I decide to either call another web service (from the 4 web services) or return a response to the caller. Here's what I am trying to do:
public static Promise<Result> accounts(){
return WS.url("url1").get().map(response1 -> {
JsonNode mynode = response1.asJson();
if (mynode.get("status").asInt()==200){
Promise<JsonNode> jsonPromise = WS.url("url2").get().map(response2->{
return response2.asJson();
});
}
return ok(mynode);
});
}
Now, from the documentation, I think that what I need is to chain promises where each web service call is a promise. But I am not sure how to do that?
Thanks