io.vertx.core.http.HttpClient Java Examples
The following examples show how to use
io.vertx.core.http.HttpClient.
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: RESTServiceBlockingChainStringTest.java From vxms with Apache License 2.0 | 6 votes |
@Test // @Ignore public void basicTestSupplyWithError() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestSupplyWithError", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "error test error"); testComplete(); }); } }); request.end(); await(); }
Example #2
Source File: RESTServiceBlockingChainByteTest.java From vxms with Apache License 2.0 | 6 votes |
@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()); assertEquals(body.toString(), "1test final"); testComplete(); }); } }); request.end(); await(); }
Example #3
Source File: RESTServiceChainByteTest.java From vxms with Apache License 2.0 | 6 votes |
@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) { assertEquals(resp.statusCode(), 500); assertEquals(resp.statusMessage(), "test error"); testComplete(); } }); request.end(); await(); }
Example #4
Source File: RESTJerseyClientEventStringResponseAsyncTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void complexErrorResponseTest() 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/complexErrorResponse", resp -> { resp.bodyHandler( body -> { System.out.println("Got a createResponse" + body.toString()); assertEquals(body.toString(), "test exception"); }); testComplete(); }); request.end(); await(); }
Example #5
Source File: RESTJerseyClientEventObjectCircuitBreakerAsyncTest.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 #6
Source File: RESTVerticleRouteBuilderSelfhostedTestStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointEight_header() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointEight_header?val=123&tmp=456", resp -> { resp.bodyHandler( body -> { System.out.println( "Got a createResponse endpointFourErrorReturnRetryTest: " + body.toString()); assertEquals(body.toString(), "123456"); }); String contentType = resp.getHeader("Content-Type"); assertEquals(contentType, "application/json"); testComplete(); }); request.end(); await(); }
Example #7
Source File: HttpTermServerBase.java From vertx-shell with Apache License 2.0 | 6 votes |
@Test public void testDifferentCharset(TestContext context) throws Exception { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080).setCharset("ISO_8859_1")); server.termHandler(term -> { term.write("\u20AC"); term.close(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); WebSocketConnectOptions options = new WebSocketConnectOptions() .setPort(8080) .setURI(basePath + "/shell/websocket") .addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())); client.webSocket(options, context.asyncAssertSuccess(ws -> { ws.handler(buf -> { context.assertTrue(Arrays.equals(new byte[]{63}, buf.getBytes())); async.complete(); }); })); })); }
Example #8
Source File: HttpTermServerBase.java From vertx-shell with Apache License 2.0 | 6 votes |
private void testResize(TestContext context, JsonObject event, int expectedCols, int expectedRows) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.termHandler(term -> { term.resizehandler(v -> { context.assertEquals(expectedCols, term.width()); context.assertEquals(expectedRows, term.height()); async.complete(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.webSocket(8080, "localhost", basePath + "/shell/websocket", context.asyncAssertSuccess(ws -> { ws.writeFinalTextFrame(event.encode()); })); })); }
Example #9
Source File: RESTAsyncThreadCheckStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleTest() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleTest", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "test exception"); testComplete(); })); request.end(); await(); }
Example #10
Source File: RESTServiceSelfhostedTestStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointTwo() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointTwo/123", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "123"); testComplete(); })); request.end(); await(); }
Example #11
Source File: PauseResumeTest.java From okapi with Apache License 2.0 | 6 votes |
@Test public void test2(TestContext context) { Async async = context.async(); HttpClient cli = vertx.createHttpClient(); HttpClientRequest req = HttpClientLegacy.post(cli, PORT, "localhost", "/test2", res -> { Buffer b = Buffer.buffer(); res.handler(b::appendBuffer); res.endHandler(res2 -> { context.assertEquals("OK2", b.toString()); context.assertEquals(200, res.statusCode()); async.complete(); }); }); req.end("foo"); }
Example #12
Source File: RESTServiceSelfhostedTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointEight_header() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointEight_header?val=123&tmp=456", resp -> { resp.bodyHandler( body -> { System.out.println( "Got a createResponse endpointFourErrorReturnRetryTest: " + body.toString()); assertEquals(body.toString(), "123456"); }); String contentType = resp.getHeader("Content-Type"); assertEquals(contentType, "application/json"); testComplete(); }); request.end(); await(); }
Example #13
Source File: RESTVerticleRouteBuilderSelfhostedTestStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointFourErrorRetryTest() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointFourErrorRetryTest?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 #14
Source File: RESTVerticleRouteBuilderSelfhostedTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void endpointFive_error() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/endpointFive_error?val=123&tmp=456", resp -> { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); if(resp.statusCode()!=200) { fail(); } Payload<String> pp = new Gson().fromJson(body.toString(), Payload.class); assertEquals(pp.getValue(), new Payload<>("123" + "456").getValue()); testComplete(); }); }); request.end(); await(); }
Example #15
Source File: KueRestApiTest.java From vertx-kue with Apache License 2.0 | 6 votes |
@Test public void testApiCreateJob(TestContext context) throws Exception { Vertx vertx = Vertx.vertx(); HttpClient client = vertx.createHttpClient(); Async async = context.async(); Job job = kue.createJob(TYPE, new JsonObject().put("data", TYPE + ":data")); client.put(PORT, HOST, "/job", response -> { context.assertEquals(201, response.statusCode()); response.bodyHandler(body -> { context.assertEquals(new JsonObject(body.toString()).getString("message"), "job created"); client.close(); async.complete(); }); }).putHeader("content-type", "application/json") .end(job.toString()); }
Example #16
Source File: RESTServiceBlockingChainByteTest.java From vxms with Apache License 2.0 | 6 votes |
@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) { assertEquals(resp.statusCode(), 500); assertEquals(resp.statusMessage(), "test error"); testComplete(); } }); request.end(); await(); }
Example #17
Source File: RESTAsyncThreadCheckStaticInitializer.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleTimeoutWithRetryTest() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/simpleTimeoutWithRetryTest", resp -> resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "operation _timeout"); testComplete(); })); request.end(); await(); }
Example #18
Source File: RESTJerseyClientEventStringCircuitBreakerAsyncTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleSyncNoConnectionErrorResponseTest() 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/simpleSyncNoConnectionErrorResponse", resp -> { resp.bodyHandler( body -> { assertEquals(body.toString(), "No handlers for address hello1"); testComplete(); }); }); request.end(); await(); }
Example #19
Source File: RESTServiceChainStringTest.java From vxms with Apache License 2.0 | 6 votes |
@Test // @Ignore public void basicTestAndThen() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestAndThen", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "2 final"); testComplete(); }); } }); request.end(); await(); }
Example #20
Source File: RESTJerseyMimeTypeClientTests.java From vxms with Apache License 2.0 | 6 votes |
@Test public void stringGETResponse_1() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client .get( "/wsService/stringGETConsumesResponse/123", resp -> { resp.exceptionHandler(error -> {}); resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "123"); testComplete(); }); }) .putHeader("Content-Type", "application/json;charset=UTF-8"); request.end(); await(); }
Example #21
Source File: HttpConnector.java From apiman with Apache License 2.0 | 6 votes |
/** * Construct an {@link HttpConnector} instance. The {@link #resultHandler} must remain exclusive to a * given instance. * * @param vertx a vertx * @param client the vertx http client * @param api an API * @param request a request with fields filled * @param options the connector options * @param connectorConfig the dynamic connector configuration as possibly modified by policies * @param resultHandler a handler, called when reading is permitted */ public HttpConnector(Vertx vertx, HttpClient client, ApiRequest request, Api api, ApimanHttpConnectorOptions options, IConnectorConfig connectorConfig, IAsyncResultHandler<IApiConnectionResponse> resultHandler) { this.client = client; this.api = api; this.apiRequest = request; this.connectorConfig = connectorConfig; this.resultHandler = resultHandler; this.exceptionHandler = new ExceptionHandler(); this.apiEndpoint = options.getUri(); this.options = options; apiHost = apiEndpoint.getHost(); apiPort = getPort(); apiPath = apiEndpoint.getPath().isEmpty() || apiEndpoint.getPath().equals("/") ? "" : apiEndpoint.getPath(); destination = apiRequest.getDestination() == null ? "" : apiRequest.getDestination(); verifyConnection(); }
Example #22
Source File: RESTJerseyClientEventStringCircuitBreakerTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void simpleSyncNoConnectionErrorResponseTest() 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/simpleSyncNoConnectionErrorResponse", resp -> { resp.bodyHandler( body -> { assertEquals(body.toString(), "No handlers for address hello1"); testComplete(); }); }); request.end(); await(); }
Example #23
Source File: PauseResumeTest.java From okapi with Apache License 2.0 | 6 votes |
@Test public void test3(TestContext context) { Async async = context.async(); HttpClient cli = vertx.createHttpClient(); HttpClientRequest req = HttpClientLegacy.post(cli, PORT, "localhost", "/test2", res -> { Buffer b = Buffer.buffer(); res.handler(b::appendBuffer); res.endHandler(res2 -> { context.assertEquals("OK2", b.toString()); context.assertEquals(200, res.statusCode()); async.complete(); }); }); req.end(); async.await(); }
Example #24
Source File: RESTServiceChainByteTest.java From vxms with Apache License 2.0 | 6 votes |
@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) { assertEquals(resp.statusCode(), 500); assertEquals(resp.statusMessage(), "test error"); testComplete(); } }); request.end(); await(); }
Example #25
Source File: RESTServiceChainStringTest.java From vxms with Apache License 2.0 | 6 votes |
@Test // @Ignore public void basicTestAndThenWithErrorUnhandledRetry() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestAndThenWithErrorUnhandledRetry", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "error 4 test error"); testComplete(); }); } }); request.end(); await(); }
Example #26
Source File: RESTServiceSelfhostedAsyncTest.java From vxms with Apache License 2.0 | 6 votes |
@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", resp -> { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "123"); testComplete(); }); }); request.end(); await(); }
Example #27
Source File: MultipartRequestTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Test public void testSingleUploadMutation() { final HttpClient client = vertx.createHttpClient(getHttpClientOptions()); final Buffer bodyBuffer = vertx.fileSystem().readFileBlocking("singleUpload.txt"); client.post(new RequestOptions() .setURI("/graphql") .setTimeout(10000) .addHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryBpwmk50wSJmsTPAH") .addHeader("accept", "application/json"), bodyBuffer, response -> response.result().bodyHandler(buffer -> { final JsonObject json = ((JsonObject) buffer.toJson()).getJsonObject("data").getJsonObject("singleUpload"); assertEquals("a.txt", json.getString("id")); complete(); })); await(); }
Example #28
Source File: TofuSecurityTest.java From orion with Apache License 2.0 | 6 votes |
@Test void testWithoutSSLConfiguration() { final CompletableAsyncResult<HttpClientResponse> result = AsyncResult.incomplete(); final HttpClient insecureClient = vertx.createHttpClient(new HttpClientOptions().setSsl(true)); final HttpClientRequest req = insecureClient.get(config.nodePort(), "localhost", "/upcheck"); req.handler(result::complete).exceptionHandler(result::completeExceptionally).end(); final CompletionException e = assertThrows(CompletionException.class, result::get); assertTrue(e.getCause() instanceof SSLHandshakeException); final HttpClientRequest clientRequest = insecureClient.get(config.clientPort(), "localhost", "/upcheck"); clientRequest.handler(result::complete).exceptionHandler(result::completeExceptionally).end(); final CompletionException clientException = assertThrows(CompletionException.class, result::get); assertTrue(clientException.getCause() instanceof SSLHandshakeException); }
Example #29
Source File: RESTServiceChainStringTest.java From vxms with Apache License 2.0 | 6 votes |
@Test // @Ignore public void basicTestAndThenWithError() throws InterruptedException { HttpClientOptions options = new HttpClientOptions(); options.setDefaultPort(PORT); options.setDefaultHost(HOST); HttpClient client = vertx.createHttpClient(options); HttpClientRequest request = client.get( "/wsService/basicTestAndThenWithError", new Handler<HttpClientResponse>() { public void handle(HttpClientResponse resp) { resp.bodyHandler( body -> { System.out.println("Got a createResponse: " + body.toString()); assertEquals(body.toString(), "error test error"); testComplete(); }); } }); request.end(); await(); }
Example #30
Source File: TenantLoading.java From raml-module-builder with Apache License 2.0 | 5 votes |
private static void loadData(String okapiUrl, Map<String, String> headers, LoadingEntry loadingEntry, HttpClient httpClient, Handler<AsyncResult<Integer>> res) { String filePath = loadingEntry.lead; if (!loadingEntry.filePath.isEmpty()) { filePath = filePath + '/' + loadingEntry.filePath; } final String endPointUrl = okapiUrl + "/" + loadingEntry.uriPath; try { List<URL> urls = getURLsFromClassPathDir(filePath); if (urls.isEmpty()) { log.warn("loadData getURLsFromClassPathDir returns empty list for path=" + filePath); } Future<Void> future = Future.succeededFuture(); for (URL url : urls) { future = future.compose(x -> { Promise<Void> p = Promise.promise(); loadURL(headers, url, httpClient, loadingEntry, endPointUrl, p.future()); return p.future(); }); } future.onComplete(x -> { if (x.failed()) { res.handle(Future.failedFuture(x.cause().getLocalizedMessage())); } else { res.handle(Future.succeededFuture(urls.size())); } }); } catch (URISyntaxException|IOException ex) { log.error("Exception for path " + filePath, ex); res.handle(Future.failedFuture("Exception for path " + filePath + " ex=" + ex.getMessage())); } }