public class AuthVertxAPI extends AbstractVerticle { String token; public String login(String username, String password, Vertx vertx) { HttpClientOptions clientOptions = new HttpClientOptions(); HttpClient httpClient = vertx.createHttpClient(clientOptions); final HttpClientRequest req = httpClient.request(HttpMethod.POST, 8080, "localhost", "/some-url", response -> { System.out.println("Got response: " + response.statusCode()); response.bodyHandler(body -> { token = body.toString("ISO-8859-1"); System.out.println("Got data " + body.toString("ISO-8859-1")); }); }); String jsonMessage = "{\"username\": \"admin\", \"password\": \"ofbiz\"}"; req.putHeader("Content-Type", "application/json") .putHeader("Content-Length", "" + jsonMessage.length()) .write(jsonMessage) .end(); return token; }}Hi Arnaud,
Thanks for your reply. But I don't want to execute the above logic asynchronously.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you for your help Ronald van Raaphorst. I will look into the shared details..
Tim : I am writing one utilty class which will hit the authentication server and provide us a token for a valid user. So that I can use that token after immediately calling of utility methods.
On Saturday, June 20, 2015 at 1:19:28 PM UTC+5:30, Ronald van Raaphorst wrote:I suppose you don't want to execute subsequent business logic code while the client is still waiting for the response. But running asynchronous doesn't mean that subsequent code can't be 'on hold' while your authentication call is waiting for an answer.Running asynchronous means that the thread your client http call is running on can be assigned to other stuff for *other* users/calls and is not waiting for the response of the httpclientrequest call while doing nothing. When the answer is received, the thread will be reassigned to this specific call and will continue with whatever you code next.