It seems like I almost never need to do anything with WebSocketHandlerAdapter when using WebFlux and websockets. I just need to register it, like this:
@Bean
SimpleUrlHandlerMapping simpleUrlHandlerMapping(WebSocketHandler wsh) {
return new SimpleUrlHandlerMapping() {
{
setUrlMap(Map.of("/ws/time", wsh));
setOrder(10);
}
};
}
@Bean
WebSocketHandlerAdapter wsha() {
return new WebSocketHandlerAdapter();
}
@Bean
WebSocketHandler wsh(Timer timer) {
return session -> session.send(timer.greet().share().map(session::textMessage));
}
I can see why i need to register the WebSocketHandler (that's where my custom websocket logic lives) and I can see why I need to register the SimpleUrlHandlermapping bean (that's where my custom routing lives). But why the WebSocketHandlerAdapter? Could it be auto-configuration registered based on the presence of websockets on the classpath and subject to a @ConditionalOnMissingBean so that users who want to contribute their own can do so? it seems ceremonial.
thanks in advance..
It seems like I almost never need to do anything with
WebSocketHandlerAdapterwhen using WebFlux and websockets. I just need to register it, like this:I can see why i need to register the
WebSocketHandler(that's where my custom websocket logic lives) and I can see why I need to register theSimpleUrlHandlermappingbean (that's where my custom routing lives). But why theWebSocketHandlerAdapter? Could it be auto-configuration registered based on the presence of websockets on the classpath and subject to a@ConditionalOnMissingBeanso that users who want to contribute their own can do so? it seems ceremonial.thanks in advance..