How can I redirect from WSS to WS?

Viewed 285

Good morning,

I have the following scenario:

Angular + SockJS <-(wss)-> WW.XX.YY.ZZ (Apache) <-(ws)-> AA.BB.CC.DD (Spring Boot Server)

I have a Spring Boot server (AA.BB.CC.DD) and I want to proxy all the requests through a secure endpoint (WW.XX.YY.ZZ), but when I access the Angular application, I can see on the Google Chrome developer tools the following meesage:

 WebSocket connection to 'wss://WW.XX.YY.ZZ/messages/websocket' failed: Error during WebSocket handshake: Unexpected response code: 403

On my Spring Boot application logs, I can see the following:

o.s.w.s.s.s.DefaultHandshakeHandler      : Handshake failed due to invalid Upgrade header: nul

The Angular configuration is the following:

export const stompConfig: InjectableRxStompConfig = {

    brokerURL: 'wss://WW.XX.YY.ZZ/messages/websocket',

    // ...

}

The Spring Boot configuration is the following:

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.setApplicationDestinationPrefixes("/app");
    config.enableSimpleBroker("/queue", "/user");
}

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

The Apache configuration is the following:

RewriteEngine On
ProxyRequests Off
ProxyPreserveHost On

<Location /messages/>
    ProxyPass ws://AA.BB.CC.DD:8080/messages/
    ProxyPassReverse ws://AA.BB.CC.DD:8080/messages/
</Location>
<Location / >
    ProxyPass http://AA.BB.CC.DD:8080/
    ProxyPassReverse http://AA.BB.CC.DD:8080/
</Location>

I've tested the following points:

  • Other Stackoverflow answers for this problem are not working for me
  • Redirecting from common requests (https -> http) is working fine
  • Connecting with final endpoint (ws://AA.BB.CC.DD:8080/messages/websocket) using this tool is working fine.
  • ws://AA.BB.CC.DD:8080/messages/websocket is working on localhost, for development purposes.

I've tried other solutions I've found on Stackoverflow without success.

0 Answers
Related