Spring server architecture for backend using ssl and websockets

I wrote a server backend for an app that I created. The app connects to the backend via https protocol and it also opens a websocket using the wss protocol. The app will make requests over http and receive push notifications via the websocket. One more thing I would like to add is that my server is behind haproxy, to allow for horizontal scaling. I have a certificate I bought that is served up by the web server. I am not using a self signed certificate.

The websockets keep disconnecting, and after some experimentation it seems that disabling ssl in the spring boot server solves this problem. From what I understand, it is highly recommended that the app connect to the backend using ssl and https, but this approach does not seem to work for the websockets. What is the best way to solve this problem? Ideally I would like the app to make requests using https and make a websocket connection without using ssl, unless there is some solution to the disconnecting issue. Is this possible in spring?

If I cannot solve the websocket disconnect issue then my next idea would be to create another spring boot server that is solely responsible for handling the websockets, but it would be better if I can use a single server for both https requests and websockets. What is the best architecture to solve this problem?

I ended up finding a solution. It was to run another tomcat connector on port 8080 and use http(ws) rather than https(wss) when connecting to the websocket, while using https when making server requests.

Leave a Comment