Skip to content

websocket + http2 #1364

@ramarro123

Description

@ramarro123

Hello,

i am trying to se websocket with an http2 server-enabled embedded on my app.

when i connect via wss:// i got an exception on chrome
if i try the http port, the websocket work.

removing http2 will bring back websocket to life even on ssl.

there are any specific configuration for websocket on http2 connector?

here is a small code snippet


            if (!new File(keyFile).exists()) {
                throw new EError(EError.EErrorKind.CFG_ERROR, "missing keyFile for ssl (https) please use an absolute path! " + keyFile);
            }
            // SSL configurations

            // We need a SSLContextFactory for the SSL encryption. That SSLContextFactory will be used by the SPDY
            // connector.
            SslContextFactory sslContextFactory = new SslContextFactory();

            sslContextFactory.setKeyStorePath(keyFile);
            sslContextFactory.setKeyStorePassword(keyPass);

            sslContextFactory.setProtocol("TLSv1.2");


            sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
            sslContextFactory.setUseCipherSuitesOrder(true);

            try {
                HttpConfiguration https_config = new HttpConfiguration(config);
                https_config.addCustomizer(new SecureRequestCustomizer());

                ALPN.debug = true;

                ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
                https.setPort(securePort);

                server.addConnector(https);

                ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
                alpn.setDefaultProtocol(httpConnector.getDefaultProtocol());

                ServerConnector https2 = new ServerConnector(server,
                        new SslConnectionFactory(sslContextFactory, alpn.getProtocol()),
                        alpn,
                        new HTTP2ServerConnectionFactory(https_config)

                );
                https2.setPort(securePort + 1);

                server.addConnector(https2);

            } catch (Throwable e1) {
                Logger.warn(e1, JWebServer.class.getName());
            }

            ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
            context.addAliasCheck(new AllowSymLinkAliasChecker());

            context.setDisplayName("C3 - Web");
            context.getMimeTypes().setMimeMap(MimeType.getAll());


            ServletHolder webSocket = new ServletHolder(new JWebSocket(this));
            webSocket.setInitParameter("minVersion", "-1");
            webSocket.setInitParameter("bufferSize", Integer.toString(WebConstant.bufferSize));
            webSocket.setInitParameter("maxIdleTime", String.valueOf(Util.MIN * 30));

            context.addServlet(webSocket, "/websocket");

            GzipHandler gzipHandler = new GzipHandler();
            gzipHandler.setHandler(context);

    
            server.setHandler(gzipHandler);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions