at present, the front end is disconnected in this way
/**
*
*
* @author rxliuli
*/
public abstract class BaseSessionEventListener<Event extends AbstractSubProtocolEvent> implements ApplicationListener<Event> {
protected final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
protected SocketSessionRegistry webAgentSessionRegistry;
/**
* user id session id
*
* @param event
* @param biConsumer
*/
protected void using(Event event, BiConsumer<String, String> biConsumer) {
StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
//login get from browser
List<String> shaNativeHeader = sha.getNativeHeader("Authorization");
String user = shaNativeHeader == null || shaNativeHeader.isEmpty() ? null : shaNativeHeader.get(0);
//
if (user == null || "".equals(user) || "undefined".equals(user) || "null".equals(user)) {
user = SocketSessionRegistry.DIRECT_TOURIST;
}
String sessionId = sha.getSessionId();
biConsumer.accept(user, sessionId);
}
}
/**
* Socket
*
* @author rxliuli
*/
@Component
public class SessionDisconnectEventListener extends BaseSessionEventListener<SessionDisconnectEvent> {
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
using(event, (user, sessionId) -> webAgentSessionRegistry.unregisterSessionId(user, sessionId));
}
}
What"s wrong with
or our back-end value? (= ^ ^) y =