如何断开客户端与websocket的连接?

时间:2019-02-19 20:42:23

标签: spring spring-ws spring-websocket sockjs

使用ChannelInterceptor方法有一个preSend

@Override
public Message <?> preSend (Message <?> message, MessageChannel channel) {

     LOGGER.info ("WEBSOCKETCHANNELINTERCEPTOR ->" + message.toString ());

     StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor (message, StompHeaderAccessor.class);

     if (accessor! = null && StompCommand.CONNECT.equals (accessor.getCommand ())) {
         List <String> headers = accessor.getNativeHeader (AUTHORIZATION);
         accessor.setUser (websocketAuthenticationManager.authenticate (new JWTTokenAuthentication (tokenUtils.resolveToken (headers! = null? headers.get (0): null))));

     }

     return message;
}

如果CONNECT发生任何错误,我想断开用户与Web套接字的连接。怎么做?

0 个答案:

没有答案