I'm using a ClientBuilder to asynchronously perform multiple GET requests from an API.
private static Future<Response> getElevation(Coordinate coordinate) {
double latatude = coordinate.getLatatude();
double longatude = coordinate.getLongatude();
String url = "https://api.open-elevation.com/api/v1/lookup?locations=" + latatude + "%2C%20" + longatude;
System.out.println("URL : " + url);
return ClientBuilder.newClient().target(url).request().async().get();
}
I call the above method and then wait until the request has been complete by using the command ...
.isDone()
on the object of type Future<,Response>. However I don't know how to get the actual response from this. I know it should have the form as such;
{"results": [{"latitude": 53.95798659954082, "elevation": 0, "longitude": -4.306156617942942}]}
I've tride, .getResult.toString() and just .toString(). But cannot see what else there is.
Thank you in advance!
You have to call get()
on the returned Future<Response>
object:
get()
Waits if necessary for the computation to complete, and then retrieves its result.
See the documentation of the Future<V>
Interface.