Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions org.restlet.java/org.restlet.ext.jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,38 @@
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<artifactId>jetty-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>jetty-http2-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${lib-jetty-version}</version>
<artifactId>jetty-alpn-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http3</groupId>
<artifactId>jetty-http3-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.quic</groupId>
<artifactId>jetty-quic-server</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${lib-jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
* <tr>
* <td>httpClientTransportMode</td>
* <td>String</td>
* <td>HTTP11</td>
* <td>HTTP1_1</td>
* <td>Indicate the HTTP client transport mode among the following options:
* "HTTP11", "HTTP2", "HTTP3", "DYNAMIC. See {@link HttpClientTransport}.</td>
* "HTTP1_1", "HTTP2", "HTTP3", "DYNAMIC". See {@link HttpClientTransport}.</td>
* </tr>
* <tr>
* <td>idleTimeout</td>
Expand Down Expand Up @@ -291,10 +291,10 @@ protected HttpClient createHttpClient() {
case "HTTP2" -> getHttpClientTransportForHttp2();
case "HTTP3" -> getHttpClientTransportForHttp3(sslContextFactory);
case "DYNAMIC" -> getHttpClientTransportForDynamicMode(sslContextFactory);
case "HTTP11" -> getHttpTransportForHttp1_1();
case "HTTP1_1" -> getHttpTransportForHttp1_1();
default -> {
getLogger().log(Level.WARNING,
"Unknown HTTP client transport mode: {0}, default to HTTP11", httpClientTransportMode);
"Unknown HTTP client transport mode: {0}, default to HTTP1_1", httpClientTransportMode);
yield getHttpTransportForHttp1_1();
}
};
Expand Down Expand Up @@ -515,14 +515,14 @@ public String getHttpComplianceMode() {

/**
* Returns the HTTP client transport mode among the following options:
* "HTTP11", "HTTP2", "HTTP3", "DYNAMIC. See {@link HttpClientTransport}.
* Defaults to "HTTP11".
* "HTTP1_1", "HTTP2", "HTTP3", "DYNAMIC. See {@link HttpClientTransport}.
* Default to "HTTP1_1".
*
* @return The HTTP client transport mode.
*/
public String getHttpClientTransportMode() {
return getHelpedParameters().getFirstValue("httpClientTransportMode",
"HTTP11");
"HTTP1_1");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.restlet.ext.jetty;

import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
Expand All @@ -17,7 +18,16 @@

/**
* Jetty HTTP server connector.
*
*
* <table>
* <caption>list of supported parameters</caption>
* <tr>
* <td>http.transport.mode</td>
* <td>string</td>
* <td>http1</td>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thboileau Could we use "HTTP1_1" and "HTTP2" for consistency with the protocol version and client-side parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thanks

* <td>Supported protocol. Values: http1 or http2. The protocol HTTP 1.1 is always supported, the support of HTTP 2 is done thanks to upgrade from HTTP 1.1 protocol.</td>
* </tr>
* </table>
* @author Jerome Louvel
* @author Tal Liron
*/
Expand All @@ -41,8 +51,31 @@ public HttpServerHelper(Server server) {
@Override
protected ConnectionFactory[] createConnectionFactories(
final HttpConfiguration configuration) {
return new ConnectionFactory[] {
new HttpConnectionFactory(configuration) };
final ConnectionFactory[] result;

final String httpTransportProtocolAsString = getHttpTransportProtocol();
result = switch (httpTransportProtocolAsString) {
case "http1" -> new ConnectionFactory[] { new HttpConnectionFactory(configuration) };
case "http2" -> new ConnectionFactory[] {
new HttpConnectionFactory(configuration), // still necessary to support protocol upgrade
new HTTP2CServerConnectionFactory(configuration)
};
default -> {
final String errorMessage = String.format("'%s' is not one of the supported value: [http1, http2]", httpTransportProtocolAsString);
throw new IllegalArgumentException(errorMessage);
}
};

return result;
}

/**
* Supported HTTP transport protocol. Defaults to http1.
*
* @return Supported HTTP transport protocol.
*/
public String getHttpTransportProtocol() {
return getHelpedParameters().getFirstValue("http.transport.protocol", "http1");
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Copyright 2005-2024 Qlik
*
* <p>
* The contents of this file is subject to the terms of the Apache 2.0 open
* source license available at http://www.opensource.org/licenses/apache-2.0
*
* <p>
* Restlet is a registered trademark of QlikTech International AB.
*/

package org.restlet.ext.jetty;

import java.util.logging.Level;

import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.AbstractConnectionFactory;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration;
Expand All @@ -21,6 +21,11 @@
import org.restlet.engine.ssl.DefaultSslContextFactory;
import org.restlet.ext.jetty.internal.RestletSslContextFactoryServer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;

/**
* Jetty HTTPS server connector. Here is the list of additional parameters that
* are supported. They should be set in the Server's context before it is
Expand All @@ -41,10 +46,16 @@
* parameter, or an instance as an attribute for a more complete and flexible
* SSL context setting</td>
* </tr>
* <tr>
* <td>http.transport.protocols</td>
* <td>string</td>
* <td>http1</td>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about "HTTP1_1"

* <td>Coma separated and sorted list of supported protocols. Values: http1, http2, http3.</td>
* </tr>
* </table>
* For the default SSL parameters see the Javadocs of the
* {@link DefaultSslContextFactory} class.
*
*
* @see <a href=
* "https://jetty.org/docs/jetty/12/operations-guide/keystore/index.html">How
* to configure SSL for Jetty</a>
Expand All @@ -55,7 +66,7 @@ public class HttpsServerHelper extends JettyServerHelper {

/**
* Constructor.
*
*
* @param server The server to help.
*/
public HttpsServerHelper(Server server) {
Expand All @@ -64,21 +75,50 @@ public HttpsServerHelper(Server server) {
}

@Override
protected ConnectionFactory[] createConnectionFactories(
HttpConfiguration configuration) {
protected ConnectionFactory[] createConnectionFactories(HttpConfiguration configuration) {
ConnectionFactory[] result;

try {
final List<ConnectionFactory> connectionFactories = new ArrayList<>();

for (String httpTransportProtocolAsString : getHttpTransportProtocols()) {
switch (httpTransportProtocolAsString) {
case "http1":
connectionFactories.add(new HttpConnectionFactory(configuration));
break;
case "http2":
connectionFactories.add(new ALPNServerConnectionFactory());
connectionFactories.add(new HTTP2ServerConnectionFactory(configuration));
break;
default:
final String errorMessage = String.format("'%s' is not one of the supported value: [http1, http2]", httpTransportProtocolAsString);
throw new IllegalArgumentException(errorMessage);
}
}

SslContextFactory.Server sslContextFactory = new RestletSslContextFactoryServer(
org.restlet.engine.ssl.SslUtils.getSslContextFactory(this));
result = AbstractConnectionFactory.getFactories(sslContextFactory,
new HttpConnectionFactory(configuration));

result = AbstractConnectionFactory.getFactories(sslContextFactory, connectionFactories.toArray(new ConnectionFactory[0]));
} catch (RuntimeException e) {
getLogger().log(Level.WARNING, "Unable to create the Jetty SSL context factory", e);
throw e;
} catch (Exception e) {
result = null;
getLogger().log(Level.WARNING,
"Unable to create the Jetty SSL context factory", e);
getLogger().log(Level.WARNING, "Unable to create the Jetty SSL context factory", e);
throw new RuntimeException(e);
}

return result;
}

/**
* Supported HTTP transport protocol. Defaults to http1.
*
* @return Supported HTTP transport protocol.
*/
public List<String> getHttpTransportProtocols() {
String httpTransportProtocolsAsString = getHelpedParameters().getFirstValue("http.transport.protocols", "http1");
return Arrays.stream(httpTransportProtocolsAsString.split(","))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.net.Socket;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.Executor;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@
* <td>int</td>
* <td>-1</td>
* <td>Connector selector thread count; When less or equal than 0,
* Jetty computes a default value derived from a heuristic over available CPUs and thread pool size.}</td>
* Jetty computes a default value derived from a heuristic over available CPUs and thread pool size.</td>
* </tr>
* <tr>
* <td>connector.acceptQueueSize</td>
Expand All @@ -97,13 +98,6 @@
* is read or written, then the timeout is reset</td>
* </tr>
* <tr>
* <td>connector.soLingerTime</td>
* <td>int</td>
* <td>-1</td>
* <td>Connector TCP/IP SO linger time in milliseconds; when -1 is disabled; see
* {@link Socket#setSoLinger(boolean, int)}</td>
* </tr>
* <tr>
* <td>connector.stopTimeout</td>
* <td>long</td>
* <td>30000</td>
Expand Down Expand Up @@ -210,8 +204,7 @@
* </table>
*
* @see <a href=
* "https://eclipse.dev/jetty/documentation/jetty-9/index.html">Jetty SPDY
* and NPN page</a>
* "https://jetty.org/docs/jetty/12/index.html">Jetty 12 documentation</a>
* @author Jerome Louvel
* @author Tal Liron
*/
Expand Down Expand Up @@ -264,18 +257,18 @@ protected abstract ConnectionFactory[] createConnectionFactories(
* @param server The Jetty server.
* @return A Jetty connector.
*/
private Connector createConnector(org.eclipse.jetty.server.Server server) {
protected Connector createConnector(org.eclipse.jetty.server.Server server) {
final HttpConfiguration configuration = createConfiguration();

final ConnectionFactory[] connectionFactories = createConnectionFactories(
configuration);

final int acceptors = getConnectorAcceptors();
final int selectors = getConnectorSelectors();
final Executor executor = getConnectorExecutor();
final Scheduler scheduler = getConnectorScheduler();
final ByteBufferPool byteBufferPool = getConnectorByteBufferPool();

final ConnectionFactory[] connectionFactories = createConnectionFactories(
configuration);

final ServerConnector connector = new ServerConnector(server, executor,
scheduler, byteBufferPool, acceptors, selectors,
connectionFactories);
Expand All @@ -289,7 +282,6 @@ private Connector createConnector(org.eclipse.jetty.server.Server server) {
connector.setAcceptQueueSize(getConnectorAcceptQueueSize());
connector.setIdleTimeout(getConnectorIdleTimeout());
connector.setShutdownIdleTimeout(getShutdownTimeout());
// connector.setSoLingerTime(getConnectorSoLingerTime());

return connector;
}
Expand Down Expand Up @@ -492,19 +484,6 @@ public int getConnectorSelectors() {
.getFirstValue("connector.selectors", "-1"));
}

/**
* Connector TCP/IP SO linger time in milliseconds. Defaults to -1
* (disabled).
* <p>
* See {@link Socket#setSoLinger(boolean, int)}.
*
* @return Connector TCP/IP SO linger time.
*/
public int getConnectorSoLingerTime() {
return Integer.parseInt(getHelpedParameters()
.getFirstValue("connector.soLingerTime", "-1"));
}

/**
* Connector stop timeout in milliseconds. Defaults to 30000.
* <p>
Expand Down Expand Up @@ -791,6 +770,7 @@ protected org.eclipse.jetty.server.Server getWrappedServer() {
* @param wrappedServer The wrapped Jetty server.
*/
protected void setWrappedServer(org.eclipse.jetty.server.Server wrappedServer) {
Objects.requireNonNull(wrappedServer);
this.wrappedServer = wrappedServer;
}

Expand All @@ -799,6 +779,7 @@ public void start() throws Exception {
super.start();
org.eclipse.jetty.server.Server server = getWrappedServer();
ServerConnector connector = (ServerConnector) server.getConnectors()[0];

getLogger().info("Starting the Jetty " + getProtocols()
+ " server on port " + getHelped().getPort());
try {
Expand All @@ -818,7 +799,9 @@ public void start() throws Exception {
public void stop() throws Exception {
getLogger().info("Stopping the Jetty " + getProtocols()
+ " server on port " + getHelped().getPort());
getWrappedServer().stop();
if (this.wrappedServer != null) {
getWrappedServer().stop();
}
super.stop();
}
}
Loading
Loading