@Test public void testInvalidAbsoluteURI() { try { client.requestAbs(HttpMethod.GET, "ijdijwidjqwoijd192d192192ej12d", resp -> { }).end(); fail("Should throw exception"); } catch (VertxException e) { //OK } }
private void testSimpleRequest(String uri, HttpMethod method, boolean absolute, Handler<HttpClientResponse> handler) { boolean ssl = this instanceof Http2Test; HttpClientRequest req; if (absolute) { req = client.requestAbs(method, (ssl ? "https://" : "http://") + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT + uri, onSuccess(handler::handle)); } else { req = client.request(method, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, onSuccess(handler::handle)); } testSimpleRequest(uri, method, req, absolute); }
@Test public void requestAbsNoPort() { client.requestAbs(HttpMethod.GET, "http://www.google.com", res -> testComplete()).end(); await(); }
@Test // Client trusts all server certs public void testClearClientRequestAbsSetSSL() throws Exception { String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).requestProvider((c, handler) -> c.requestAbs(HttpMethod.POST, absoluteURI, handler)).pass(); }
@Test // Client trusts all server certs public void testSSLClientRequestAbsSetSSL() throws Exception { String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestProvider((c, handler) -> c.requestAbs(HttpMethod.POST, absoluteURI, handler)).pass(); }
@Test // Client trusts all server certs public void testSSLClientRequestAbsSetClear() throws Exception { String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).serverSSL(false).requestProvider((c, handler) -> c.requestAbs(HttpMethod.POST, absoluteURI, handler)).pass(); }
@Test // Client trusts all server certs public void testClearClientRequestAbsSetClear() throws Exception { String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestProvider((c, handler) -> c.requestAbs(HttpMethod.POST, absoluteURI, handler)).pass(); }
@Test public void testRequestNPE() { String uri = "/some-uri?foo=bar"; TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod)null, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, resp -> {})); TestUtils.assertNullPointerException(() -> client.requestAbs((HttpMethod) null, "http://someuri", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", "/somepath", null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod) null, 8080, "localhost", "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, null, "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", null, resp -> { })); }
private void testSimpleRequest(String uri, HttpMethod method, boolean absolute, Handler<HttpClientResponse> handler) { boolean ssl = this instanceof Http2Test; HttpClientRequest req; if (absolute) { req = client.requestAbs(method, (ssl ? "https://" : "http://") + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT + uri, handler); } else { req = client.request(method, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, handler); } testSimpleRequest(uri, method, req, absolute); }
@Test public void testInvalidAbsoluteURI() { try { client.requestAbs(HttpMethod.GET, "ijdijwidjqwoijd192d192192ej12d", resp -> { }).end(); fail("Should throw exception"); } catch (VertxException e) { //OK } }
@Test public void requestAbsNoPort() { client.requestAbs(HttpMethod.GET, "http://www.google.com", res -> testComplete()).end(); await(); }
@Test // Client trusts all server certs public void testSSLClientRequestAbsSetSSL() throws Exception { String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestProvider(c -> c.requestAbs(HttpMethod.POST, absoluteURI)).pass(); }
@Test // Client trusts all server certs public void testClearClientRequestAbsSetSSL() throws Exception { String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).requestProvider(c -> c.requestAbs(HttpMethod.POST, absoluteURI)).pass(); }
@Test // Client trusts all server certs public void testSSLClientRequestAbsSetClear() throws Exception { String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).serverSSL(false).requestProvider(c -> c.requestAbs(HttpMethod.POST, absoluteURI)).pass(); }
@Test // Client trusts all server certs public void testClearClientRequestAbsSetClear() throws Exception { String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI; testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestProvider(c -> c.requestAbs(HttpMethod.POST, absoluteURI)).pass(); }
@Override public Promise<HttpClientResponse> requestAbs(HttpMethod method, String absoluteURI, RequestOptions options) { RequestFunction func = client -> client.requestAbs(method, absoluteURI); return doRequest(options, func); }
@Override public Promise<HttpClientResponse> requestAbs(HttpMethod method, String absoluteURI, RequestOptions options) { RequestFunction func = client -> client.requestAbs(method, absoluteURI); return doRequest(options, func); }
/** * Create an HTTP request to send to the server using an absolute URI * @param method the HTTP method * @param absoluteURI the absolute URI * @return an HTTP client request object */ public io.vertx.rxjava.core.http.HttpClientRequest requestAbs(HttpMethod method, String absoluteURI) { io.vertx.rxjava.core.http.HttpClientRequest ret = io.vertx.rxjava.core.http.HttpClientRequest.newInstance(delegate.requestAbs(method, absoluteURI)); return ret; }
@Test public void testRequestNPE() { String uri = "/some-uri?foo=bar"; TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod)null, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, resp -> {})); TestUtils.assertNullPointerException(() -> client.requestAbs((HttpMethod) null, "http://someuri", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", "/somepath", null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod) null, 8080, "localhost", "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, null, "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", null, resp -> { })); }
private void runHttpTest() { vertx.createHttpClient() .requestAbs(HttpMethod.GET, "http://localhost:8080/service", response -> { assertEquals(200, response.statusCode()); testComplete(); }) .end(); }