What do I want to have:
- Client sends
GET / HTTP/1.1
(withoutConnection: upgrade
) - this request should be handled byRequestMappingHandlerMapping
- Client sends
Connection: upgrade
along with GET request - this request should be handled byServletWebSocketHandlerRegistry
My Java configuration:
@Configuration
@EnableWebSocket
public class WebsocketConfiguration extends WebMvcConfigurationSupport
implements WebSocketConfigurer {
@Bean
WebsocketComponent wsHandler() {
return new WebsocketComponent();
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(wsHandler(), "/").setAllowedOrigins("*");
}
}
My webmvc controller:
@Controller
public class Status {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String status() {
return "OK";
}
}
The problem is - when MVC controller taking precedence, it always respond with HTTP 200, WebSocket handler never reached. When WebSocket handler have precedence - it works with WebSocket client, but when I try http client(browser) it responds with Can "Upgrade" only to "WebSocket".
Is it possible to replace somehow this error page with fallback to my MVC mapping? Any other configurations to make what I described first?