use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
// Create the web client and enable SSL/TLS with a trust store
WebClient client = WebClient.create(vertx, new WebClientOptions().setSsl(true).setTrustStoreOptions(new JksOptions().setPath("client-truststore.jks").setPassword("wibble")));
client.get(8443, "localhost", "/").send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class TwitterOAuthExample method start.
@Override
public void start() throws Exception {
// Create the web client.
WebClient client = WebClient.create(vertx);
String queryToSearch = "vertx";
// First we need to authenticate our call.
String authHeader = "Basic " + B64_ENCODED_AUTH;
client.postAbs(AUTH_URL).as(BodyCodec.jsonObject()).addQueryParam("grant_type", "client_credentials").putHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8").putHeader("Authorization", authHeader).send(authHandler -> {
// Authentication successful.
if (authHandler.succeeded() && 200 == authHandler.result().statusCode()) {
JsonObject authJson = authHandler.result().body();
String accessToken = authJson.getString("access_token");
String header = "Bearer " + accessToken;
// Making call to search tweets.
client.getAbs(TWEET_SEARCH_URL).as(BodyCodec.jsonObject()).addQueryParam("q", queryToSearch).putHeader("Authorization", header).send(handler -> {
if (handler.succeeded() && 200 == handler.result().statusCode()) {
System.out.println(handler.result().body());
} else {
System.out.println(handler.cause().getMessage());
}
});
} else {
// Authentication failed
System.out.println(authHandler.cause().getMessage());
}
});
}
use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/").addQueryParam("firstName", "Dale").addQueryParam("lastName", "Cooper").addQueryParam("male", "true").send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("firstName", "Dale");
form.add("lastName", "Cooper");
form.add("male", "true");
client.post(8080, "localhost", "/").putHeader("content-type", "multipart/form-data").sendForm(form, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/").as(BodyCodec.jsonObject()).send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
System.out.println("Got HTTP response body");
System.out.println(response.body().encodePrettily());
} else {
ar.cause().printStackTrace();
}
});
}
Aggregations