That said, throughout my coding, it was generally uneventful. That is, until I tried deploying the package into the cloud. The WildFly was sitting behind Apache acting as the proxy, and this was where the problem manifested itself. The issue was compounded by the use of HTTPS, but only running on the proxy; with WildFly only listening for HTTP.
It took quite some time for me to figure out a solution on my own. If your setup is using the stack from Bitnami similar to mine then I certainly hope you'll find this post useful.
Assumptions:
- Your Bitnami stack is up and running correctly;
- WildFly is listening internally on :8080 port;
- You have complete access to your WildFly management console;
- Your app can be deployed successfully to WildFly;
- Both WildFly and Apache are sited on the same machine/instance;
- Apache has been configured with a SSL certificate for proper HTTPS operation;
- Apache is functioning normally for regular HTTP/HTTPS traffic
- Apache error log should indicate an excessive amount of traffic due to the websocket
- Apache access log should indicate HTTP 502 or similar erroneous codes
- httpd.conf should already have uncommented the LoadModule lines for mod_proxy and all its modules, especially mod_proxy_wstunnel.so
<IfModule proxy_wstunnel_module>Do the same for both HTTP (port :80) and HTTPS (port :443) traffic. And then restart Apache.
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/(.*)$ ws://localhost:8080/$1 [P,L]
</IfModule>
It took me a while to realise, after enabling the Apache debug log level, that
- There is never any wss:// used by WildFly because I'm do not have the HTTPS listener setup; just the vanilla HTTP;
- Redirecting to ws://www.mysite.com/$1 would not work either, because that's still throwing the same request to Apache;
- Redirecting to ws://localhost/$1 would not work, because that's equally requesting to Apache itself;