@Test public void testReportProtocolViolationOnServer() { server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { AtomicReference<Throwable> failure = new AtomicReference<>(); ws.closeHandler(v -> { assertNotNull(failure.get()); testComplete(); }); ws.exceptionHandler(failure::set); }); server.listen(ar -> { assertTrue(ar.succeeded()); handshake(sock -> { // Let's write an invalid frame Buffer buff = Buffer.buffer(); buff.appendByte((byte)(0x8)).appendByte((byte)0); // Violates protocol with V13 (final control frame) sock.write(buff); }); }); await(); }
public SockJSSocket exceptionHandler(Handler<Throwable> handler) { ws.exceptionHandler(handler); return this; }
@Test public void testInvalidUnmaskedFrameRequest(){ client = vertx.createHttpClient(new HttpClientOptions().setSendUnmaskedFrames(true)); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)); server.requestHandler(req -> { req.response().setChunked(true).write("connect"); }); server.websocketHandler(ws -> { ws.exceptionHandler(exception -> { testComplete(); }); ws.handler(result -> { fail("Cannot decode unmasked message because I require masked frame as configured"); }); }); server.listen(onSuccess(server -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.writeFinalTextFrame("first unmasked frame"); }); })); await(); }
WebSocketListener(ServerWebSocket ws, SockJSSession session) { this.ws = ws; this.session = session; ws.textMessageHandler(this::handleMessages); ws.closeHandler(v -> { closed = true; session.shutdown(); }); ws.exceptionHandler(t -> { closed = true; session.shutdown(); session.handleException(t); }); }
public SockJSSocket exceptionHandler(Handler<Throwable> handler) { ws.exceptionHandler(handler); return this; }
public SockJSSocket exceptionHandler(Handler<Throwable> handler) { ws.exceptionHandler(handler); return this; }
public SockJSSocket exceptionHandler(Handler<Throwable> handler) { ws.exceptionHandler(handler); return this; }
public io.vertx.rxjava.core.http.ServerWebSocket exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
public io.vertx.rxjava.core.http.ServerWebSocket exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
@Test public void testReportProtocolViolationOnServer() { server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { AtomicReference<Throwable> failure = new AtomicReference<>(); ws.closeHandler(v -> { assertNotNull(failure.get()); testComplete(); }); ws.exceptionHandler(failure::set); }); server.listen(ar -> { assertTrue(ar.succeeded()); HttpClientRequest request = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/some/path"); handshake(request, sock -> { // Let's write an invalid frame Buffer buff = Buffer.buffer(); buff.appendByte((byte)(0x8)).appendByte((byte)0); // Violates protocol with V13 (final control frame) sock.write(buff); }); }); await(); }
@Test public void testInvalidUnmaskedFrameRequest(){ client = vertx.createHttpClient(new HttpClientOptions().setSendUnmaskedFrames(true)); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)); server.requestHandler(req -> { req.response().setChunked(true).write("connect"); }); server.websocketHandler(ws -> { ws.exceptionHandler(exception -> { testComplete(); }); ws.handler(result -> { fail("Cannot decode unmasked message because I require masked frame as configured"); }); }); server.listen(onSuccess(server -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.writeFinalTextFrame("first unmasked frame"); }); })); await(); }
vertxServerWebSocket.exceptionHandler(event -> { if (event instanceof Exception) { webSocket.onError((Exception) event);
WebSocketListener(ServerWebSocket ws, Session session) { this.ws = ws; this.session = session; ws.handler(data -> { if (!session.isClosed()) { String msgs = data.toString(); if (msgs.equals("")) { //Ignore empty frames } else if ((msgs.startsWith("[\"") && msgs.endsWith("\"]")) || (msgs.startsWith("\"") && msgs.endsWith("\""))) { session.handleMessages(msgs); } else { //Invalid JSON - we close the connection close(); } } }); ws.closeHandler(v -> { closed = true; session.shutdown(); }); ws.exceptionHandler(t -> { closed = true; session.shutdown(); session.handleException(t); }); }
WebSocketListener(ServerWebSocket ws, SockJSSession session) { this.ws = ws; this.session = session; ws.handler(data -> { if (!session.isClosed()) { String msgs = data.toString(); if (msgs.equals("")) { //Ignore empty frames } else if ((msgs.startsWith("[\"") && msgs.endsWith("\"]")) || (msgs.startsWith("\"") && msgs.endsWith("\""))) { session.handleMessages(msgs); } else { //Invalid JSON - we close the connection close(); } } }); ws.closeHandler(v -> { closed = true; session.shutdown(); }); ws.exceptionHandler(t -> { closed = true; session.shutdown(); session.handleException(t); }); }
private HttpServer setupStatusService() { return vertx.createHttpServer().websocketHandler(websock -> { websock.writeFinalTextFrame(new JsonObject().put("message", getStatusServiceWelcomeMessage()).encode()); AtomicReference<String> uploadId = new AtomicReference<>(""); // sets up an event bus consumer to listen for import progress. MessageConsumer<JsonObject> consumer = vertx.eventBus().consumer(IMPORT_PROGRESS, data -> { try { if (uploadId.get().equals(data.body().getString(UPLOAD_ID))) { websock.writeFinalTextFrame(data.body().encode()); } } catch (Throwable e) { websock.close(); } }); // we only support one message from the client - to set the upload ID to listen to. websock.handler(handler -> uploadId.set(handler.toJsonObject().getString(UPLOAD_ID))); // when the websocket is closed we should stop listening for status messages. websock.closeHandler(closed -> consumer.unregister()); // when the websocket excepts we should also stop listening for status messages. websock.exceptionHandler(sock -> consumer.unregister()); }); }
WebSocketListener(ServerWebSocket ws, SockJSSession session) { this.ws = ws; this.session = session; ws.textMessageHandler(this::handleMessages); ws.closeHandler(v -> { closed = true; session.shutdown(); }); ws.exceptionHandler(t -> { closed = true; session.shutdown(); session.handleException(t); }); }
webSocket.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable event) {
public void start() { netSocket.handler(this); netSocket.exceptionHandler(event -> { String clientInfo = getClientInfo(); logger.info(clientInfo + ", web-socket closed ... " + netSocket.binaryHandlerID() + " error: " + event.getMessage()); handleWillMessage(); shutdown(); }); netSocket.closeHandler(aVoid -> { String clientInfo = getClientInfo(); logger.info(clientInfo + ", web-socket closed ... "+ netSocket.binaryHandlerID() +" "+ netSocket.textHandlerID()); shutdown(); }); }
ebnb.stop(); }); sock.exceptionHandler(throwable -> { logger.error("Bridge Server - Exception: " + throwable.getMessage(), throwable); ebnb.stop();
socket.exceptionHandler((exception) -> { LOGGER.error("The STOMP server caught a WebSocket error - closing connection", exception); connection.close();