@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 ); } }
@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())); } }
@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)); } }
@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(); }); } }
Http(String host, NetworkHttp networkHttp) throws MalformedURLException { this.url = new URL(host); final Vertx vertx = Vertx.vertx(); this.client = WebClient.create(vertx); objectMapper.configure(DeserializationFeature.USE_LONG_FOR_INTS, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.networkHttp = networkHttp; }
@Bean public WebClient webClient() { WebClientOptions options = new WebClientOptions() .setConnectTimeout(Integer.valueOf(properties.getProperty("oidc.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("oidc.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))) .setTrustAll(Boolean.valueOf(properties.getProperty("oidc.http.client.trustAll", "true"))); return WebClient.create(vertx,options); } }
@Bean public WebClient httpClient() { WebClientOptions httpClientOptions = new WebClientOptions(); httpClientOptions .setUserAgent(DEFAULT_USER_AGENT) .setConnectTimeout(Integer.valueOf(properties.getProperty("identities.oauth2.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("identities.oauth2.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))); return WebClient.create(vertx, httpClientOptions); } }
@Bean public WebClient httpClient() { WebClientOptions httpClientOptions = new WebClientOptions(); httpClientOptions .setUserAgent(DEFAULT_USER_AGENT) .setConnectTimeout(Integer.valueOf(properties.getProperty("identities.oauth2.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("identities.oauth2.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))); return WebClient.create(vertx, httpClientOptions); } }
@Bean public WebClient httpClient() { WebClientOptions httpClientOptions = new WebClientOptions(); httpClientOptions .setUserAgent(DEFAULT_USER_AGENT) .setConnectTimeout(Integer.valueOf(properties.getProperty("identities.github.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("identities.github.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))); return WebClient.create(vertx, httpClientOptions); } }
public HttpActionAdapterProxyImpl(Vertx vertx, ServiceAdapterOptions configuration) { this.httpClientFacade = new HttpClientFacade( WebClient.create(vertx, configuration.getClientOptions()), configuration); }
public FormsAdapterProxyImpl(Vertx vertx, HttpFormsAdapterOptions configuration) { this.httpClientFacade = new HttpClientFacade( WebClient.create(vertx, configuration.getClientOptions()), configuration); }
@Bean public WebClient httpClient() { WebClientOptions httpClientOptions = new WebClientOptions(); httpClientOptions .setUserAgent(DEFAULT_USER_AGENT) .setConnectTimeout(Integer.valueOf(properties.getProperty("identities.github.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("identities.github.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))); return WebClient.create(vertx, httpClientOptions); } }
public HttpServiceAdapterProxyImpl(Vertx vertx, ServiceAdapterOptions configuration) { this.httpClientFacade = new HttpClientFacade( WebClient.create(vertx, configuration.getClientOptions()), configuration); }
public HttpDataSourceAdapterProxy(Vertx vertx, HttpDataSourceAdapterOptions configuration) { this.httpClientFacade = new HttpClientFacade( WebClient.create(vertx, configuration.getClientOptions()), configuration); }
public HttpServiceAdapterProxyImpl(Vertx vertx, ServiceAdapterOptions configuration) { this.httpClientFacade = new HttpClientFacade( WebClient.create(vertx, configuration.getClientOptions()), configuration); }
private Single<String> get(Vertx vertx, URI uri){ WebClient client = WebClient.create(vertx); Single<HttpResponse<Buffer>> responseHandler = client.get(uri.getPort(), uri.getHost(), uri.getPath()).rxSend(); return responseHandler.map(response -> response.body().toString()) .doAfterTerminate(() -> client.close()); }
private void testPostRequest(VertxTestContext context, Vertx vertx, String url, Consumer<HttpResponse<Buffer>> expectedResponse) { WebClient client = WebClient.create(vertx); MultiMap formData = MultiMap.caseInsensitiveMultiMap(); formData.add("a", "b"); Single<HttpResponse<Buffer>> httpResponseSingle = client .post(KnotxServerRoutingTest.KNOTX_SERVER_PORT, KnotxServerRoutingTest.KNOTX_SERVER_ADDRESS, url) .rxSendForm(formData); subscribeToResult_shouldSucceed(context, httpResponseSingle, expectedResponse); }
private void testGetRequest(VertxTestContext context, Vertx vertx, String url, String expectedResult) { WebClient client = WebClient.create(vertx); Single<HttpResponse<Buffer>> httpResponseSingle = client .get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url).rxSend(); subscribeToResult_shouldSucceed(context, httpResponseSingle, resp -> { assertEquals(expectedResult, resp.body().toString(), "Wrong engines processed request, expected " + expectedResult); assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); }); }
@Test @KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json") public void whenDoPostPublicWithoutCSRF_expectOk( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleKnot(vertx, "some-knot", "test", null); MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value"); WebClient client = WebClient.create(vertx); Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> httpResponseSingle = client .post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html") .rxSendForm(body); subscribeToResult_shouldSucceed(context, httpResponseSingle, resp -> { assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); }); }