use of okhttp3.WebSocketListener in project okhttp by square.
the class WebSocketRecorder method onMessage.
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onMessage", null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onMessage(webSocket, bytes);
} else {
Message event = new Message(bytes);
events.add(event);
}
}
use of okhttp3.WebSocketListener in project okhttp by square.
the class WebSocketHttpTest method throwingOnMessageClosesImmediatelyAndFails.
@Test
public void throwingOnMessageClosesImmediatelyAndFails() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
newWebSocket();
clientListener.assertOpen();
WebSocket server = serverListener.assertOpen();
final RuntimeException e = new RuntimeException();
clientListener.setNextEventDelegate(new WebSocketListener() {
@Override
public void onMessage(WebSocket webSocket, String text) {
throw e;
}
});
server.send("Hello, WebSockets!");
clientListener.assertFailure(e);
serverListener.assertExhausted();
}
Aggregations