use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method websocketScheme.
private void websocketScheme(String scheme) throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
Request request = new Request.Builder().url(scheme + "://" + webServer.getHostName() + ":" + webServer.getPort() + "/").build();
RealWebSocket webSocket = newWebSocket(request);
clientListener.assertOpen();
serverListener.assertOpen();
webSocket.send("abc");
serverListener.assertTextMessage("abc");
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onFailure.
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onFailure", t);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onFailure(webSocket, t, response);
} else {
events.add(new Failure(t, response));
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onOpen.
@Override
public void onOpen(WebSocket webSocket, Response response) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onOpen", null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onOpen(webSocket, response);
} else {
events.add(new Open(webSocket, response));
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onClosing.
@Override
public void onClosing(WebSocket webSocket, int code, String reason) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onClose " + code, null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onClosing(webSocket, code, reason);
} else {
events.add(new Closing(code, reason));
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method closeReasonTooLong.
@Test
public void closeReasonTooLong() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
WebSocket webSocket = newWebSocket();
WebSocket server = serverListener.assertOpen();
clientListener.assertOpen();
String reason = repeat('X', 124);
try {
webSocket.close(1000, reason);
fail();
} catch (IllegalArgumentException expected) {
assertEquals("reason.size() > 123: " + reason, expected.getMessage());
}
webSocket.close(1000, null);
serverListener.assertClosing(1000, "");
server.close(1000, null);
clientListener.assertClosing(1000, "");
clientListener.assertClosed(1000, "");
serverListener.assertClosed(1000, "");
}
Aggregations