Skip to content

Commit

Permalink
Jetty 12 HTTP/2 support
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 Dec 6, 2023
1 parent 23fe9ba commit e045e3d
Show file tree
Hide file tree
Showing 60 changed files with 5,244 additions and 64 deletions.
12 changes: 6 additions & 6 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
<artifactId>jersey-jetty11-connector</artifactId>
<version>${project.version}</version>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jetty11-http2-connector</artifactId>
<artifactId>jersey-jetty-http2-connector</artifactId>
<version>${project.version}</version>
</dependency>--> <!-- TODO - HTTP/2 support for Jetty 12 container -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jdk-connector</artifactId>
Expand All @@ -118,11 +118,11 @@
<artifactId>jersey-container-jetty11-http</artifactId>
<version>${project.version}</version>
</dependency>
<!-- <dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty11-http2</artifactId>
<artifactId>jersey-container-jetty-http2</artifactId>
<version>${project.version}</version>
</dependency>--> <!-- TODO - HTTP/2 support for Jetty 12 container -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/apidocs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@
<includeDependencySources>true</includeDependencySources>
<sourceFileExcludes>
<fileExclude>META-INF/versions/12/org/glassfish/jersey/wadl/doclet/*.java</fileExclude>
<fileExclude>META-INF/versions/17/org/glassfish/jersey/jetty/*.java</fileExclude>
<fileExclude>META-INF/versions/17/org/glassfish/jersey/helidon/connector/*.java</fileExclude>
<fileExclude>org/glassfish/jersey/helidon/connector/*.java</fileExclude>
<fileExclude>META-INF/versions/17/org/glassfish/jersey/helidon/connector/*.java</fileExclude>
<fileExclude>org/glassfish/jersey/wadl/doclet/*.java</fileExclude>
</sourceFileExcludes>
<dependencySourceIncludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
* @author Arul Dhesiaseelan (aruld at acm.org)
* @author Marek Potociar
*/
class JettyConnector implements Connector {
public class JettyConnector implements Connector {

private static final Logger LOGGER = Logger.getLogger(JettyConnector.class.getName());

Expand All @@ -146,23 +146,17 @@ class JettyConnector implements Connector {
* @param jaxrsClient JAX-RS client instance, for which the connector is created.
* @param config client configuration.
*/
JettyConnector(final Client jaxrsClient, final Configuration config) {
public JettyConnector(final Client jaxrsClient, final Configuration config) {
this.configuration = config;
HttpClient httpClient = null;
if (config.isRegistered(JettyHttpClientSupplier.class)) {
Optional<Object> contract = config.getInstances().stream()
.filter(a-> JettyHttpClientSupplier.class.isInstance(a)).findFirst();
if (contract.isPresent()) {
httpClient = ((JettyHttpClientSupplier) contract.get()).getHttpClient();
}
}
HttpClient httpClient = getRegisteredHttpClient(config);

if (httpClient == null) {
final SSLContext sslContext = jaxrsClient.getSslContext();
final SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(false);
sslContextFactory.setSslContext(sslContext);
final ClientConnector connector = new ClientConnector();
connector.setSslContextFactory(sslContextFactory);
final HttpClientTransport transport = new HttpClientTransportOverHTTP(connector);
final HttpClientTransport transport = initClientTransport(connector);
httpClient = new HttpClient(transport);
}
this.client = httpClient;
Expand Down Expand Up @@ -231,6 +225,37 @@ class JettyConnector implements Connector {
this.cookieStore = client.getHttpCookieStore();
}

/**
* provides required HTTP client transport for client
*
* the default transport is {@link HttpClientTransportOverHTTP}
*
* @return instance of {@link HttpClientTransport}
* @since 2.41
*/
protected HttpClientTransport initClientTransport(ClientConnector clientConnector) {
return new HttpClientTransportOverHTTP(clientConnector);
}

/**
* provides custom registered {@link HttpClient} if any (or NULL)
*
* @param config configuration where {@link HttpClient} could be registered
* @return {@link HttpClient} instance if any was previously registered or NULL
*
* @since 2.41
*/
protected HttpClient getRegisteredHttpClient(Configuration config) {
if (config.isRegistered(JettyHttpClientSupplier.class)) {
Optional<Object> contract = config.getInstances().stream()
.filter(a-> JettyHttpClientSupplier.class.isInstance(a)).findFirst();
if (contract.isPresent()) {
return ((JettyHttpClientSupplier) contract.get()).getHttpClient();
}
}
return null;
}

/**
* Get the {@link HttpClient}.
*
Expand Down
273 changes: 273 additions & 0 deletions connectors/jetty-http2-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
<?xml version="1.0"?>
<!--
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>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>project</artifactId>
<version>3.1.99-SNAPSHOT</version>
</parent>

<artifactId>jersey-jetty-http2-connector</artifactId>
<packaging>jar</packaging>
<name>jersey-connectors-jetty-http2</name>

<description>Jersey Client Transport via Jetty</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java11.build.outputDirectory>${project.basedir}/target</java11.build.outputDirectory>
<java11.sourceDirectory>${project.basedir}/src/main/java11</java11.sourceDirectory>
<java17.build.outputDirectory>${project.basedir}/target17</java17.build.outputDirectory>
<java17.sourceDirectory>${project.basedir}/src/main/java17</java17.sourceDirectory>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jetty-connector</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-osgi</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.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</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>
</build>

<profiles>
<profile>
<id>JettyExclude</id>
<activation>
<jdk>[11,17)</jdk>
</activation>
<properties>
<jetty.version>${jetty11.version}</jetty.version>
</properties>
<build>
<directory>${java11.build.outputDirectory}</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${java11.sourceDirectory}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testExcludes>
<testExclude>org/glassfish/jersey/jetty/http2/connector/*.java</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>JettyInclude</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>jetty-http2-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>jetty-http2-client-transport</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http2</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty-http2</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<directory>${java17.build.outputDirectory}</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${java17.sourceDirectory}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>copyJDK17FilesToMultiReleaseJar</id>
<activation>
<file>
<!-- ${java17.build.outputDirectory} does not work here -->
<exists>target17/classes/org/glassfish/jersey/jetty/http2/connector/JettyHttp2Connector.class</exists>
</file>
<jdk>[11,17)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<instructions>
<Multi-Release>true</Multi-Release>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>copy-jdk17-classes</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${java11.build.outputDirectory}/classes/META-INF/versions/17</outputDirectory>
<resources>
<resource>
<directory>${java17.build.outputDirectory}/classes</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy-jdk17-sources</id>
<phase>package</phase>
<configuration>
<target>
<property name="sources-jar" value="${java11.build.outputDirectory}/${project.artifactId}-${project.version}-sources.jar"/>
<echo>sources-jar: ${sources-jar}</echo>
<zip destfile="${sources-jar}" update="true">
<zipfileset dir="${java17.sourceDirectory}" prefix="META-INF/versions/17"/>
</zip>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Loading

0 comments on commit e045e3d

Please sign in to comment.