use of okhttp3.WebSocketListener 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.WebSocketListener 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.WebSocketListener 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.WebSocketListener in project okhttp by square.
the class WebSocketHttpTest method throwingOnOpenFailsImmediately.
@Test
public void throwingOnOpenFailsImmediately() {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
final RuntimeException e = new RuntimeException();
clientListener.setNextEventDelegate(new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
throw e;
}
});
newWebSocket();
serverListener.assertOpen();
serverListener.assertExhausted();
clientListener.assertFailure(e);
}
use of okhttp3.WebSocketListener in project okhttp by square.
the class WebSocketHttpTest method throwingOnClosingClosesImmediatelyAndFails.
@Test
public void throwingOnClosingClosesImmediatelyAndFails() 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 onClosing(WebSocket webSocket, int code, String reason) {
throw e;
}
});
server.close(1000, "bye");
clientListener.assertFailure(e);
serverListener.assertExhausted();
}
Aggregations