use of io.vertx.core.http.WebSocket in project vertx-web by vert-x3.
the class SockJSHandlerTest method setupRawWebsocketClient.
/**
* This does not set up a handler on the websocket
*/
private WebSocket setupRawWebsocketClient(String serverPath) throws InterruptedException {
String requestURI = serverPath + "/websocket";
AtomicReference<WebSocket> openedWebSocketReference = new AtomicReference<>();
CountDownLatch openSocketCountDown = new CountDownLatch(1);
client.websocket(requestURI, ws -> {
openedWebSocketReference.set(ws);
openSocketCountDown.countDown();
ws.endHandler(v -> testComplete());
ws.exceptionHandler(this::fail);
});
openSocketCountDown.await(5, TimeUnit.SECONDS);
return openedWebSocketReference.get();
}
use of io.vertx.core.http.WebSocket in project vertx-web by vert-x3.
the class SockJSHandlerTest method testTextFrameRawWebSocket.
@Test
public void testTextFrameRawWebSocket() throws InterruptedException {
String serverPath = "/textecho";
setupSockJsServer(serverPath, this::echoRequest);
String message = "hello";
AtomicReference<String> receivedReply = new AtomicReference<>();
WebSocket ws = setupRawWebsocketClient(serverPath);
ws.handler(replyBuffer -> receivedReply.set(replyBuffer.toString()));
ws.writeFrame(WebSocketFrame.textFrame(message, true));
await(5, TimeUnit.SECONDS);
assertEquals("Client reply should have matched request", message, receivedReply.get());
}
use of io.vertx.core.http.WebSocket in project vertx-examples by vert-x3.
the class SubscriptionClient method start.
@Override
public void start() {
HttpClient httpClient = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
httpClient.webSocket("/graphql", websocketRes -> {
if (websocketRes.succeeded()) {
WebSocket webSocket = websocketRes.result();
webSocket.handler(message -> {
System.out.println(message.toJsonObject().encodePrettily());
});
JsonObject request = new JsonObject().put("id", "1").put("type", ApolloWSMessageType.START.getText()).put("payload", new JsonObject().put("query", "subscription { links { url, postedBy { name } } }"));
webSocket.write(request.toBuffer());
} else {
websocketRes.cause().printStackTrace();
}
});
}
Aggregations