use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onMessage.
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
Platform.get().log("[WS " + name + "] onMessage", Platform.INFO, 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.WebSocket in project okhttp by square.
the class WebSocketRecorder method onMessage.
@Override
public void onMessage(WebSocket webSocket, String text) {
Platform.get().log("[WS " + name + "] onMessage", Platform.INFO, null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onMessage(webSocket, text);
} else {
Message event = new Message(text);
events.add(event);
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method successfulExtensions.
private void successfulExtensions(String extensionsHeader) throws Exception {
webServer.enqueue(new MockResponse().addHeader("Sec-WebSocket-Extensions", extensionsHeader).withWebSocketUpgrade(serverListener));
WebSocket client = newWebSocket();
clientListener.assertOpen();
WebSocket server = serverListener.assertOpen();
// Server to client message big enough to be compressed.
String message1 = TestUtil.repeat('a', (int) RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE);
server.send(message1);
clientListener.assertTextMessage(message1);
// Client to server message big enough to be compressed.
String message2 = TestUtil.repeat('b', (int) RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE);
client.send(message2);
serverListener.assertTextMessage(message2);
// Empty server to client message.
String message3 = "";
server.send(message3);
clientListener.assertTextMessage(message3);
// Empty client to server message.
String message4 = "";
client.send(message4);
serverListener.assertTextMessage(message4);
// Server to client message that shares context with message1.
String message5 = message1 + message1;
server.send(message5);
clientListener.assertTextMessage(message5);
// Client to server message that shares context with message2.
String message6 = message2 + message2;
client.send(message6);
serverListener.assertTextMessage(message6);
closeWebSockets(client, server);
RecordedRequest upgradeRequest = webServer.takeRequest();
assertThat(upgradeRequest.getHeader("Sec-WebSocket-Extensions")).isEqualTo("permessage-deflate");
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method closeReasonMaximumLength.
@Test
public void closeReasonMaximumLength() {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
String clientReason = repeat('C', 123);
String serverReason = repeat('S', 123);
WebSocket webSocket = newWebSocket();
WebSocket server = serverListener.assertOpen();
clientListener.assertOpen();
webSocket.close(1000, clientReason);
serverListener.assertClosing(1000, clientReason);
server.close(1000, serverReason);
clientListener.assertClosing(1000, serverReason);
clientListener.assertClosed(1000, serverReason);
serverListener.assertClosed(1000, clientReason);
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method throwingOnMessageClosesImmediatelyAndFails.
@Test
public void throwingOnMessageClosesImmediatelyAndFails() {
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.assertFailure(EOFException.class);
serverListener.assertExhausted();
}
Aggregations