org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator Java Examples
The following examples show how to use
org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SockJsSessionTests.java From java-technology-stack with MIT License | 6 votes |
@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); } }
Example #2
Source File: SockJsSessionTests.java From spring-analysis-note with MIT License | 6 votes |
@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); } }
Example #3
Source File: StandardWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) { PongMessage pongMessage = new PongMessage(payload); try { this.handler.handleMessage(this.wsSession, pongMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #4
Source File: StandardWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
private void handleTextMessage(javax.websocket.Session session, String payload, boolean isLast) { TextMessage textMessage = new TextMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, textMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #5
Source File: JettyWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@OnWebSocketFrame public void onWebSocketFrame(Frame frame) { if (OpCode.PONG == frame.getOpCode()) { ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD; PongMessage message = new PongMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } }
Example #6
Source File: JettyWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@OnWebSocketError public void onWebSocketError(Throwable cause) { try { this.webSocketHandler.handleTransportError(this.wsSession, cause); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #7
Source File: SockJsHttpRequestHandler.java From java-technology-stack with MIT License | 5 votes |
/** * Create a new SockJsHttpRequestHandler. * @param sockJsService the SockJS service * @param webSocketHandler the websocket handler */ public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) { Assert.notNull(sockJsService, "SockJsService must not be null"); Assert.notNull(webSocketHandler, "WebSocketHandler must not be null"); this.sockJsService = sockJsService; this.webSocketHandler = new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler)); }
Example #8
Source File: StandardWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void handleTextMessage(javax.websocket.Session session, String payload, boolean isLast) { TextMessage textMessage = new TextMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, textMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #9
Source File: StandardWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) { BinaryMessage binaryMessage = new BinaryMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, binaryMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #10
Source File: JettyWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] payload, int offset, int length) { BinaryMessage message = new BinaryMessage(payload, offset, length, true); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #11
Source File: StandardWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void onError(javax.websocket.Session session, Throwable exception) { try { this.handler.handleTransportError(this.wsSession, exception); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #12
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketConnect public void onWebSocketConnect(Session session) { try { this.wsSession.initializeNativeSession(session); this.webSocketHandler.afterConnectionEstablished(this.wsSession); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #13
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String payload) { TextMessage message = new TextMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #14
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] payload, int offset, int length) { BinaryMessage message = new BinaryMessage(payload, offset, length, true); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #15
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketFrame public void onWebSocketFrame(Frame frame) { if (OpCode.PONG == frame.getOpCode()) { ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD; PongMessage message = new PongMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } }
Example #16
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketError public void onWebSocketError(Throwable cause) { try { this.webSocketHandler.handleTransportError(this.wsSession, cause); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #17
Source File: SockJsHttpRequestHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new SockJsHttpRequestHandler. * @param sockJsService the SockJS service * @param webSocketHandler the websocket handler */ public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) { Assert.notNull(sockJsService, "SockJsService must not be null"); Assert.notNull(webSocketHandler, "WebSocketHandler must not be null"); this.sockJsService = sockJsService; this.webSocketHandler = new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler)); }
Example #18
Source File: SockJsSessionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(new String[] { msg1, msg2, msg3 }); fail("expected exception"); } catch (SockJsMessageDeliveryException ex) { assertEquals(Arrays.asList(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); } }
Example #19
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketError public void onWebSocketError(Throwable cause) { try { this.webSocketHandler.handleTransportError(this.wsSession, cause); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #20
Source File: StandardWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) { BinaryMessage binaryMessage = new BinaryMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, binaryMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #21
Source File: StandardWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) { PongMessage pongMessage = new PongMessage(payload); try { this.handler.handleMessage(this.wsSession, pongMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #22
Source File: StandardWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@Override public void onError(javax.websocket.Session session, Throwable exception) { try { this.handler.handleTransportError(this.wsSession, exception); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #23
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketConnect public void onWebSocketConnect(Session session) { try { this.wsSession.initializeNativeSession(session); this.webSocketHandler.afterConnectionEstablished(this.wsSession); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #24
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String payload) { TextMessage message = new TextMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #25
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] payload, int offset, int length) { BinaryMessage message = new BinaryMessage(payload, offset, length, true); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #26
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketFrame public void onWebSocketFrame(Frame frame) { if (OpCode.PONG == frame.getOpCode()) { ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD; PongMessage message = new PongMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } }
Example #27
Source File: JettyWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String payload) { TextMessage message = new TextMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #28
Source File: SockJsHttpRequestHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a new SockJsHttpRequestHandler. * @param sockJsService the SockJS service * @param webSocketHandler the websocket handler */ public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) { Assert.notNull(sockJsService, "SockJsService must not be null"); Assert.notNull(webSocketHandler, "WebSocketHandler must not be null"); this.sockJsService = sockJsService; this.webSocketHandler = new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler)); }
Example #29
Source File: StandardWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
private void handleTextMessage(javax.websocket.Session session, String payload, boolean isLast) { TextMessage textMessage = new TextMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, textMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #30
Source File: StandardWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) { BinaryMessage binaryMessage = new BinaryMessage(payload, isLast); try { this.handler.handleMessage(this.wsSession, binaryMessage); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }