Copy JDK 11 Jetty classes to JDK 8 target (#4709)
* Copy JDK 11 Jetty classes to JDK 8 target
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
diff --git a/connectors/jetty-connector/pom.xml b/connectors/jetty-connector/pom.xml
index 58d9832..90761ac 100644
--- a/connectors/jetty-connector/pom.xml
+++ b/connectors/jetty-connector/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
- Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2011, 2021 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
@@ -122,19 +122,25 @@
<profiles>
<profile>
- <id>testsSkipJdk6</id>
- <activation>
- <jdk>1.6</jdk>
- </activation>
- <properties>
- <skip.tests>true</skip.tests>
- </properties>
- </profile>
- <profile>
<id>JettyExclude</id>
<activation>
<jdk>1.8</jdk>
</activation>
+ <properties>
+ <jetty.version>9.4.28.v20200408</jetty.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ </dependencies>
<build>
<directory>${java8.build.outputDirectory}</directory>
<plugins>
diff --git a/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientContract.java b/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientContract.java
new file mode 100644
index 0000000..b061ef5
--- /dev/null
+++ b/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientContract.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021 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.connector;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.glassfish.jersey.spi.Contract;
+
+/**
+ * A contract that allows for an optional registration of user predefined Jetty {@code HttpClient}
+ * that is consequently used by {@link JettyConnector}
+ */
+@Contract
+public interface JettyHttpClientContract {
+ /**
+ * Supply a user predefined HttpClient
+ * @return a user predefined HttpClient
+ */
+ HttpClient getHttpClient();
+}
diff --git a/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientSupplier.java b/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientSupplier.java
new file mode 100644
index 0000000..59c8fd3
--- /dev/null
+++ b/connectors/jetty-connector/src/main/java8/org/glassfish/jersey/jetty/connector/JettyHttpClientSupplier.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2021 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.connector;
+
+import jakarta.ws.rs.ProcessingException;
+import org.eclipse.jetty.client.HttpClient;
+import org.glassfish.jersey.internal.util.JdkVersion;
+
+/**
+ * Jetty HttpClient supplier to be registered into Jersey configuration to be used by {@link JettyConnector}.
+ * Not every possible configuration option is covered by the Jetty Connector and this supplier offers a way to provide
+ * an HttpClient that has configured the options not covered by the Jetty Connector.
+ * <p>
+ * Typical usage:
+ * </p>
+ * <pre>
+ * {@code
+ * HttpClient httpClient = ...
+ *
+ * ClientConfig config = new ClientConfig();
+ * config.connectorProvider(new JettyConnectorProvider());
+ * config.register(new JettyHttpClientSupplier(httpClient));
+ * Client client = ClientBuilder.newClient(config);
+ * }
+ * </pre>
+ * <p>
+ * The {@code HttpClient} is configured as if it was created by {@link JettyConnector} the usual way.
+ * </p>
+ */
+public class JettyHttpClientSupplier implements JettyHttpClientContract {
+ private final HttpClient httpClient;
+
+ /**
+ * {@code HttpClient} supplier to be optionally registered to a {@link org.glassfish.jersey.client.ClientConfig}
+ * @param httpClient a HttpClient to be supplied when {@link JettyConnector#getHttpClient()} is called.
+ */
+ public JettyHttpClientSupplier(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ @Override
+ public HttpClient getHttpClient() {
+ if (JdkVersion.getJdkVersion().getMajor() < 11) {
+ throw new ProcessingException(LocalizationMessages.NOT_SUPPORTED());
+ }
+ return null; // does not work at JDK 1.8
+ }
+}
diff --git a/containers/jetty-http/pom.xml b/containers/jetty-http/pom.xml
index a05052a..33f97ba 100644
--- a/containers/jetty-http/pom.xml
+++ b/containers/jetty-http/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2013, 2021 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
@@ -100,6 +100,21 @@
<activation>
<jdk>1.8</jdk>
</activation>
+ <properties>
+ <jetty.version>9.4.28.v20200408</jetty.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ </dependencies>
<build>
<directory>${java8.build.outputDirectory}</directory>
<plugins>
diff --git a/containers/jetty-http/src/main/java8/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java b/containers/jetty-http/src/main/java8/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java
new file mode 100644
index 0000000..1218c2e
--- /dev/null
+++ b/containers/jetty-http/src/main/java8/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2021 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 jakarta.ws.rs.ProcessingException;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.glassfish.jersey.internal.util.JdkVersion;
+import org.glassfish.jersey.jetty.internal.LocalizationMessages;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import java.net.URI;
+
+/**
+ * Jersey {@code Container} stub.
+ *
+ * For JDK 1.8 only since Jetty 11 does not support JDKs below 11
+ *
+ */
+public final class JettyHttpContainerFactory {
+
+ private JettyHttpContainerFactory() {
+ }
+
+ public static Server createServer(final URI uri) throws ProcessingException {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final boolean start) throws ProcessingException {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final ResourceConfig config)
+ throws ProcessingException {
+
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final ResourceConfig configuration, final boolean start)
+ throws ProcessingException {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final ResourceConfig config, final boolean start,
+ final Object parentContext) {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final ResourceConfig config, final Object parentContext) {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ public static Server createServer(final URI uri, final SslContextFactory.Server sslContextFactory,
+ final ResourceConfig config)
+ throws ProcessingException {
+ validateJdk();
+ return null; // does not work at JDK 1.8 }
+ }
+
+ public static Server createServer(final URI uri,
+ final SslContextFactory.Server sslContextFactory,
+ final JettyHttpContainer handler,
+ final boolean start) {
+ validateJdk();
+ return null; // does not work at JDK 1.8
+ }
+
+ private static void validateJdk() {
+ if (JdkVersion.getJdkVersion().getMajor() < 11) {
+ throw new ProcessingException(LocalizationMessages.NOT_SUPPORTED());
+ }
+ }
+}