Java Code Examples for io.vertx.core.http.HttpClient#get()
The following examples show how to use
io.vertx.core.http.HttpClient#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RESTJerseyClientTimeoutTests.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleTimeoutTest_1() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleTimeoutTest", resp -> { resp.exceptionHandler( error -> { System.out.println("Got a createResponse ERROR: " + error.toString()); }); resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "operation _timeout"); testComplete(); }); }); request.end(); await(); }
Example 2
Source File: RESTVerticleRouteBuilderSelfhostedTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointThree() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointThree?val=123&tmp=456", resp -> { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "123456"); testComplete(); }); }); request.end(); await(); }
Example 3
Source File: RESTServiceBlockingChainStringTest.java From vxms with Apache License 2.0 | 6 votes |
@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()); assertEquals(body.toString(), "1 final"); testComplete(); })); request.end(); await(); }
Example 4
Source File: RESTAsyncThreadCheckStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void statefulTimeoutWithRetryTest_() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/statefulTimeoutWithRetryTest/crash", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "operation _timeout"); testComplete(); })); request.end(); await(); }
Example 5
Source File: RESTServiceExceptionTest.java From vxms with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: RESTJerseyClientEventByteCircuitBreakerAsyncTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleSyncNoConnectionAndExceptionErrorResponseFail() throws InterruptedException { System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT2); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleSyncNoConnectionAndExceptionErrorResponseFail", resp -> { resp.bodyHandler( body -> { System.out.println( "RESPONSE: " + resp.statusMessage() + " " + body.toString()); assertEquals(resp.statusMessage(), "nullpointer in onFailureRespond"); testComplete(); }); }); request.end(); await(); }
Example 7
Source File: RESTJerseyClientTimeoutTests.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleTimeoutNonBlockingTest_1() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleTimeoutNonBlockingTest", resp -> { resp.exceptionHandler( error -> { System.out.println("Got a createResponse ERROR: " + error.toString()); }); resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "failure"); testComplete(); }); }); request.end(); await(); }
Example 8
Source File: RESTAsyncThreadCheck.java From vxms with Apache License 2.0 | 6 votes |
@Test public void statefulTimeoutWithRetryTest_() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/statefulTimeoutWithRetryTest/crash", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "operation _timeout"); testComplete(); })); request.end(); await(); }
Example 9
Source File: RESTServiceSelfhostedTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointFive() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointFive?val=123&tmp=456", resp -> { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); Payload<String> pp = new Gson().fromJson(body.toString(), Payload.class); assertEquals(pp.getValue(), new Payload<>("123" + "456").getValue()); }); testComplete(); }); request.end(); await(); }
Example 10
Source File: RESTServiceExceptionTest.java From vxms with Apache License 2.0 | 6 votes |
@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); }
Example 11
Source File: RESTServiceOnFailureTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleOnFailureResponseBlocking() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleOnFailureResponseBlocking", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { String val = body.getString(0, body.length()); System.out.println("--------catchedAsyncByteErrorDelay: " + val); assertEquals("", val); testComplete(); }); } }); request.end(); await(10000, TimeUnit.MILLISECONDS); }
Example 12
Source File: RESTServiceExceptionTest.java From vxms with Apache License 2.0 | 6 votes |
@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); }
Example 13
Source File: RESTAsyncThreadCheckStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleRetryTest() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleRetryTest", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "test exception"); testComplete(); })); request.end(); await(); }
Example 14
Source File: ResolveServicesByLabelsOKTest.java From vxms with Apache License 2.0 | 5 votes |
@Test public void testServiceByName() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); AtomicBoolean failed = new AtomicBoolean(false); HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/myTestService", resp -> { resp.bodyHandler( body -> { String response = body.toString(); System.out.println("Response entity '" + response + "' received."); vertx.runOnContext( context -> { failed.set( !response.equalsIgnoreCase("192.168.1.1:8080/192.168.1.2:9080")); latch.countDown(); }); }); }); request.end(); latch.await(); assertTrue(!failed.get()); testComplete(); }
Example 15
Source File: ResolveServicesByLAbelsWithPortNameOfflineTest.java From vxms with Apache License 2.0 | 5 votes |
@Test public void testServiceByName() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); AtomicBoolean failed = new AtomicBoolean(false); HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/myTestService", resp -> { resp.bodyHandler( body -> { String response = body.toString(); System.out.println("Response entity '" + response + "' received."); vertx.runOnContext( context -> { failed.set( !response.equalsIgnoreCase( "tcp://192.168.1.1:9090/http://192.168.1.2:9080")); latch.countDown(); }); }); }); request.end(); latch.await(); assertTrue(!failed.get()); testComplete(); }
Example 16
Source File: TypeScriptVerticleTest.java From vertx-lang-typescript with Apache License 2.0 | 5 votes |
private void makeRequest(HttpClient client, int port, int retries, int delay, Handler<AsyncResult<Buffer>> handler) { Vertx vertx = runTestOnContext.vertx(); HttpClientRequest request = client.get(port, "localhost", "/", response -> response.bodyHandler(buffer -> handler.handle(Future.succeededFuture(buffer)))); request.exceptionHandler(t -> { if (retries > 0 && t instanceof ConnectException) { vertx.setTimer(delay, l -> makeRequest(client, port, retries - 1, delay, handler)); } else { handler.handle(Future.failedFuture(t)); } }); request.end(); }
Example 17
Source File: RESTServiceUnhandledExceptionsTest.java From vxms with Apache License 2.0 | 5 votes |
@Test public void unhandledExceptionWithRetryBlocking() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/unhandledExceptionWithRetryBlocking?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 + " CODE: " + resp.statusCode()); // assertEquals(key, "val"); testComplete(); }); } }); request.end(); await(5000, TimeUnit.MILLISECONDS); }
Example 18
Source File: ResolveServicesByLabelOKTest.java From vxms with Apache License 2.0 | 5 votes |
@Test public void testServiceByName() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); AtomicBoolean failed = new AtomicBoolean(false); HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/myTestService", resp -> { resp.bodyHandler( body -> { String response = body.toString(); System.out.println("Response entity '" + response + "' received."); vertx.runOnContext( context -> { failed.set( !response.equalsIgnoreCase("192.168.1.1:8080/192.168.1.2:9080")); latch.countDown(); }); }); }); request.end(); latch.await(); assertTrue(!failed.get()); testComplete(); }
Example 19
Source File: RESTJerseyClientStatefulCircuitBrakerTests.java From vxms with Apache License 2.0 | 4 votes |
@Test public void stringGETResponseCircuitBaseTest() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/stringGETResponseCircuitBaseTest/crash", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "failure"); HttpClientRequest request2 = client.get( "/wsService/stringGETResponseCircuitBaseTest/value", resp2 -> resp2.bodyHandler( body2 -> { System.out.println( "Got a createResponse: " + body2.toString()); assertEquals(body2.toString(), "failure"); // wait 1s, but circuit is still open vertx.setTimer( 1205, handler -> { HttpClientRequest request3 = client.get( "/wsService/stringGETResponseCircuitBaseTest/value", resp3 -> resp3.bodyHandler( body3 -> { System.out.println( "Got a createResponse: " + body3.toString()); assertEquals( body3.toString(), "failure"); // wait another 1s, now circuit // should be closed vertx.setTimer( 2005, handler2 -> { HttpClientRequest request4 = client.get( "/wsService/stringGETResponseCircuitBaseTest/value", resp4 -> resp4.bodyHandler( body4 -> { System.out .println( "Got a createResponse: " + body4 .toString()); assertEquals( body4 .toString(), "value"); // should be // closed testComplete(); })); request4.end(); }); })); request3.end(); }); })); request2.end(); })); request.end(); await(80000, TimeUnit.MILLISECONDS); }
Example 20
Source File: RESTServiceBlockingChainStringTest.java From vxms with Apache License 2.0 | 4 votes |
@Test public void basicTestAndThenWithErrorAndCircuitBreaker() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/crash", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "failure"); HttpClientRequest request2 = client.get( "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value", resp2 -> resp2.bodyHandler( body2 -> { System.out.println( "Got a createResponse: " + body2.toString()); assertEquals(body2.toString(), "failure"); // wait 1s, but circuit is still open vertx.setTimer( 1205, handler -> { HttpClientRequest request3 = client.get( "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value", resp3 -> resp3.bodyHandler( body3 -> { System.out.println( "Got a createResponse: " + body3.toString()); assertEquals( body3.toString(), "failure"); // wait another 1s, now circuit // should be closed vertx.setTimer( 2005, handler2 -> { HttpClientRequest request4 = client.get( "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value", resp4 -> resp4.bodyHandler( body4 -> { System.out .println( "Got a createResponse: " + body4 .toString()); assertEquals( body4 .toString(), "value"); // should be // closed testComplete(); })); request4.end(); }); })); request3.end(); }); })); request2.end(); })); request.end(); await(80000, TimeUnit.MILLISECONDS); }