@Override public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception { this.delegate.afterConnectionClosed(session, closeStatus); }
public void delegateConnectionEstablished() throws Exception { this.state = State.OPEN; this.handler.afterConnectionEstablished(this); }
@Override public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception { this.delegate.handleMessage(session, message); }
@Test public void connectReceiveAndCloseWithPrelude() throws Exception { StringBuilder sb = new StringBuilder(2048); for (int i = 0; i < 2048; i++) { sb.append('h'); } String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo"))); verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!"))); verifyNoMoreInteractions(this.webSocketHandler); }
public void delegateError(Throwable ex) throws Exception { this.handler.handleTransportError(this, ex); }
@Test public void errorResponseStatus() throws Exception { connect(response(HttpStatus.OK, "o\n"), response(HttpStatus.INTERNAL_SERVER_ERROR, "Oops")); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleTransportError(any(), any()); verify(this.webSocketHandler).afterConnectionClosed(any(), any()); verifyNoMoreInteractions(this.webSocketHandler); }
@Test public void afterTransportClosed() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.afterTransportClosed(CloseStatus.SERVER_ERROR); assertThat(this.session.isOpen(), equalTo(false)); verify(this.handler).afterConnectionEstablished(this.session); verify(this.handler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR); verifyNoMoreInteractions(this.handler); }
@Test public void handleFrameMessageWithWebSocketHandlerException() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); willThrow(new IllegalStateException("Fake error")).given(this.handler) .handleMessage(this.session, new TextMessage("foo")); willThrow(new IllegalStateException("Fake error")).given(this.handler) .handleMessage(this.session, new TextMessage("bar")); this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent()); assertThat(this.session.isOpen(), equalTo(true)); verify(this.handler).afterConnectionEstablished(this.session); verify(this.handler).handleMessage(this.session, new TextMessage("foo")); verify(this.handler).handleMessage(this.session, new TextMessage("bar")); verifyNoMoreInteractions(this.handler); }
if (this.handler.supportsPartialMessages()) { session.addMessageHandler(new MessageHandler.Partial<String>() { @Override this.handler.afterConnectionEstablished(this.wsSession);
@Override public boolean supportsPartialMessages() { return this.delegate.supportsPartialMessages(); }
@Test public void delegateMessagesWithErrorAndConnectionClosing() throws Exception { WebSocketHandler wsHandler = new ExceptionWebSocketHandlerDecorator(this.webSocketHandler); TestSockJsSession sockJsSession = new TestSockJsSession( "1", this.sockJsConfig, wsHandler, Collections.<String, Object>emptyMap()); String msg1 = "message 1"; String msg2 = "message 2"; String msg3 = "message 3"; willThrow(new IOException()).given(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2)); sockJsSession.delegateConnectionEstablished(); try { sockJsSession.delegateMessages(msg1, msg2, msg3); fail("expected exception"); } catch (SockJsMessageDeliveryException ex) { assertEquals(Collections.singletonList(msg3), ex.getUndeliveredMessages()); verify(this.webSocketHandler).afterConnectionEstablished(sockJsSession); verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg1)); verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2)); verify(this.webSocketHandler).afterConnectionClosed(sockJsSession, CloseStatus.SERVER_ERROR); verifyNoMoreInteractions(this.webSocketHandler); } }
@Override public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { this.delegate.handleTransportError(session, exception); }
@Test public void responseClosedAfterDisconnected() throws Exception { String body = "o\n" + "c[3000,\"Go away!\"]\n" + "a[\"foo\"]\n"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).afterConnectionClosed(any(), any()); verifyNoMoreInteractions(this.webSocketHandler); verify(response).close(); }
@Test public void handleFrameMessage() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent()); verify(this.handler).afterConnectionEstablished(this.session); verify(this.handler).handleMessage(this.session, new TextMessage("foo")); verify(this.handler).handleMessage(this.session, new TextMessage("bar")); verifyNoMoreInteractions(this.handler); }
if (this.handler.supportsPartialMessages()) { session.addMessageHandler(new MessageHandler.Partial<String>() { @Override this.handler.afterConnectionEstablished(this.wsSession);
@Override public boolean supportsPartialMessages() { return this.delegate.supportsPartialMessages(); }
@Test public void connectReceiveAndClose() throws Exception { String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo"))); verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!"))); verifyNoMoreInteractions(this.webSocketHandler); }
@Override public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) { try { getDelegate().afterConnectionClosed(session, closeStatus); } catch (Throwable ex) { if (logger.isWarnEnabled()) { logger.warn("Unhandled exception after connection closed for " + this, ex); } } }
public void handleTransportError(Throwable error) { try { if (logger.isErrorEnabled()) { logger.error("Transport error in " + this, error); } this.webSocketHandler.handleTransportError(this, error); } catch (Throwable ex) { logger.error("WebSocketHandler.handleTransportError threw an exception", ex); } }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { this.delegate.afterConnectionEstablished(session); }