Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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,32 +18,66 @@

/**
* 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
*/
public class HttpServerHelper extends JettyServerHelper {

/**
* Constructor.
*
* @param server The server to help.
*/
public HttpServerHelper(Server server) {
super(server);
getProtocols().add(Protocol.HTTP);
}

/**
* Create and configure the Jetty HTTP connector
*
* @param configuration The HTTP configuration.
*/
@Override
protected ConnectionFactory[] createConnectionFactories(
final HttpConfiguration configuration) {
return new ConnectionFactory[] {
new HttpConnectionFactory(configuration) };
}
/**
* Constructor.
*
* @param server The server to help.
*/
public HttpServerHelper(Server server) {
super(server);
getProtocols().add(Protocol.HTTP);
}

/**
* Create and configure the Jetty HTTP connector
*
* @param configuration The HTTP configuration.
*/
@Override
protected ConnectionFactory[] createConnectionFactories(final HttpConfiguration 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,17 @@
* 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 @@ -53,32 +65,63 @@
*/
public class HttpsServerHelper extends JettyServerHelper {

/**
* Constructor.
*
* @param server The server to help.
*/
public HttpsServerHelper(Server server) {
super(server);
getProtocols().add(Protocol.HTTPS);
}
/**
* Constructor.
*
* @param server The server to help.
*/
public HttpsServerHelper(Server server) {
super(server);
getProtocols().add(Protocol.HTTPS);
}

@Override
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));

@Override
protected ConnectionFactory[] createConnectionFactories(
HttpConfiguration configuration) {
ConnectionFactory[] result;
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) {
getLogger().log(Level.WARNING, "Unable to create the Jetty SSL context factory", e);
throw new RuntimeException(e);
}

try {
SslContextFactory.Server sslContextFactory = new RestletSslContextFactoryServer(
org.restlet.engine.ssl.SslUtils.getSslContextFactory(this));
result = AbstractConnectionFactory.getFactories(sslContextFactory,
new HttpConnectionFactory(configuration));
} catch (Exception e) {
result = null;
getLogger().log(Level.WARNING,
"Unable to create the Jetty SSL context factory", e);
}
return result;
}

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();
}
}
Loading