Skip to content

Instantly share code, notes, and snippets.

@JosePaumard
Created September 7, 2017 14:03
Show Gist options
  • Save JosePaumard/5799975c42a05f00d6dc892c4013d731 to your computer and use it in GitHub Desktop.
Save JosePaumard/5799975c42a05f00d6dc892c4013d731 to your computer and use it in GitHub Desktop.
public void getJson(@Suspended final AsyncResponse async) throws NoSuchAlgorithmException, KeyManagementException {
Client client = getUnsecureClient();
LocationDetails locDetails = new LocationDetails();
CompletionStage<JsonObject> cfIp = client.target("http://api.ipify.org/")
.queryParam("format", "json")
.request()
.rx()
.get(JsonObject.class);
Function<JsonObject, CompletionStage<JsonObject>> function = ip ->
client.target("https://ipvigilante.com")
.path("json").path(ip.getString("ip"))
.request()
.rx()
.get(JsonObject.class);
Consumer<JsonObject> consumer = location ->
async.resume(locDetails.updateWithLocation(location).get().orElse("???"));
cfIp.thenCompose(function)
.thenAccept(consumer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment