I have the following code which should setup a secure websocket endpoint in a stand alone Java application (jnlp triggered) and allow me to connect from a client (Javascript in the browser) with the url: ws://localhost:8444/echo
The server starts up without errors, but I cannot connect:
WebSocket connection to 'wss://localhost:8444/echo' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED
server = new Server();
SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setKeyStorePath("/path/keys/keystore.jks");
contextFactory.setKeyStorePassword("changeit");
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString());
ServerConnector connector = new ServerConnector(server, sslConnectionFactory);
connector.setPort(8444);
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
HandlerCollection hc = new HandlerCollection();
hc.addHandler(contextHandler);
server.setHandler(contextHandler);
server.addConnector(connector);
// Add websocket servlet
ServletHolder wsHolder = new ServletHolder("echo",new EchoSocketServlet());
contextHandler.addServlet(wsHolder,"/echo");
try
{
server.start();
server.join();
}
catch (Exception e)
{
e.printStackTrace();
}
If anyone can spot an obvious error in the above, some feedback would be appreciated. Also, I can successfully connect to the above when I remove the SslConnectionFactory and connect using non SSL Websocket URL (ws://).