Created
September 7, 2017 14:03
-
-
Save JosePaumard/5799975c42a05f00d6dc892c4013d731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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