use of io.vertx.core.http.WebSocket in project vertx-web by vert-x3.
the class SockJSHandlerTest method testSplitLargeReplyRawWebSocket.
@Test
public void testSplitLargeReplyRawWebSocket() throws InterruptedException {
String serverPath = "/split";
String largeReply = TestUtils.randomAlphaString(65536 * 5);
Buffer largeReplyBuffer = Buffer.buffer(largeReply);
setupSockJsServer(serverPath, (sock, requestBuffer) -> {
sock.write(largeReplyBuffer);
sock.close();
});
Buffer totalReplyBuffer = Buffer.buffer(largeReplyBuffer.length());
AtomicInteger receivedReplies = new AtomicInteger(0);
WebSocket ws = setupRawWebsocketClient(serverPath);
ws.handler(replyBuffer -> {
totalReplyBuffer.appendBuffer(replyBuffer);
receivedReplies.incrementAndGet();
});
ws.writeFrame(WebSocketFrame.binaryFrame(Buffer.buffer("hello"), true));
await(5, TimeUnit.SECONDS);
int receivedReplyCount = receivedReplies.get();
assertEquals("Combined reply on client should equal message from server", largeReplyBuffer, totalReplyBuffer);
assertTrue("Should have received > 1 reply frame, actually received " + receivedReplyCount, receivedReplyCount > 1);
}
use of io.vertx.core.http.WebSocket in project vertx-web by vert-x3.
the class SockJSHandlerTest method testTextFrameSockJs.
@Test
public void testTextFrameSockJs() throws InterruptedException {
String serverPath = "/text-sockjs";
setupSockJsServer(serverPath, this::echoRequest);
List<Buffer> receivedMessages = new ArrayList<>();
WebSocket openedWebSocket = setupSockJsClient(serverPath, receivedMessages);
String messageToSend = "[\"testMessage\"]";
openedWebSocket.writeFrame(WebSocketFrame.textFrame(messageToSend, true));
await(5, TimeUnit.SECONDS);
assertEquals("Client should have received 2 messages: the reply and the close.", 2, receivedMessages.size());
Buffer expectedReply = Buffer.buffer("a" + messageToSend);
assertEquals("Client reply should have matched request", expectedReply, receivedMessages.get(0));
assertEquals("Final message should have been a close", SOCKJS_CLOSE_REPLY, receivedMessages.get(1));
}
use of io.vertx.core.http.WebSocket in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method simulateWebSocketStartup.
private void simulateWebSocketStartup() throws InterruptedException, ExecutionException, TimeoutException {
ArgumentCaptor<Handler> webSocketHandlerCapture = ArgumentCaptor.forClass(Handler.class);
ArgumentCaptor<Handler> bufferHandlerCapture = ArgumentCaptor.forClass(Handler.class);
when(httpClientMock.websocket(any(RequestOptions.class), webSocketHandlerCapture.capture())).thenReturn(httpClientMock);
when(webSocketMock.handler(bufferHandlerCapture.capture())).thenReturn(webSocketMock);
CompletableFuture<Void> future = listener.open();
Handler<WebSocket> webSocketHandler = webSocketHandlerCapture.getValue();
Assertions.assertNotNull(webSocketHandler);
webSocketHandler.handle(webSocketMock);
Handler<Buffer> bufferHandler = bufferHandlerCapture.getValue();
Assertions.assertNotNull(bufferHandler);
Buffer event = new BufferFactoryImpl().buffer(jsonHelper.print(Collections.singletonMap("uid", wsId)));
bufferHandler.handle(event);
future.get(3, TimeUnit.SECONDS);
}
use of io.vertx.core.http.WebSocket in project chili-core by codingchili.
the class WebsocketListenerIT method sendRequest.
@Override
public void sendRequest(ResponseListener listener, JsonObject data) {
context.vertx().createHttpClient().webSocket(port, HOST, CoreStrings.DIR_SEPARATOR, handler -> {
if (handler.succeeded()) {
WebSocket webSocket = handler.result();
webSocket.handler(body -> handleBody(listener, body));
webSocket.write(Buffer.buffer(data.encode()));
} else {
throw new RuntimeException(handler.cause());
}
});
}
use of io.vertx.core.http.WebSocket in project vertx-web by vert-x3.
the class SockJSHandlerTest method testCookiesRemoved.
@Test
public void testCookiesRemoved() throws Exception {
router.route("/cookiesremoved/*").handler(SockJSHandler.create(vertx).socketHandler(sock -> {
MultiMap headers = sock.headers();
String cookieHeader = headers.get("cookie");
assertNotNull(cookieHeader);
assertEquals("JSESSIONID=wibble", cookieHeader);
testComplete();
}));
MultiMap headers = new CaseInsensitiveHeaders();
headers.add("cookie", "JSESSIONID=wibble");
headers.add("cookie", "flibble=floob");
client.websocket("/cookiesremoved/websocket", headers, ws -> {
String frame = "foo";
ws.writeFrame(io.vertx.core.http.WebSocketFrame.textFrame(frame, true));
});
await();
}
Aggregations