Alessandro C
Alessandro C

Reputation: 3560

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.

Upvotes: 3

Views: 5674

Answers (1)

Alessandro C
Alessandro C

Reputation: 3560

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.

Upvotes: 3

Related Questions