springwebsocketstompsockjspivotal-web-services

websocket stomp in spring over sockjs redirects to http protocol while the origin is https in pivotal web services


I am developing a spring web chat application using stomp and sockjs. I uploaded the application in pivotal web services. I understand that it uses a different port i.e. 4443. Once I run the application the websocket losts connection to undefined

The following error comes into the console: Opening Web Socket...

WebSocket connection to

'wss://homeworkpavilion.cfapps.io:4443/chat/193/dqu_2erz/websocket' failed: Error during WebSocket handshake: Unexpected response code: 302

POST https://homeworkpavilion.cfapps.io/chat/193/_bhfpyma/xhr_streaming 500 (Internal Server Error)

POST https://homeworkpavilion.cfapps.io/chat/193/nys00vmj/xhr 500 (Internal Server Error)

Whoops! Lost connection to undefined

Pls help, this stuff is reaaaalyy bugging me


Solution

  • There is no permission to redirect to different port. You can bypass this restriction by setting all origins to allowed when registering your stomp endpoints. I want to point out, that this is a very bad solution. You should take advantage of proxies, but I lack information here to help you with that.

    Here is the code you might find useful:

    public void registerStompEndpoints(StompEndpointRegistry registry) {
       registry.addEndpoint("/your_endpoint").setAllowedOrigins("*").withSockJS();
    }