client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, ws -> { AtomicBoolean receivedFirstFrame = new AtomicBoolean(); ws.frameHandler(received -> { Buffer receivedBuffer = Buffer.buffer(received.textData()); if (!received.isFinal()) {
@Test public void testCloseStatusCodeFromServer() throws InterruptedException { CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); vertx.setTimer(1000, (ar) -> socket.close()); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.frameHandler(frame -> { assertEquals(1000, frame.binaryData().getByteBuf().getShort(0)); assertEquals(1000, frame.closeStatusCode()); assertNull(frame.closeReason()); latch.countDown(); }); }); }); awaitLatch(latch); }
@Test public void testCloseCustomPayloadFromServer() throws InterruptedException { final String REASON = "I'm moving away!"; final short STATUS_CODE = (short)1001; CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); vertx.setTimer(1000, (ar) -> socket.close(STATUS_CODE, REASON)); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.frameHandler(frame -> { assertEquals(REASON, frame.binaryData().getByteBuf().readerIndex(2).toString(StandardCharsets.UTF_8)); assertEquals(STATUS_CODE, frame.binaryData().getByteBuf().getShort(0)); assertEquals(REASON, frame.closeReason()); assertEquals(STATUS_CODE, frame.closeStatusCode()); latch.countDown(); }); }); }); awaitLatch(latch); }
ws.frameHandler(frame -> {
ws.frameHandler(frame -> { if (frame.isClose()) { complete();
ws.frameHandler(frame -> { Buffer action = frame.binaryData(); LOGGER.info("watching config recieved {}", action);
this.vertxWebSocket.frameHandler(event -> { if (event.isFinal()) { if (event.isBinary()) {
public io.vertx.rxjava.core.http.WebSocket frameHandler(Handler<io.vertx.rxjava.core.http.WebSocketFrame> handler) { delegate.frameHandler(new Handler<io.vertx.core.http.WebSocketFrame>() { public void handle(io.vertx.core.http.WebSocketFrame event) { handler.handle(io.vertx.rxjava.core.http.WebSocketFrame.newInstance(event)); } }); return this; }
public io.vertx.rxjava.core.http.WebSocket frameHandler(Handler<io.vertx.rxjava.core.http.WebSocketFrame> handler) { delegate.frameHandler(new Handler<io.vertx.core.http.WebSocketFrame>() { public void handle(io.vertx.core.http.WebSocketFrame event) { handler.handle(io.vertx.rxjava.core.http.WebSocketFrame.newInstance(event)); } }); return this; }
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, ws -> { AtomicBoolean receivedFirstFrame = new AtomicBoolean(); ws.frameHandler(received -> { Buffer receivedBuffer = Buffer.buffer(received.textData()); if (!received.isFinal()) {
@Test public void testCloseCustomPayloadFromServer() throws InterruptedException { final String REASON = "I'm moving away!"; final short STATUS_CODE = (short)1001; CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); vertx.setTimer(1000, (ar) -> socket.close(STATUS_CODE, REASON)); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.frameHandler(frame -> { assertEquals(REASON, frame.binaryData().getByteBuf().readerIndex(2).toString(StandardCharsets.UTF_8)); assertEquals(STATUS_CODE, frame.binaryData().getByteBuf().getShort(0)); assertEquals(REASON, frame.closeReason()); assertEquals(STATUS_CODE, frame.closeStatusCode()); latch.countDown(); }); }); }); awaitLatch(latch); }
@Test public void testCloseStatusCodeFromServer() throws InterruptedException { CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); vertx.setTimer(1000, (ar) -> socket.close()); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.frameHandler(frame -> { assertEquals(1000, frame.binaryData().getByteBuf().getShort(0)); assertEquals(1000, frame.closeStatusCode()); assertNull(frame.closeReason()); latch.countDown(); }); }); }); awaitLatch(latch); }
@Test public void testInvalidMessageCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("SockJSHandlerTest.testInvalidMessageCode"))) ); vertx.eventBus().consumer("SockJSHandlerTest.testInvalidMessageCode", msg -> msg.reply(new JsonObject())); client.websocket("/ws-timeout/websocket", ws -> { ws.writeFinalBinaryFrame(Buffer.buffer("durp!")); ws.frameHandler(frame -> { // we should get a normal frame with a error message if (!frame.isClose()) { JsonObject msg = new JsonObject(frame.binaryData()); assertEquals("err", msg.getString("type")); assertEquals("invalid_json", msg.getString("body")); testComplete(); ws.close(); } }); }); await(); } }
ws.frameHandler(frame -> {
@Test public void testTimeoutCloseCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().setPingTimeout(1)) ); client.websocket("/ws-timeout/websocket", ws -> ws.frameHandler(frame -> { if (frame.isClose()) { assertEquals(1001, frame.closeStatusCode()); assertEquals("Session expired", frame.closeReason()); testComplete(); } })); await(); }
ws.frameHandler(frame -> { if (frame.isClose()) { complete();
this.vertxWebSocket.frameHandler(event -> { if (event.isFinal()) { if (event.isBinary()) {
@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); }); }
@Test public void testInvalidMessageCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("SockJSHandlerTest.testInvalidMessageCode"))) ); vertx.eventBus().consumer("SockJSHandlerTest.testInvalidMessageCode", msg -> msg.reply(new JsonObject())); client.websocket("/ws-timeout/websocket", ws -> { ws.writeFinalBinaryFrame(Buffer.buffer("durp!")); ws.frameHandler(frame -> { // we should get a normal frame with a error message if (!frame.isClose()) { JsonObject msg = new JsonObject(frame.binaryData()); assertEquals("err", msg.getString("type")); assertEquals("invalid_json", msg.getString("body")); testComplete(); ws.close(); } }); }); await(); } }
@Test public void testTimeoutCloseCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().setPingTimeout(1)) ); client.websocket("/ws-timeout/websocket", ws -> ws.frameHandler(frame -> { if (frame.isClose()) { assertEquals(1001, frame.closeStatusCode()); assertEquals("Session expired", frame.closeReason()); testComplete(); } })); await(); }