Spring Websocket断开连接。例外

时间:2015-11-08 06:20:01

标签: spring-websocket stompjs

我使用Spring Websocket(正是这个例子Template for my appl) 如果我在客户端断开连接,我会在底部得到这个例外:

$scope.$on('$destroy', function() { // invoked if page is leaved 
        if (vm.stompClient != null) {
            vm.stompClient.unsubscribe();
            vm.stompClient.disconnect(function() {
                console.log("Disconnected in chat.controller.js#destroy");
            });
        }
    });

有谁知道我能做些什么才能防止这种异常。 它对该功能没有任何影响 - 一切仍然有效,但它不是干净的代码,因此我会解决这个问题 - 感谢您的帮助!

  

java.lang.IllegalStateException:会话关闭时无法发送消息       在org.springframework.util.Assert.state(Assert.java:385)       在org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(AbstractSockJsSession.java:159)       在org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.tryFlushMessageBuffer(ConcurrentWebSocketSessionDecorator.java:126)       在org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sendMessage(ConcurrentWebSocketSessionDecorator.java:99)       在org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:368)       在org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:337)       在org.springframework.messaging.support.ExecutorSubscribableChannel $ SendTask.run(ExecutorSubscribableChannel.java:135)       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

[编辑]

我也找到了这两个日志条目:

  

2015-11-08 07:47:53.642 DEBUG 13452 --- [io-8080-exec-10] swshLoggingWebSocketHandlerDecorator: WebSocketServerSockJsSession [id = kludit93]关闭与CloseStatus [code = 1000 ,reason = null]   2015-11-08 07:47:53.643 DEBUG 13452 --- [io-8080-exec-10] o.s.w.s.m.SubProtocolWebSocketHandler:清算会话kludit93   2015-11-08 07:47:53.646 DEBUG 13452 --- [tboundChannel-4] o.s.w.s.m.SubProtocolWebSocketHandler:GenericMessage没有会话[payload = byte [0],headers = {simpMessageType = DISCONNECT_ACK,simpSessionId = kludit93}]   2015-11-08 07:47:53.659 DEBUG 13452 --- [tboundChannel-3] o.s.w.s.m.StompSubProtocolHandler:无法在会话kludit93 中向客户端发送WebSocket消息。

所以这对我来说意味着首先会话被关闭,并且尝试通过这个已关闭的会话向客户端发送一些内容。 有没有可能阻止这种行为? 谢谢!

0 个答案:

没有答案