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<Data>> request = client.get(8080, "localhost", "/").as(BodyCodec.json(Data.class)).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
use of io.vertx.reactivex.ext.web.client.WebClient in project knotx by Cognifide.
the class HttpClientFacadeTest method whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
// when
Single<ClientResponse> result = clientFacade.process(new AdapterRequest().setParams(new JsonObject()).setRequest(clientRequest), HttpMethod.POST);
// then
result.doOnError(error -> {
context.assertEquals("Parameter `path` was not defined in `params`!", error.getMessage());
Mockito.verify(mockedWebClient, Mockito.times(0)).request(Matchers.any(), Matchers.anyInt(), Matchers.anyString(), Matchers.anyString());
}).subscribe(response -> context.fail("Error should occur!"), error -> async.complete());
}
use of io.vertx.reactivex.ext.web.client.WebClient in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenDoPostSecureWithCSRF_expectOK.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostSecureWithCSRF_expectOK(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
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()) {
String token = getToken(ar.result().cookies());
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").putHeader(CSRFHandler.DEFAULT_HEADER_NAME, token).sendForm(body, res -> {
if (res.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), res.result().statusCode());
async.complete();
} else {
context.fail(ar.cause());
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 KnotxServerCsrfTest method whenDoPostSecureWithoutCSRF_expectForbidden.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostSecureWithoutCSRF_expectForbidden(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").sendForm(body, ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.FORBIDDEN.code(), ar.result().statusCode());
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 KnotxServerCsrfTest method whenDoPostPublicWithoutCSRF_expectOk.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostPublicWithoutCSRF_expectOk(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html").sendForm(body, ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), ar.result().statusCode());
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
}
Aggregations