Skip to content

Instantly share code, notes, and snippets.

@circlee
Created March 26, 2019 16:04
Show Gist options
  • Save circlee/3b604a4d4391e4a68e0af8168a30397d to your computer and use it in GitHub Desktop.
Save circlee/3b604a4d4391e4a68e0af8168a30397d to your computer and use it in GitHub Desktop.
@Bean
WebSocketHandlerAdapter getWebsocketHandlerAdapter(){
HandshakeWebSocketService handshakeWebSocketService = new HandshakeWebSocketService();
handshakeWebSocketService.setSessionAttributePredicate( k -> true);
WebSocketHandlerAdapter wsha = new WebSocketHandlerAdapter(handshakeWebSocketService){
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
Map<String, Object> attributes = exchange.getAttributes();
exchange.getSession().subscribe((session) -> {
session.getAttributes().putAll(attributes);
});
return super.handle(exchange, handler);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment