@Override public WebSocketStream websocketStreamAbs(String url, MultiMap headers, WebsocketVersion version, String subProtocols) { URI uri; try { uri = new URI(url); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } String scheme = uri.getScheme(); if (!"ws".equals(scheme) && !"wss".equals(scheme)) { throw new IllegalArgumentException("Scheme: " + scheme); } boolean ssl = scheme.length() == 3; int port = uri.getPort(); if (port == -1) port = ssl ? 443 : 80; StringBuilder relativeUri = new StringBuilder(); if (uri.getRawPath() != null) { relativeUri.append(uri.getRawPath()); } if (uri.getRawQuery() != null) { relativeUri.append('?').append(uri.getRawQuery()); } if (uri.getRawFragment() != null) { relativeUri.append('#').append(uri.getRawFragment()); } RequestOptions options = new RequestOptions().setHost(uri.getHost()).setPort(port).setSsl(ssl).setURI(relativeUri.toString()); return websocketStream(options, headers, version, subProtocols); }
/** * Create options from JSON * * @param json the JSON */ public RequestOptions(JsonObject json) { setHost(json.getString("host", DEFAULT_HOST)); setPort(json.getInteger("port", DEFAULT_PORT)); setSsl(json.getBoolean("ssl", DEFAULT_SSL)); setURI(json.getString("uri", DEFAULT_URI)); }
/** * Copy constructor * * @param other the options to copy */ public RequestOptions(RequestOptions other) { setHost(other.host); setPort(other.port); setSsl(other.ssl); setURI(other.uri); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(true); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, false, true, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(true); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, true, true, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, false, false, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, true, false, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(4043).setURI(DEFAULT_TEST_URI).setSsl(true); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).requestOptions(options).pass(); }
@Test public void testRedirectToSSL() throws Exception { HttpServer redirectServer = vertx.createHttpServer(new HttpServerOptions() .setHost(DEFAULT_HTTP_HOST) .setPort(DEFAULT_HTTP_PORT) ).requestHandler(req -> { req.response().setStatusCode(303).putHeader("location", "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end(); }); startServer(redirectServer); RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(DEFAULT_HTTP_PORT); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE) .clientSSL(false) .serverSSL(true) .requestOptions(options) .followRedirects(true) .pass(); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(4043).setURI(DEFAULT_TEST_URI).setSsl(true); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestOptions(options).pass(); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestOptions(options).pass(); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).serverSSL(false).requestOptions(options).pass(); }
@Test public void testRedirectFromSSL() throws Exception { HttpServer redirectServer = vertx.createHttpServer(new HttpServerOptions() .setSsl(true) .setKeyStoreOptions(Cert.SERVER_JKS.get()) .setHost(DEFAULT_HTTP_HOST) .setPort(DEFAULT_HTTP_PORT) ).requestHandler(req -> { req.response().setStatusCode(303).putHeader("location", "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end(); }); startServer(redirectServer); RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.NONE, Trust.NONE) .clientSSL(true) .serverSSL(false) .requestOptions(options) .followRedirects(true) .pass(); } }
.setPort(DEFAULT_HTTP_PORT) .setHost(DEFAULT_HTTP_HOST) .setURI(DEFAULT_TEST_URI);
/** * Create options from JSON * * @param json the JSON */ public RequestOptions(JsonObject json) { setHost(json.getString("host", DEFAULT_HOST)); setPort(json.getInteger("port", DEFAULT_PORT)); setSsl(json.getBoolean("ssl", DEFAULT_SSL)); setURI(json.getString("uri", DEFAULT_URI)); }
/** * Copy constructor * * @param other the options to copy */ public RequestOptions(RequestOptions other) { setHost(other.host); setPort(other.port); setSsl(other.ssl); setURI(other.uri); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, true, false, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(HttpTestBase.DEFAULT_HTTP_HOST).setURI("/").setPort(4043).setSsl(true); testTLS(Cert.NONE, Trust.NONE, Cert.SERVER_JKS, Trust.NONE, false, false, true, false, true, false, true, false, new String[0], client -> client.websocketStream(options)); }
@Test // Client trusts all server certs public void testSSLClientRequestOptionsSetSSL() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(4043).setURI(DEFAULT_TEST_URI).setSsl(true); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestOptions(options).pass(); }
@Test // Client trusts all server certs public void testClearClientRequestOptionsSetClear() throws Exception { RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false); testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestOptions(options).pass(); }