From f5d7b81a161c2450713cd4073983a2cdd53a9cb8 Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Mon, 27 Mar 2023 10:30:10 +0200 Subject: [PATCH] HTTP/2 for Jetty container Signed-off-by: Maxim Nesen --- .../glassfish/jersey/jetty/JettyHttpContainerFactory.java | 5 ++++- .../org/glassfish/jersey/test/jetty/JettyContainerTest.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java index 1065c0ea0a..37349cec5d 100644 --- a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java +++ b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory; import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; +import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.server.ConnectionFactory; import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder; import org.glassfish.jersey.jetty.internal.LocalizationMessages; @@ -361,12 +362,14 @@ private static ConnectionFactory[] getConnectionFactories(String protocol, final SslContextFactory sslContextFactory) { final List factories = new ArrayList<>(); if (protocol.equalsIgnoreCase("h2")) { - factories.add(new HTTP2ServerConnectionFactory(config)); if (ssl) { + factories.add(new HTTP2ServerConnectionFactory(config)); final ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); alpn.setDefaultProtocol(protocol); factories.add(new SslConnectionFactory(sslContextFactory, alpn.getProtocol())); factories.add(alpn); + } else { + factories.add(new HTTP2CServerConnectionFactory(config)); } } else if (ssl) { factories.add(new SslConnectionFactory(sslContextFactory, "http/1.1")); diff --git a/test-framework/providers/jetty/src/test/java/org/glassfish/jersey/test/jetty/JettyContainerTest.java b/test-framework/providers/jetty/src/test/java/org/glassfish/jersey/test/jetty/JettyContainerTest.java index baa8abdc6b..426ad7be5a 100644 --- a/test-framework/providers/jetty/src/test/java/org/glassfish/jersey/test/jetty/JettyContainerTest.java +++ b/test-framework/providers/jetty/src/test/java/org/glassfish/jersey/test/jetty/JettyContainerTest.java @@ -17,6 +17,7 @@ package org.glassfish.jersey.test.jetty; import java.net.URI; +import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -114,7 +115,7 @@ public void testHttp2Container() { final ServiceLocator locator = new ServiceLocatorImpl("MyServiceLocator", null); final Server server = JettyHttpContainerFactory.createHttp2Server(URI.create("http://localhost:9876"), new ResourceConfig(Resource.class), true, locator); - JettyHttpContainer container = (JettyHttpContainer) server.getHandler(); - assertTrue(server.getConnectors()[0].getProtocols().contains("h2")); + final List protocols = server.getConnectors()[0].getProtocols(); + assertTrue(protocols.contains("h2") || protocols.contains("h2c")); } }