3

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.

6
  • So your server supports encrypted connections? How did you configure that? Commented Apr 6, 2016 at 12:55
  • sure it supports them. My app is served in https and uses already sockets with sockjs. Commented Apr 6, 2016 at 13:00
  • "uses already sockets with sockjs" - which can use fallback options. Maybe websockets are not yet configured to be used with SSL/TLS. Commented Apr 6, 2016 at 13:16
  • I don't understand. The application can normally connect to web sockets using sockjs; I'm trying to add a normal WebSocket but I have that error... Commented Apr 6, 2016 at 13:26
  • "The application can normally connect to web sockets using sockjs" That was my point: Maybe it does not(!) connect via websockets but uses a fallback option, because websockets don't work on your server. SockJS can(!) use websockets. Commented Apr 6, 2016 at 13:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.