@Test public void testWebsocketAbs() { SelfSignedCertificate certificate = SelfSignedCertificate.create(); HttpServerOptions serverOptions = new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTPS_PORT) .setSsl(true) .setKeyCertOptions(certificate.keyCertOptions()); HttpClientOptions clientOptions = new HttpClientOptions() .setTrustAll(true) .setVerifyHost(false); client = vertx.createHttpClient(clientOptions); server = vertx.createHttpServer(serverOptions).requestHandler(request -> { if ("/test".equals(request.path())) { request.upgrade().close(); } else { request.response().end(); } }).listen(onSuccess(server -> { String url = "wss://" + clientOptions.getDefaultHost() + ":" + HttpTestBase.DEFAULT_HTTPS_PORT + "/test"; client.websocketAbs(url, null, null, null, ws -> { ws.closeHandler(v -> { testComplete(); }); }, null); })); await(); }
@Test public void testWebsocketAbs() { SelfSignedCertificate certificate = SelfSignedCertificate.create(); HttpServerOptions serverOptions = new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTPS_PORT) .setSsl(true) .setKeyCertOptions(certificate.keyCertOptions()); HttpClientOptions clientOptions = new HttpClientOptions() .setTrustAll(true) .setVerifyHost(false); client = vertx.createHttpClient(clientOptions); server = vertx.createHttpServer(serverOptions).requestHandler(request -> { if ("/test".equals(request.path())) { request.upgrade().close(); } else { request.response().end(); } }).listen(onSuccess(server -> { String url = "wss://" + clientOptions.getDefaultHost() + ":" + HttpTestBase.DEFAULT_HTTPS_PORT + "/test"; client.websocketAbs(url, null, null, null, ws -> { ws.closeHandler(v -> { testComplete(); }); }, null); })); await(); }
/** * Connect a WebSocket with the specified absolute url, with the specified headers, using * the specified version of WebSockets, and the specified websocket sub protocols. * @param url the absolute url * @param headers the headers * @param version the websocket version * @param subProtocols the subprotocols to use * @param wsConnect handler that will be called with the websocket when connected * @param failureHandler handler that will be called if websocket connection fails * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpClient websocketAbs(String url, io.vertx.rxjava.core.MultiMap headers, WebsocketVersion version, String subProtocols, Handler<io.vertx.rxjava.core.http.WebSocket> wsConnect, Handler<Throwable> failureHandler) { delegate.websocketAbs(url, headers.getDelegate(), version, subProtocols, new Handler<io.vertx.core.http.WebSocket>() { public void handle(io.vertx.core.http.WebSocket event) { wsConnect.handle(io.vertx.rxjava.core.http.WebSocket.newInstance(event)); } }, failureHandler); return this; }
/** * Connect a WebSocket with the specified absolute url, with the specified headers, using * the specified version of WebSockets, and the specified websocket sub protocols. * @param url the absolute url * @param headers the headers * @param version the websocket version * @param subProtocols the subprotocols to use * @param wsConnect handler that will be called with the websocket when connected * @param failureHandler handler that will be called if websocket connection fails * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpClient websocketAbs(String url, io.vertx.rxjava.core.MultiMap headers, WebsocketVersion version, String subProtocols, Handler<io.vertx.rxjava.core.http.WebSocket> wsConnect, Handler<Throwable> failureHandler) { delegate.websocketAbs(url, headers.getDelegate(), version, subProtocols, new Handler<io.vertx.core.http.WebSocket>() { public void handle(io.vertx.core.http.WebSocket event) { wsConnect.handle(io.vertx.rxjava.core.http.WebSocket.newInstance(event)); } }, failureHandler); return this; }
@SuppressWarnings("squid:HiddenFieldCheck") private void connectSocket(final String url) { client.websocketAbs(url, null, null, null, socket -> { this.socket = socket; socketOpen = true; catnip.eventBus().publish(Raw.CONNECTED, shardInfo()); socket.frameHandler(this::handleSocketFrame) .closeHandler(this::handleSocketClose) .exceptionHandler(t -> catnip.logAdapter().error("Shard {}/{}: Exception in Websocket", id, limit, t)); }, failure -> { socket = null; socketOpen = false; catnip.logAdapter().error("Shard {}/{}: Couldn't connect socket:", id, limit, failure); catnip.eventBus().publish(Raw.CLOSED, shardInfo()); stateReply(ShardConnectState.FAILED); }); }