private ALPNServerConnectionFactory createAlpnProtocolFactory( HttpConnectionFactory httpConnectionFactory) { NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable(); ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); alpn.setDefaultProtocol(httpConnectionFactory.getProtocol()); return alpn; }
/** * Configure the http2 server. * * @param server the server * @return the server */ @VisibleForTesting Server configureServerForHttp2(Server server) { // HTTP Configuration HttpConfiguration http11Config = new HttpConfiguration(); http11Config.setSecureScheme("https"); http11Config.setSecurePort(httpsPort); // SSL Context Factory for HTTPS and HTTP/2 SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(newClassPathResource("sample.jks")); sslContextFactory.setKeyStorePassword("secret"); sslContextFactory.setKeyManagerPassword("secret"); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); sslContextFactory.setUseCipherSuitesOrder(true); // HTTPS Configuration HttpConfiguration httpsConfig = new HttpConfiguration(http11Config); httpsConfig.addCustomizer(new SecureRequestCustomizer()); // HTTP/2 Connection Factory HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig); NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable(); ALPNServerConnectionFactory alpnServerConnectionFactory = new ALPNServerConnectionFactory(); alpnServerConnectionFactory.setDefaultProtocol("h2"); alpnServerConnectionFactory.getALPNProcessor(); // SSL Connection Factory SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, alpnServerConnectionFactory.getProtocol()); // HTTP/2 Connector ServerConnector http2Connector = new ServerConnector(server, sslConnectionFactory, alpnServerConnectionFactory, h2, new HttpConnectionFactory(httpsConfig)); http2Connector.setPort(httpPort); server.addConnector(http2Connector); return server; }