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 37349cec5d6..de905b37a88 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 @@ -244,6 +244,25 @@ public static Server createServer(final URI uri, return createGeneralHttpServer(uri, sslContextFactory, handler, start, "http/1.1"); } + /** + * Creates HTTP/2 enabled {@link Server} instance that registers an {@link org.eclipse.jetty.server.Handler}. + * + * @param uri uri on which the {@link org.glassfish.jersey.server.ApplicationHandler} will be deployed. Only first path + * segment will be used as context path, the rest will be ignored. + * @param start if set to false, server will not get started, which allows to configure the underlying transport + * layer, see above for details. + * @return newly created {@link Server}. + * + * @throws ProcessingException in case of any failure when creating a new Jetty {@code Server} instance. + * @throws IllegalArgumentException if {@code uri} is {@code null}. + * + * @since 2.40 + */ + + public static Server createHttp2Server(final URI uri, final boolean start) throws ProcessingException { + return createHttp2Server(uri, null, null, start); + } + /** * Create HTTP/2 enabled {@link Server} that registers an {@link org.eclipse.jetty.server.Handler} that * in turn manages all root resource and provider classes declared by the diff --git a/containers/jetty-servlet/src/main/java/org/glassfish/jersey/jetty/servlet/JettyWebContainerFactory.java b/containers/jetty-servlet/src/main/java/org/glassfish/jersey/jetty/servlet/JettyWebContainerFactory.java index dd585ce49af..12842a3843a 100644 --- a/containers/jetty-servlet/src/main/java/org/glassfish/jersey/jetty/servlet/JettyWebContainerFactory.java +++ b/containers/jetty-servlet/src/main/java/org/glassfish/jersey/jetty/servlet/JettyWebContainerFactory.java @@ -69,6 +69,15 @@ public static Server create(String u) return create(URI.create(u)); } + public static Server createHttp2(String u) + throws Exception { + if (u == null) { + throw new IllegalArgumentException("The URI must not be null"); + } + + return createHttp2(URI.create(u)); + } + /** * Create a {@link Server} that registers the {@link ServletContainer}. * @@ -91,6 +100,15 @@ public static Server create(String u, Map initParams) return create(URI.create(u), initParams); } + public static Server createHttp2(String u, Map initParams) + throws Exception { + if (u == null) { + throw new IllegalArgumentException("The URI must not be null"); + } + + return createHttp2(URI.create(u), initParams); + } + /** * Create a {@link Server} that registers the {@link ServletContainer}. * @@ -108,6 +126,11 @@ public static Server create(URI u) return create(u, ServletContainer.class); } + public static Server createHttp2(URI u) + throws Exception { + return createHttp2(u, ServletContainer.class); + } + /** * Create a {@link Server} that registers the {@link ServletContainer}. * @@ -126,6 +149,11 @@ public static Server create(URI u, Map initParams) return create(u, ServletContainer.class, initParams); } + public static Server createHttp2(URI u, Map initParams) + throws Exception { + return createHttp2(u, ServletContainer.class, initParams); + } + /** * Create a {@link Server} that registers the declared * servlet class. @@ -149,6 +177,15 @@ public static Server create(String u, Class c) return create(URI.create(u), c); } + public static Server createHttp2(String u, Class c) + throws Exception { + if (u == null) { + throw new IllegalArgumentException("The URI must not be null"); + } + + return createHttp2(URI.create(u), c); + } + /** * Create a {@link Server} that registers the declared * servlet class. @@ -174,6 +211,16 @@ public static Server create(String u, Class c, return create(URI.create(u), c, initParams); } + public static Server createHttp2(String u, Class c, + Map initParams) + throws Exception { + if (u == null) { + throw new IllegalArgumentException("The URI must not be null"); + } + + return createHttp2(URI.create(u), c, initParams); + } + /** * Create a {@link Server} that registers the declared * servlet class. @@ -193,6 +240,11 @@ public static Server create(URI u, Class c) return create(u, c, null); } + public static Server createHttp2(URI u, Class c) + throws Exception { + return createHttp2(u, c, null); + } + /** * Create a {@link Server} that registers the declared * servlet class. @@ -210,11 +262,17 @@ public static Server create(URI u, Class c) */ public static Server create(URI u, Class c, Map initParams) throws Exception { - return create(u, c, null, initParams, null); + return create(u, c, null, initParams, null, "http/1.1"); + } + + public static Server createHttp2(URI u, Class c, Map initParams) + throws Exception { + return create(u, c, null, initParams, null, "h2"); } private static Server create(URI u, Class c, Servlet servlet, - Map initParams, Map contextInitParams) + Map initParams, Map contextInitParams, + String protocol) throws Exception { if (u == null) { throw new IllegalArgumentException("The URI must not be null"); @@ -252,7 +310,8 @@ private static Server create(URI u, Class c, Servlet servlet, holder.setInitParameters(initParams); } - Server server = JettyHttpContainerFactory.createServer(u, false); + final Server server = (protocol.equalsIgnoreCase("h2")) ? JettyHttpContainerFactory.createHttp2Server(u, false) + : JettyHttpContainerFactory.createServer(u, false); server.setHandler(context); server.start(); return server; @@ -279,6 +338,14 @@ public static Server create(URI u, Servlet servlet, Map initPara if (servlet == null) { throw new IllegalArgumentException("The servlet must not be null"); } - return create(u, null, servlet, initParams, contextInitParams); + return create(u, null, servlet, initParams, contextInitParams, "http/1.1"); + } + + public static Server createHttp2(URI u, Servlet servlet, Map initParams, Map contextInitParams) + throws Exception { + if (servlet == null) { + throw new IllegalArgumentException("The servlet must not be null"); + } + return create(u, null, servlet, initParams, contextInitParams, "h2"); } }