@Path("3") @GET public void hello3(@Suspended final AsyncResponse asyncResponse, // Inject the Vertx instance @Context Vertx vertx){ System.err.println("Creating client"); HttpClientOptions options = new HttpClientOptions(); options.setSsl(true); options.setTrustAll(true); options.setVerifyHost(false); HttpClient client = vertx.createHttpClient(options); client.getNow(443, "www.google.com", "/robots.txt", resp -> { System.err.println("Got response"); resp.bodyHandler(body -> { System.err.println("Got body"); asyncResponse.resume(Response.ok(body.toString()).build()); }); }); System.err.println("Created client"); }
private HttpClientOptions createHttpClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setConnectTimeout(CONFIG_CENTER_CONFIG.getConnectionTimeout()); if (serverUri.get(0).toLowerCase().startsWith("https")) { LOGGER.debug("service center client performs requests over TLS"); SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration()); SSLOption sslOption; if (factory == null) { sslOption = SSLOption.buildFromYaml(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration()); } else { sslOption = factory.createSSLOption(); } SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass()); VertxTLSBuilder.buildHttpClientOptions(sslOption, sslCustom, httpClientOptions); } return httpClientOptions; }
@Test public void testbuildClientOptionsBaseAuthPeerFalse() { SSLOption option = SSLOption.buildFromYaml("rest.consumer"); SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass()); HttpClientOptions serverOptions = new HttpClientOptions(); new MockUp<SSLOption>() { @Mock public boolean isAuthPeer() { return false; } }; VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions); Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1); Assert.assertEquals(serverOptions.isTrustAll(), true); }
@Test public void testbuildClientOptionsBaseSTORE_JKS() { SSLOption option = SSLOption.buildFromYaml("rest.consumer"); SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass()); HttpClientOptions serverOptions = new HttpClientOptions(); new MockUp<SSLOption>() { @Mock public String getKeyStoreType() { return "JKS"; } }; VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions); Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1); Assert.assertEquals(serverOptions.isTrustAll(), true); }
@Test public void testbuildClientOptionsBaseSTORE_PKCS12() { SSLOption option = SSLOption.buildFromYaml("rest.consumer"); SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass()); HttpClientOptions serverOptions = new HttpClientOptions(); new MockUp<SSLOption>() { @Mock public String getTrustStoreType() { return "PKCS12"; } }; VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions); Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1); Assert.assertEquals(serverOptions.isTrustAll(), true); }
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleWatchTimeout()); if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center ws client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center ws client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; }
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout()); if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) { ProxyOptions proxy = new ProxyOptions(); proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost()); proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort()); proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername()); proxy.setPassword(ServiceRegistryConfig.INSTANCE.getProxyPasswd()); httpClientOptions.setProxyOptions(proxy); } if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; }
@Test public void testPrivateMethodCreateHttpClientOptions() { MicroserviceFactory microserviceFactory = new MicroserviceFactory(); Microservice microservice = microserviceFactory.create("app", "ms"); oClient.registerMicroservice(microservice); oClient.registerMicroserviceInstance(microservice.getInstance()); new MockUp<ServiceRegistryConfig>() { @Mock public HttpVersion getHttpVersion() { return HttpVersion.HTTP_2; } @Mock public boolean isSsl() { return true; } }; try { oClient.init(); HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions"); Assert.assertNotNull(httpClientOptions); Assert.assertEquals(80, httpClientOptions.getDefaultPort()); } catch (Exception e) { Assert.assertNotNull(e); } }
private void setupHttpClient(String connectionToken, String protocolVersion){ if(client != null){ client.close(); } UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromUriString("/signalr/connect"); urlBuilder.queryParam("transport", "webSockets"); urlBuilder.queryParam("clientProtocol", protocolVersion); urlBuilder.queryParam("connectionToken", connectionToken); urlBuilder.queryParam("connectionData", "[{\"name\":\"corehub\"}]"); String endPoint = urlBuilder.build().encode().toUriString(); HttpClientOptions options = new HttpClientOptions(); options.setMaxWebsocketFrameSize(1000000); options.setMaxWebsocketMessageSize(1000000); client = vertx.createHttpClient(options); connectToBittrex(endPoint); }
@Bean public HttpClientOptions httpClientOptions() { final HttpClientOptions options = new HttpClientOptions() .setPipelining(true); if (httpClientProxyHost != null) { final ProxyOptions proxyOptions = new ProxyOptions() .setHost(httpClientProxyHost) .setPort(httpClientProxyPort) .setType(httpClientProxyType) .setUsername(httpClientProxyUsername) .setPassword(httpClientProxyPassword); options.setProxyOptions(proxyOptions); } return options; }
@Before public void setup(TestContext context) { this.vertx = Vertx.vertx(); Router router = Router.router(vertx); router.get("/object").handler(this::getData); router.get("/array").handler(this::getArray); router.get("/400").handler(this::get400); router.get("/badobject").handler(this::getBadObject); router.get("/badarray").handler(this::getBadArray); // TODO: get random available port this.httpServer = vertx.createHttpServer() .requestHandler(router::accept) .listen(port, context.asyncAssertSuccess()); this.httpClient = vertx.createHttpClient( new HttpClientOptions() .setDefaultHost("localhost") .setDefaultPort(port) ); }
/** * @param vertx vertx instance to create the socket from * @param context of execution to run operations that need vertx initialized * @param options Statful options to configure host and port */ public HttpSender(final Vertx vertx, final Context context, final StatfulMetricsOptions options) { super(options, new Sampler(options, new Random())); this.options = options; context.runOnContext(aVoid -> { final HttpClientOptions httpClientOptions = new HttpClientOptions() .setDefaultHost(options.getHost()) .setDefaultPort(options.getPort()) .setSsl(options.isSecure()); this.client = vertx.createHttpClient(httpClientOptions); this.configureFlushInterval(vertx, this.options.getFlushInterval()); }); }
MethodHandler create( final Target<?> target, final MethodMetadata metadata, final RequestTemplate.Factory buildTemplateFromArgs, final HttpClientOptions options, final Decoder decoder, final ErrorDecoder errorDecoder) { return new AsynchronousMethodHandler( target, client, retryer, requestInterceptors, logger, logLevel, metadata, buildTemplateFromArgs, options, decoder, errorDecoder, decode404); }
@Test public void testCORS(TestContext context) { JsonObject config = TestConfig.getApiConfig(); config.getJsonObject("cors").put("enable", true).put("origin", "https://localhost:8888"); deployApiVerticle(context, config); final Async asyncClient = context.async(); String myOrigin = "https://localhost:8888"; HttpClientOptions sslOpts = new HttpClientOptions().setSsl(true) .setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions()); vertx.createHttpClient(sslOpts).get(port, "localhost", "/api/v1.0/pr/latest", res -> { context.assertEquals(200, res.statusCode()); context.assertEquals(myOrigin, res.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); asyncClient.complete(); }).putHeader(HttpHeaders.ORIGIN, myOrigin).end(); }
@Test public void testSslServerAuthentication(TestContext context) { JsonObject config = TestConfig.getApiConfig(); deployApiVerticle(context, config); final Async asyncSslClient = context.async(); HttpClientOptions sslOpts = new HttpClientOptions().setSsl(true) .setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions()); vertx.createHttpClient(sslOpts).get(port, "localhost", "/api/v1.0/pr/latest", res -> { context.assertEquals(200, res.statusCode()); asyncSslClient.complete(); }).end(); final Async asyncClient = context.async(); vertx.createHttpClient().get(port, "localhost", "/api/v1.0/pr/latest", res -> context.fail("Connected to HTTPS connection with HTTP!") ).exceptionHandler(res -> asyncClient.complete() ).end(); }
@Test public void testPaymentRoutes() throws InterruptedException { HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); client.get("/payments").handler(r -> r.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); String response = poll().toString(); JsonArray array = new JsonArray(response); assertEquals(2, array.size()); JsonObject fooPayment = array.getJsonObject(0); assertEquals("foo", fooPayment.getString("id")); assertEquals("1", fooPayment.getString("amount")); client.get("/payments/bar").handler(r -> r.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); response = poll().toString(); JsonObject barPayment = new JsonObject(response); assertEquals("bar", barPayment.getString("id")); assertEquals("100", barPayment.getString("amount")); }
@Test public void testNestedRoutes() throws InterruptedException { HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); client.get("/payments").handler(r -> r.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); String response = poll().toString(); JsonArray array = new JsonArray(response); assertEquals(2, array.size()); JsonObject fooPayment = array.getJsonObject(0); assertEquals("foo", fooPayment.getString("id")); assertEquals("1", fooPayment.getString("amount")); client.get("/payments/bar").handler(r -> r.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); response = poll().toString(); JsonObject barPayment = new JsonObject(response); assertEquals("bar", barPayment.getString("id")); assertEquals("100", barPayment.getString("amount")); // Test ignored routes client.get("/payments/inner").handler(r -> SYNCHRONIZER.add("" + r.statusCode())).end(); assertEquals("404", poll()); client.get("/payments/string").handler(r -> SYNCHRONIZER.add("" + r.statusCode())).end(); assertEquals("404", poll()); }
public TelegramBot(Vertx vertx, TelegramOptions options) { this.vertx = vertx; this.botOptions = options; mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); HttpClientOptions httpOptions = new HttpClientOptions() .setSsl(true) .setTrustAll(true) .setIdleTimeout(this.getOptions().getPollingTimeout()) .setMaxPoolSize(this.getOptions().getMaxConnections()) .setDefaultHost(Util.BASEHOST) .setDefaultPort(443) .setLogActivity(true); if (options.getProxyOptions() != null) httpOptions.setProxyOptions(options.getProxyOptions()); client = vertx.createHttpClient(httpOptions); }
@Test public void test404Response() throws Exception { HttpClientOptions options = new HttpClientOptions(); options.setDefaultHost("localhost"); options.setDefaultPort(port()); HttpClient client = Mesh.vertx().createHttpClient(options); CompletableFuture<String> future = new CompletableFuture<>(); HttpClientRequest request = client.request(HttpMethod.POST, "/api/v1/test", rh -> { rh.bodyHandler(bh -> { future.complete(bh.toString()); }); }); request.end(); String response = future.get(1, TimeUnit.SECONDS); assertTrue("The response string should not contain any html specific characters but it was {" + response + "} ", response.indexOf("<") != 0); }
public HttpModuleClient(String host, int port, String tenantId, boolean keepAlive, int connTO, int idleTO, boolean autoCloseConnections, long cacheTO) { this.tenantId = tenantId; this.cacheTO = cacheTO; this.connTO = connTO; this.idleTO = idleTO; options = new HttpClientOptions().setLogActivity(true).setKeepAlive(keepAlive) .setConnectTimeout(connTO).setIdleTimeout(idleTO); options.setDefaultHost(host); if(port == -1){ absoluteHostAddr = true; } else{ options.setDefaultPort(port); } this.autoCloseConnections = autoCloseConnections; vertx = VertxUtils.getVertxFromContextOrNew(); setDefaultHeaders(); }
public HttpModuleClient2(String host, int port, String tenantId, boolean keepAlive, int connTO, int idleTO, boolean autoCloseConnections, long cacheTO) { this.tenantId = tenantId; this.cacheTO = cacheTO; this.connTO = connTO; this.idleTO = idleTO; options = new HttpClientOptions().setLogActivity(true).setKeepAlive(keepAlive) .setConnectTimeout(connTO).setIdleTimeout(idleTO); options.setDefaultHost(host); if(port == -1){ absoluteHostAddr = true; } else{ options.setDefaultPort(port); } this.autoCloseConnections = autoCloseConnections; vertx = VertxUtils.getVertxFromContextOrNew(); setDefaultHeaders(); httpClient = vertx.createHttpClient(options); }
@Test public void testConfigurationOptions(TestContext testContext) throws Exception { final HttpClientOptions options = new HttpClientOptions().setTryUseCompression(false); final HttpClient httpClient = runTestOnContext.vertx().createHttpClient(options); final Async asyncOp = testContext.async(); // issue a request on the custom server bind address and port, testing for compression httpClient.get(SERVER_PORT, SERVER_BIND_ADDRESS, "/hystrix-dashboard/") .setChunked(false) .putHeader(HttpHeaders.ACCEPT_ENCODING, HttpHeaders.DEFLATE_GZIP) .handler(resp -> { testContext.assertEquals(200, resp.statusCode(), "Should have fetched the index page with status 200"); testContext.assertEquals("gzip", resp.getHeader(HttpHeaders.CONTENT_ENCODING)); }) .exceptionHandler(testContext::fail) .endHandler(event -> asyncOp.complete()) .end(); }
@Test // @Ignore public void basicTestSupplyWithErrorUnhandled() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestSupplyWithErrorUnhandled", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { Assert.assertEquals(resp.statusCode(), 500); Assert.assertEquals(resp.statusMessage(), "test error"); testComplete(); } }); request.end(); await(); }
@Test public void noResponse() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/noResponse?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------noResponse: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(); // request.end(); }
@Test public void exceptionInMethodBody() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/exceptionInMethodBody?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------exceptionInMethodBody: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(); }
@Test public void exceptionInStringResponse() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/exceptionInStringResponse?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------exceptionInStringResponse: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
@Test public void exceptionInByteResponse() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/exceptionInByteResponse?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------exceptionInByteResponse: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
public VertxHawkularOptions() { host = DEFAULT_HOST; port = DEFAULT_PORT; httpOptions = new HttpClientOptions(); metricsServiceUri = DEFAULT_METRICS_URI; tenant = DEFAULT_TENANT; sendTenantHeader = DEFAULT_SEND_TENANT_HEADER; authenticationOptions = new AuthenticationOptions(); httpHeaders = new JsonObject(); schedule = DEFAULT_SCHEDULE; prefix = DEFAULT_PREFIX; batchSize = DEFAULT_BATCH_SIZE; batchDelay = DEFAULT_BATCH_DELAY; metricsBridgeEnabled = DEFAULT_METRICS_BRIDGE_ENABLED; metricsBridgeAddress = DEFAULT_METRICS_BRIDGE_ADDRESS; disabledMetricsTypes = EnumSet.noneOf(MetricsType.class); tags = new JsonObject(); taggedMetricsCacheSize = DEFAULT_TAGGED_METRICS_CACHE_SIZE; metricTagsMatches = new ArrayList<>(); }
@Test // @Ignore public void basicTestAndThenWithErrorUnhandled() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestAndThenWithErrorUnhandled", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { Assert.assertEquals(resp.statusCode(), 500); Assert.assertEquals(resp.statusMessage(), "test error"); testComplete(); } }); request.end(); await(); }
@Test public void exceptionInAsyncStringResponseWithErrorHandler() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/exceptionInAsyncStringResponseWithErrorHandler?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------exceptionInStringResponse: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
@Test // @Ignore public void basicTestSupply() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestSupply", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Assert.assertEquals(body.toString(), "1 final"); testComplete(); })); request.end(); await(); }
@Test public void catchedAsyncByteErrorDelay() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/catchedAsyncByteErrorDelay?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------catchedAsyncByteErrorDelay: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
@Test // @Ignore public void endpointOne() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointOne", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Assert.assertEquals(body.toString(), "1test final"); testComplete(); }); } }); request.end(); await(); }
@Test public void simpleOnFailureResponse() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleOnFailureResponse", resp -> resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------catchedAsyncByteErrorDelay: " + val); assertEquals("on failure", val); testComplete(); })); request.end(); await(10000, TimeUnit.MILLISECONDS); }
@Test public void basicTestSupply() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestSupply", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Assert.assertEquals(body.toString(), "1 final"); testComplete(); })); request.end(); await(); }
@Test public void asyncStringResponse() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/asyncStringResponse", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Assert.assertEquals(body.toString(), "test"); }); testComplete(); } }); request.end(); await(); }
@Test public void exceptionInStringResponseWithErrorHandler() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/exceptionInStringResponseWithErrorHandler?val=123&tmp=456", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------exceptionInStringResponse: " + val); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
@Test public void asyncStringResponseParameter() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/asyncStringResponseParameter/123", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Assert.assertEquals(body.toString(), "123"); }); testComplete(); } }); request.end(); await(); }