@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(); } }); } }
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); client.get(8080, "localhost", "/").send(ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode() + " with data " + response.body().toString("ISO-8859-1")); } else { ar.cause().printStackTrace(); } }); } }
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); Buffer body = Buffer.buffer("Hello World"); client.put(8080, "localhost", "/").sendBuffer(body, ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); } }
@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(); } }); } }
WebClient client = WebClient.create(vertx); 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 -> { if (authHandler.succeeded() && 200 == authHandler.result().statusCode()) { JsonObject authJson = authHandler.result().body(); String accessToken = authJson.getString("access_token"); String header = "Bearer " + accessToken; 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());
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); client.get(8080, "localhost", "/") .as(BodyCodec.json(User.class)) .send(ar -> { if (ar.succeeded()) { HttpResponse<User> response = ar.result(); System.out.println("Got HTTP response body"); User user = response.body(); System.out.println("FirstName " + user.firstName); System.out.println("LastName " + user.lastName); System.out.println("Male " + user.male); } else { ar.cause().printStackTrace(); } }); } }
private void invoke(RoutingContext rc) { client.get("/luke").as(BodyCodec.string()).send(ar -> { if (ar.failed()) { rc.response().end("Unable to call the greeting service: " + ar.cause().getMessage()); } else { if (ar.result().statusCode() != 200) { rc.response().end("Unable to call the greeting service - received status:" + ar.result().statusMessage()); } else { rc.response().end("Greeting service invoked: '" + ar.result().body() + "'"); } } }); } }
protected void connect() { this.client = WebClient.create(vertx, new WebClientOptions() .setSsl(true) // TODO: Fetch CA and use .setTrustAll(true) .setVerifyHost(false)); }
@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", "/").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(); } }); } }
@Override public void start() throws Exception { String filename = "upload.txt"; FileSystem fs = vertx.fileSystem(); WebClient client = WebClient.create(vertx); fs.props(filename, ares -> { FileProps props = ares.result(); System.out.println("props is " + props); long size = props.size(); HttpRequest<Buffer> req = client.put(8080, "localhost", "/"); req.putHeader("content-length", "" + size); fs.open(filename, new OpenOptions(), ares2 -> { req.sendStream(ares2.result(), ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); }); }); } }
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); JsonObject user = new JsonObject() .put("firstName", "Dale") .put("lastName", "Cooper") .put("male", true); client.put(8080, "localhost", "/").sendJson(user, ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); } }
private void mutateResponseHandler(HttpContext context) { if (context.phase() == ClientPhase.DISPATCH_RESPONSE) { HttpResponse<?> resp = context.response(); assertEquals(500, resp.statusCode()); context.response(new HttpResponseImpl<Object>() { @Override public int statusCode() { return 200; } }); } context.next(); }
/** * @return the status message of the response */ public String statusMessage() { if (cached_2 != null) { return cached_2; } String ret = delegate.statusMessage(); cached_2 = ret; return ret; }
/** * Configure the request to use a new method <code>value</code>. * @param value * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.client.HttpRequest<T> method(HttpMethod value) { delegate.method(value); return this; }
@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(); } }); } }
@Override protected void connect() { this.client = WebClient.create(vertx, new WebClientOptions() .setSsl(false) .setTrustAll(true) .setVerifyHost(false)); }
@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(); } }); } }
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); User user = new User(); user.firstName = "Dale"; user.lastName = "Cooper"; user.male = true; client.put(8080, "localhost", "/").sendJson(user, ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); } }