Search code examples
spring-mvcwebsocketspring-websocket

Error during WebSocket handshake: Unexpected response code: 405


I have a Web Socket with Spring and SockJs, I have to expose the Socket also for a "WebSocket" standard.

I have my handler:

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(mySocketHandler(), "/mySocket").setAllowedOrigins("*");
}

When I create the websocket via browser, with this:

var ws = new WebSocket('wss://localhost:8443/myApp/mySocket')

I have the following error:

WebSocket connection to 'wss://localhost:8443/myApp/mySocket' failed: Error during WebSocket handshake: Unexpected response code: 405

Any suggestions?

Thanks.


Solution

  • I have found the solution.

    This error occoured because in the @Configuration component the annotation @EnableWebSocket was missing.

    After adding @EnableWebSocket, the connection was correctly established.