eclipse-ee4j / tyrus

Tyrus
Other
113 stars 36 forks source link

why there is no documentation for enabling ssl in websocket server ? #882

Open AhmedHumk opened 8 months ago

AhmedHumk commented 8 months ago

currently i initiate my websocket server as following

tyrusServer = new Server("localhost", port, "/"+contextpath, null, ServerEndPoint_Jakarta.class);

I have checked the Tyrus Server properties it doesn't provide any ssl properties how to enable wss in tyrus server ?

jansupol commented 8 months ago

Tyrus server is designed to be run in a container such as Servlet Container in an application server (Tomcat, Glassfish), or Grizzly (NIO server).

The SSL/TLS handshake occurs before the HTTP upgrade and it is handled by the container. Tyrus receives the HTTP request only after the SSL/TLS if that one is successful. Hence, the SSL/TLS needs to be configured for the container you run Tyrus in rather than for Tyrus Server itself.

AhmedHumk commented 7 months ago

i couldnt figure out how to enable wss in my tyrus server i spent serveral days though.. i found a few snippets but how to assign it to the websocket server ?

                // SSL configuration
            SSLContextConfigurator sslContext = new SSLContextConfigurator();
            sslContext.setKeyStoreFile("path/to/keystore.jks");
            sslContext.setKeyStorePass("keystore-password");

            // Set up SSL/TLS for Grizzly
            SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator(sslContext).setClientMode(false);

        tyrusServer = new Server("localhost", port, "/"+contextpath, serverProperties, ServerEndPoint_Jakarta.class);
jansupol commented 7 months ago

You do not assign it to the WebSocket/Tyrus Server. You do assign it:

jansupol commented 7 months ago

You can see the Readme in the HTTPS example for Glassfish using the default certificate.

AhmedHumk commented 7 months ago

I will move on from here ..since there is no accurate documentation for such important feature. Obviously that the websocket server in java is running under Grizzly Container which there is no way to get that container or event initiating custom one. i looked at the demo you have provided and all the links in the readme file to refer to SSL part are invalid. I have been sticking around Tyrus documentation for a while .. it lacks a lot of important stuff..