春季重踏:尝试订阅主题时终止客户端会话

时间:2019-02-27 21:28:13

标签: java spring stomp

当用户不在任何不等于连接的命令中时,我想使用拦截器终止客户端连接,这是我的代码:

@Component

公共类WebSocketInterceptor扩展ChannelInterceptorAdapter {

@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) throws AuthenticationException {
    StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);


    if (StompCommand.CONNECT == accessor.getCommand()) {
        //user = authenticate and get user
        accessor.setUser(user);
    } else if (accessor.getUser() == null) {
       //disconnect from web socket completely

    }

    return message;
}

}

我已经尝试抛出异常,但是它仍然允许客户端发送消息

0 个答案:

没有答案