@ Override public void handleMessageToClient ( WebSocketSession session , Message < ? > message ) { if ( ! ( message instanceof WampMessage ) ) { logger . error ( "Expected WampMessage. Ignoring " + message + "." ) ; return ; } boolean closeWebSocketSession = false ; try { String json = ( ( WampMessage ) message ) . toJson ( this . jsonFactory ) ; session . sendMessage ( new TextMessage ( json ) ) ; } catch ( SessionLimitExceededException ex ) { // Bad session, just get out throw ex ; } catch ( Throwable ex ) { // Could be part of normal workflow (e.g. browser tab closed) logger . debug ( "Failed to send WebSocket message to client in session " + session . getId ( ) + "." , ex ) ; closeWebSocketSession = true ; } finally { if ( closeWebSocketSession ) { try { session . close ( CloseStatus . PROTOCOL_ERROR ) ; } catch ( IOException ex ) { // Ignore } } } }
Handle WAMP messages going back out to WebSocket clients .