Linking a user to a session

We are still missing a critical ingredient--linking the username entered to the user's WebSocket session.

Since every one of our WebSocketHandler services we built may need access to this user data, we should build a shim called UserParsingHandshakeHandler to slip in like this:

 abstract class UserParsingHandshakeHandler implements WebSocketHandler { private final Map<String, String> userMap; UserParsingHandshakeHandler() { this.userMap = new HashMap<>(); } @Override public final Mono<Void> handle(WebSocketSession session) { this.userMap.put(session.getId(), Stream.of(session.getHandshakeInfo().getUri() .getQuery().split("&")) .map(s -> s.split("=")) .filter(strings -> strings[0].equals("user")) .findFirst() .map(strings ...

Get Learning Spring Boot 2.0 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.