使用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套接字的连接。怎么做?