java – WebSocket Handshake – Unexpected response code 200 – AngularJs and Spring Boot

java – WebSocket Handshake – Unexpected response code 200 – AngularJs and Spring Boot

I had a similiar problem, I was testing my websocket connection using an chrome plugin (Simple WebSocket Client) and was trying to connect to ws://localhost:8080/handler/ which is defined in my code as registry.addEndpoint(/handler).setAllowedOrigins(*).withSockJS(); but unexpected error 200 was occuring. Ive fixed this by appending /websocket to my client request string on the chrome extension, so what you could try is to change in your JS file the following line:

var ws = $websocket.$new(ws://localhost:8080/socket);

to

 var ws = $websocket.$new(ws://localhost:8080/socket/websocket);

I dont know the reason why this fixed it in my case i just randomly stumbled upon it, if some1 could clarify it more it would be really nice 🙂

Can you try this WebsocketConfiguration configuration:

@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry)
{
    stompEndpointRegistry.addEndpoint(/socket).setAllowedOrigins(*);      
    stompEndpointRegistry.addEndpoint(/socket).setAllowedOrigins(*).withSockJS();
}

so you have both websocket and SockJS configurations?

java – WebSocket Handshake – Unexpected response code 200 – AngularJs and Spring Boot

You need to use a sockJS client if you configure it to use sockJS on your websocket endpoint.

Leave a Reply

Your email address will not be published.