use of io.vertx.reactivex.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class VertxWebClientVerticle method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(80, "perdu.com", "/").rxSend().map(HttpResponse::bodyAsString).subscribe(s -> LOGGER.info("From web client: " + s), Throwable::printStackTrace);
}
use of io.vertx.reactivex.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);
Single<HttpResponse<String>> request = client.get(8080, "localhost", "/").as(BodyCodec.string()).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
}
use of io.vertx.reactivex.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
// Create two requests
WebClient client = WebClient.create(vertx);
Single<JsonObject> request = client.get(8080, "localhost", "/").as(BodyCodec.jsonObject()).rxSend().map(resp -> resp.body());
// Combine the responses with the zip into a single response
request.zipWith(request, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)).subscribe(json -> {
System.out.println("Got combined result " + json);
}, err -> {
err.printStackTrace();
});
}
use of io.vertx.reactivex.ext.web.client.WebClient in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenRequestingGetLocalPath_expectLocalAC.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenRequestingGetLocalPath_expectLocalAC(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), ar.result().statusCode());
context.assertTrue(ar.result().getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, ar.result().getHeader(EXPECTED_RESPONSE_HEADER));
context.assertTrue(ar.result().cookies().stream().anyMatch(cookie -> cookie.contains(CSRFHandler.DEFAULT_COOKIE_NAME)));
client.close();
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
}
use of io.vertx.reactivex.ext.web.client.WebClient in project knotx by Cognifide.
the class HttpClientFacadeTest method whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
final JsonObject expectedResponse = new JsonObject(FileReader.readText("first-response.json"));
// when
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", REQUEST_PATH), clientRequest), HttpMethod.POST);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(expectedResponse, response.getBody().toJsonObject());
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.POST, PORT, DOMAIN, REQUEST_PATH);
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
Aggregations