use of com.neovisionaries.ws.client.WebSocket in project FlareBot by FlareBot.
the class WebSocketFactory method createSocket.
@Override
public WebSocket createSocket(URI uri) throws IOException {
WebSocket socket = super.createSocket(uri);
socket.addListener(this.listener);
return socket;
}
use of com.neovisionaries.ws.client.WebSocket in project FlareBot by FlareBot.
the class WebSocketFactory method createSocket.
@Override
public WebSocket createSocket(URI uri, int timeout) throws IOException {
WebSocket socket = super.createSocket(uri, timeout);
socket.addListener(this.listener);
return socket;
}
use of com.neovisionaries.ws.client.WebSocket in project ninja by ninjaframework.
the class ChatWebSocketTest method sendAndReceiveBinary.
@Test
public void sendAndReceiveBinary() throws IOException, WebSocketException, InterruptedException {
String chatId = UUID.randomUUID().toString();
String url = withBaseWebSocketUrl("/chat");
WebSocket ws = new WebSocketFactory().createSocket(url);
try {
ws.addHeader("X-Chat-Id", chatId);
ws.connect();
BlockingQueue<byte[]> received = new LinkedBlockingQueue<>();
ws.addListener(new WebSocketAdapter() {
@Override
public void onBinaryMessage(WebSocket websocket, byte[] binary) throws Exception {
received.put(binary);
}
});
ws.sendText("binary1");
byte[] reply = received.poll(2L, TimeUnit.SECONDS);
assertThat(reply, is(ChatWebSocket.BINARY1));
} finally {
ws.disconnect(WebSocketCloseCode.NORMAL);
}
}
use of com.neovisionaries.ws.client.WebSocket in project ninja by ninjaframework.
the class ChatWebSocketTest method unsupportedProtocol.
@Test
public void unsupportedProtocol() throws IOException, WebSocketException {
String url = withBaseWebSocketUrl("/chat");
WebSocket ws = new WebSocketFactory().createSocket(url);
try {
ws.addProtocol("chat2");
ws.connect();
assertThat(ws.getAgreedProtocol(), is(nullValue()));
} finally {
ws.disconnect(WebSocketCloseCode.NORMAL);
}
}
use of com.neovisionaries.ws.client.WebSocket in project ninja by ninjaframework.
the class ChatWebSocketTest method handshakeUnauthorized.
@Test
public void handshakeUnauthorized() throws IOException, WebSocketException {
String url = withBaseWebSocketUrl("/chat?status=401");
WebSocket ws = new WebSocketFactory().createSocket(url);
try {
ws.connect();
fail("should have failed with a 401");
} catch (OpeningHandshakeException e) {
assertThat(e.getStatusLine().getStatusCode(), is(401));
} finally {
ws.disconnect(WebSocketCloseCode.NORMAL);
}
}
Aggregations