List of usage examples for io.vertx.core.http HttpClient getNow
@Fluent
default HttpClient getNow(String requestURI, Handler<AsyncResult<HttpClientResponse>> responseHandler)
From source file:examples.HTTPEndpointExamples.java
License:Open Source License
public void example2(ServiceDiscovery discovery) { // Get the record discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> { if (ar.succeeded() && ar.result() != null) { // Retrieve the service reference ServiceReference reference = discovery.getReference(ar.result()); // Retrieve the service object HttpClient client = reference.get(); // You need to path the complete path client.getNow("/api/persons", response -> { // ... // Dont' forget to release the service reference.release();//from w w w . ja v a2s.c o m }); } }); }
From source file:examples.HTTPEndpointExamples.java
License:Open Source License
public void example3(ServiceDiscovery discovery) { HttpEndpoint.getClient(discovery, new JsonObject().put("name", "some-http-service"), ar -> { if (ar.succeeded()) { HttpClient client = ar.result(); // You need to path the complete path client.getNow("/api/persons", response -> { // ... // Dont' forget to release the service ServiceDiscovery.releaseServiceObject(discovery, client); });// w w w .jav a 2s . c om } }); }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example30(Vertx vertx) { // Set the default host HttpClientOptions options = new HttpClientOptions().setDefaultHost("wibble.com"); // Can also set default port if you want... HttpClient client = vertx.createHttpClient(options); client.getNow("/some-uri", response -> { System.out.println("Received response with status code " + response.statusCode()); });//ww w .j a v a 2s . c o m }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example32(Vertx vertx) { HttpClient client = vertx.createHttpClient(); // Send a GET request client.getNow("/some-uri", response -> { System.out.println("Received response with status code " + response.statusCode()); });/*from ww w.j a v a2s .com*/ // Send a GET request client.headNow("/other-uri", response -> { System.out.println("Received response with status code " + response.statusCode()); }); }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example45(HttpClient client) { client.getNow("some-uri", response -> { // the status code - e.g. 200 or 404 System.out.println("Status code is " + response.statusCode()); // the status message e.g. "OK" or "Not Found". System.out.println("Status message is " + response.statusMessage()); });// w w w. j a va 2 s . co m }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example47(HttpClient client) { client.getNow("some-uri", response -> { response.handler(buffer -> {//from w w w . j a v a 2s .c o m System.out.println("Received a part of the response body: " + buffer); }); }); }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example48(HttpClient client) { client.getNow("some-uri", response -> { // Create an empty buffer Buffer totalBuffer = Buffer.buffer(); response.handler(buffer -> {//w w w .j a v a2 s .com System.out.println("Received a part of the response body: " + buffer.length()); totalBuffer.appendBuffer(buffer); }); response.endHandler(v -> { // Now all the body has been read System.out.println("Total response body length is " + totalBuffer.length()); }); }); }
From source file:examples.HTTPExamples.java
License:Open Source License
public void example49(HttpClient client) { client.getNow("some-uri", response -> { response.bodyHandler(totalBuffer -> { // Now all the body has been read System.out.println("Total response body length is " + totalBuffer.length()); });//from www . j a v a2 s . c om }); }
From source file:examples.HTTPExamples.java
License:Open Source License
public void setSSLPerRequest(HttpClient client) { client.getNow(new RequestOptions().setHost("localhost").setPort(8080).setURI("/").setSsl(true), response -> {/* www . j a va2 s. c o m*/ System.out.println("Received response with status code " + response.statusCode()); }); }
From source file:org.entcore.common.neo4j.Neo4jRestNodeClient.java
License:Open Source License
private void checkHealth() { for (int i = 0; i < clients.length; i++) { final int idx = i; HttpClient client = clients[i]; if (client != null) { client.getNow("/db/manage/server/ha/available", new Handler<HttpClientResponse>() { @Override//ww w . j av a 2 s. com public void handle(HttpClientResponse resp) { if (resp.statusCode() == 200) { resp.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer body) { if ("master".equals(body.toString())) { masterNode(idx); } else { slaveNode(idx); } } }); } else { unavailableNode(idx); } } }); } else { unavailableNode(idx); } } }