I managed to get things working after upgrading to Java11, but I needed to apply a few changes to JettyFactoryImpl. I'm unsure how alpn/h2 support is functional for others with the current state of the code.
When we find ALPN classes (alpnClassesAvailable), the main thing is that SSLConnectionFactory will lead to alpn and not to h2 following (significant changes are in bold):
//SAME
Class<?> comparatorClass = bundle.loadClass("org.eclipse.jetty.http2.HTTP2Cipher");
Comparator<String> cipherComparator = (Comparator<String>) FieldUtils.readDeclaredStaticField(comparatorClass, "COMPARATOR");
sslContextFactory.setCipherComparator(cipherComparator);
// Say that SSL should support alpn, not h2
sslFactory = new SslConnectionFactory(sslContextFactory, "alpn");
// was sslFactory = new SslConnectionFactory(sslContextFactory, "h2");
connectionFactories.add(sslFactory);
Class<?> loadClass = bundle.loadClass("org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory");
http2Factory = (AbstractConnectionFactory) ConstructorUtils.invokeConstructor(loadClass, httpsConfig);
connectionFactories.add(http2Factory);
//Explicitely configure ALPN
loadClass = bundle.loadClass("org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory");
alpnFactory = (NegotiatingServerConnectionFactory) ConstructorUtils.invokeConstructor(loadClass, (Object) new String[] {"ssl", "h2", "http/1.1"});
alpnFactory.setDefaultProtocol("h2");
connectionFactories.add(alpnFactory);
This leads the server to serve up h2 requests unless we explicitely requested http1.1.
Do these changes make sense to you?
The negociation process succeeds with both:
curl -v for all requests lists:
* ALPN, offering h2
* ALPN, offering http/1.1
* ALPN, server accepted to use http/1.1
-v lists: * * ALPN, server accepted to use h2
Please let me know if these changes make sense. If so, let me know if you want a PR.
Regards,
Stephane Vaucher