-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
- Loading branch information
Showing
14 changed files
with
775 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0, which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>project</artifactId> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<version>2.40-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jersey-container-jetty-http2</artifactId> | ||
<packaging>jar</packaging> | ||
<name>jersey-container-jetty-http2</name> | ||
|
||
<description>Jetty Http2 Container</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-jetty-http</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.hk2.external</groupId> | ||
<artifactId>jakarta.inject</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-util</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-continuation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.http2</groupId> | ||
<artifactId>http2-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-alpn-conscrypt-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.sun.istack</groupId> | ||
<artifactId>istack-commons-maven-plugin</artifactId> | ||
<inherited>true</inherited> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<inherited>true</inherited> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<inherited>true</inherited> | ||
<configuration> | ||
<instructions> | ||
<Import-Package> | ||
${jetty.osgi.version}, | ||
* | ||
</Import-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
|
||
<resources> | ||
<resource> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
</project> |
213 changes: 213 additions & 0 deletions
213
...ners/jetty-http2/src/main/java/org/glassfish/jersey/jetty/JettyHttp2ContainerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.jetty; | ||
|
||
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory; | ||
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; | ||
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; | ||
import org.eclipse.jetty.server.ConnectionFactory; | ||
import org.eclipse.jetty.server.Connector; | ||
import org.eclipse.jetty.server.HttpConfiguration; | ||
import org.eclipse.jetty.server.HttpConnectionFactory; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.server.SslConnectionFactory; | ||
import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
import org.glassfish.jersey.jetty.internal.LocalizationMessages; | ||
import org.glassfish.jersey.server.ContainerFactory; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
|
||
import javax.ws.rs.ProcessingException; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class JettyHttp2ContainerFactory { | ||
|
||
private JettyHttp2ContainerFactory() { | ||
|
||
} | ||
|
||
/** | ||
* 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. | ||
* @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}. | ||
*/ | ||
public static Server createHttp2Server(final URI uri) throws ProcessingException { | ||
return createHttp2Server(uri, null, null, true); | ||
} | ||
|
||
/** | ||
* 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 | ||
* resource configuration. | ||
* <p/> | ||
* This implementation defers to the | ||
* {@link org.glassfish.jersey.server.ContainerFactory#createContainer(Class, javax.ws.rs.core.Application)} method | ||
* for creating an Container that manages the root resources. | ||
* | ||
* @param uri URI on which the Jersey web application will be deployed. Only first path segment will be | ||
* used as context path, the rest will be ignored. | ||
* @param configuration web application configuration. | ||
* @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}. | ||
*/ | ||
public static Server createHttp2Server(final URI uri, final ResourceConfig configuration, final boolean start) | ||
throws ProcessingException { | ||
return createHttp2Server(uri, null, | ||
ContainerFactory.createContainer(JettyHttpContainer.class, configuration), start); | ||
} | ||
|
||
/** | ||
* 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 | ||
* resource configuration. | ||
* | ||
* @param uri the URI to create the http server. The URI scheme must be | ||
* equal to "https". The URI user information and host | ||
* are ignored If the URI port is not present then port 143 will be | ||
* used. The URI path, query and fragment components are ignored. | ||
* @param config the resource configuration. | ||
* @param parentContext DI provider specific context with application's registered bindings. | ||
* @param start if set to false, server will not get started, this allows end users to set | ||
* additional properties on the underlying listener. | ||
* @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}. | ||
* @see JettyHttpContainer | ||
* | ||
* @since 2.40 | ||
*/ | ||
public static Server createHttp2Server(final URI uri, final ResourceConfig config, final boolean start, | ||
final Object parentContext) { | ||
return createHttp2Server(uri, null, new JettyHttpContainer(config, parentContext), 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 found by searching the | ||
* classes referenced in the java classpath. | ||
* | ||
* @param uri the URI to create the http server. The URI scheme must be | ||
* equal to {@code https}. The URI user information and host | ||
* are ignored. If the URI port is not present then port | ||
* {@value org.glassfish.jersey.server.spi.Container#DEFAULT_HTTPS_PORT} will be | ||
* used. The URI path, query and fragment components are ignored. | ||
* @param sslContextFactory this is the SSL context factory used to configure SSL connector | ||
* @param handler the container that handles all HTTP requests | ||
* @param start if set to false, server will not get started, this allows end users to set | ||
* additional properties on the underlying listener. | ||
* @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}. | ||
* @see JettyHttpContainer | ||
* | ||
* @since 2.40 | ||
*/ | ||
public static Server createHttp2Server(final URI uri, | ||
final SslContextFactory sslContextFactory, | ||
final JettyHttpContainer handler, | ||
final boolean start) { | ||
|
||
/** | ||
* Creating basic Jetty HTTP/1.1 container (but always not started) | ||
*/ | ||
final Server server = JettyHttpContainerFactory.createServer(uri, sslContextFactory, handler, false); | ||
/** | ||
* Obtain configured HTTP connection factory | ||
*/ | ||
final ServerConnector httpServerConnector = (ServerConnector) server.getConnectors()[0]; | ||
final HttpConnectionFactory httpConnectionFactory = httpServerConnector.getConnectionFactory(HttpConnectionFactory.class); | ||
|
||
/** | ||
* Obtain prepared config | ||
*/ | ||
final HttpConfiguration config = httpConnectionFactory.getHttpConfiguration(); | ||
|
||
/** | ||
* Add required H2/H2C connection factories using pre-configured config from the HTTP/1.1 server | ||
*/ | ||
final List<ConnectionFactory> factories = getConnectionFactories(config, sslContextFactory); | ||
factories.add(httpConnectionFactory); | ||
|
||
/** | ||
* replacing connectors for H2/H2C protocol | ||
*/ | ||
httpServerConnector.setConnectionFactories(factories); | ||
server.setConnectors(new Connector[]{httpServerConnector}); | ||
|
||
/** | ||
* Starting the server if required | ||
*/ | ||
if (start) { | ||
try { | ||
// Start the server. | ||
server.start(); | ||
} catch (final Exception e) { | ||
throw new ProcessingException(LocalizationMessages.ERROR_WHEN_CREATING_SERVER(), e); | ||
} | ||
} | ||
return server; | ||
} | ||
|
||
private static List<ConnectionFactory> getConnectionFactories( | ||
final HttpConfiguration config, | ||
final SslContextFactory sslContextFactory) { | ||
final List<ConnectionFactory> factories = new ArrayList<>(); | ||
if (sslContextFactory != null) { | ||
factories.add(new HTTP2ServerConnectionFactory(config)); | ||
final ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); | ||
alpn.setDefaultProtocol("h2"); | ||
factories.add(new SslConnectionFactory(sslContextFactory, alpn.getProtocol())); | ||
factories.add(alpn); | ||
} else { | ||
factories.add(new HTTP2CServerConnectionFactory(config)); | ||
} | ||
|
||
return factories; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ers/jetty-http2/src/main/java/org/glassfish/jersey/jetty/JettyHttp2ContainerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.jetty; | ||
|
||
import org.eclipse.jetty.server.Handler; | ||
import org.glassfish.jersey.server.spi.ContainerProvider; | ||
|
||
import javax.ws.rs.ProcessingException; | ||
import javax.ws.rs.core.Application; | ||
|
||
public final class JettyHttp2ContainerProvider implements ContainerProvider { | ||
|
||
@Override | ||
public <T> T createContainer(final Class<T> type, final Application application) throws ProcessingException { | ||
if (Handler.class == type || JettyHttpContainer.class == type) { | ||
return type.cast(new JettyHttpContainer(application)); | ||
} | ||
return null; | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
containers/jetty-http2/src/main/java/org/glassfish/jersey/jetty/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
/** | ||
* Jersey Jetty HTTP2 container classes. | ||
*/ | ||
package org.glassfish.jersey.jetty; |
1 change: 1 addition & 0 deletions
1
...p2/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ContainerProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.glassfish.jersey.jetty.JettyHttp2ContainerProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.