I am using play2.5 with java 8. I am making POST request to server using
WSRequest request = ws.url("http://abababa .com");
WSRequest complexRequest = request.setHeader("X-API-Key", "xxxxxx")
.setHeader("Content-Type", "application/x-www-form-urlencoded")
CompletionStage<WSResponse> responsePromise = complexRequest.post("grant_type=password"
+ "&username=xxxxx&password=yyyyy");
CompletionStage<JsonNode> jsonPromise = responsePromise.thenApply(WSResponse::asJson);
How do I print the final response of the response. I want to return part of the response to this function. Should the function which called this function also have different code compared to synchronous code?
The stage of completion is an indicator of progress and determines for an operation, work package, or project the ratio of the delivered output to the planned total output. As a percentage, it expresses the proportion of work performed that is part of an agreed total output.
A stage of a possibly asynchronous computation, that performs an action or computes a value when another CompletionStage completes. A stage completes upon termination of its computation, but this may in turn trigger other dependent stages.
Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier. Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.
jsonPromise.toCompletableFuture().get()
JsonNode jsonData = jsonPromise.toCompletableFuture().get()
I tried the code above but i get compiler error, to return JsonNode data, then i used
JsonNode jsonData = jsonPromise.toCompletableFuture().join()
and it works fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With