Skip to content

Commit

Permalink
HTTP/2 for Jetty container
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Mar 27, 2023
1 parent a3a2d19 commit f5d7b81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -361,12 +362,14 @@ private static ConnectionFactory[] getConnectionFactories(String protocol,
final SslContextFactory sslContextFactory) {
final List<ConnectionFactory> 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> protocols = server.getConnectors()[0].getProtocols();
assertTrue(protocols.contains("h2") || protocols.contains("h2c"));
}
}

0 comments on commit f5d7b81

Please sign in to comment.