From 951b885421dc574e6b0a38e5323f09d90b23e9b3 Mon Sep 17 00:00:00 2001 From: Mechite Date: Tue, 2 Dec 2025 15:58:31 +0000 Subject: [PATCH] RFC: Demonstration of `http2-jetty`, `http3-jetty` & `http2-robaho` Signed-off-by: Mahied Maruf --- avaje-jex-http2-jetty/pom.xml | 51 ++++++++++++++++++ .../jex/http2/jetty/JettyHttp2JexPlugin.java | 40 ++++++++++++++ .../src/main/java/module-info.java | 8 +++ avaje-jex-http2-robaho/pom.xml | 46 ++++++++++++++++ .../http2/robaho/RobahoHttp2JexPlugin.java | 27 ++++++++++ .../src/main/java/module-info.java | 5 ++ avaje-jex-http3-jetty/pom.xml | 51 ++++++++++++++++++ .../jex/http3/jetty/JettyHttp3JexPlugin.java | 54 +++++++++++++++++++ .../src/main/java/module-info.java | 8 +++ pom.xml | 3 ++ 10 files changed, 293 insertions(+) create mode 100644 avaje-jex-http2-jetty/pom.xml create mode 100644 avaje-jex-http2-jetty/src/main/java/io/avaje/jex/http2/jetty/JettyHttp2JexPlugin.java create mode 100644 avaje-jex-http2-jetty/src/main/java/module-info.java create mode 100644 avaje-jex-http2-robaho/pom.xml create mode 100644 avaje-jex-http2-robaho/src/main/java/io/avaje/jex/http2/robaho/RobahoHttp2JexPlugin.java create mode 100644 avaje-jex-http2-robaho/src/main/java/module-info.java create mode 100644 avaje-jex-http3-jetty/pom.xml create mode 100644 avaje-jex-http3-jetty/src/main/java/io/avaje/jex/http3/jetty/JettyHttp3JexPlugin.java create mode 100644 avaje-jex-http3-jetty/src/main/java/module-info.java diff --git a/avaje-jex-http2-jetty/pom.xml b/avaje-jex-http2-jetty/pom.xml new file mode 100644 index 00000000..ca1b9731 --- /dev/null +++ b/avaje-jex-http2-jetty/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + + io.avaje + avaje-jex-parent + 3.4-RC2 + + avaje-jex-http2-jetty + avaje-jex-http2-jetty + 0.1 + + 21 + 11.0.26 + + + + org.eclipse.jetty + jetty-http-spi + ${jetty.version} + + + org.eclipse.jetty.http2 + http2-server + ${jetty.version} + + + + io.avaje + avaje-jex-ssl + + + io.avaje + avaje-jex-test + test + + + + io.avaje + avaje-jsonb + test + + + + io.avaje + avaje-jsonb-generator + test + + + diff --git a/avaje-jex-http2-jetty/src/main/java/io/avaje/jex/http2/jetty/JettyHttp2JexPlugin.java b/avaje-jex-http2-jetty/src/main/java/io/avaje/jex/http2/jetty/JettyHttp2JexPlugin.java new file mode 100644 index 00000000..8eec2435 --- /dev/null +++ b/avaje-jex-http2-jetty/src/main/java/io/avaje/jex/http2/jetty/JettyHttp2JexPlugin.java @@ -0,0 +1,40 @@ +package io.avaje.jex.http2.jetty; + +import io.avaje.jex.Jex; +import io.avaje.jex.spi.JexPlugin; +import org.eclipse.jetty.http.spi.JettyHttpServerProvider; +import org.eclipse.jetty.http2.api.server.ServerSessionListener; +import org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +/** A plugin that configures Jex to enable HTTP/2 using Jetty. */ +public final class JettyHttp2JexPlugin extends ServerSessionListener.Adapter implements JexPlugin { + + private JettyHttp2JexPlugin() {} + + /** + * Creates a new instance of the {@code JettyHttp2JexPlugin}. + * + * @return The new plugin instance. + */ + public static JettyHttp2JexPlugin create() { + return new JettyHttp2JexPlugin(); + } + + @Override + public void apply(Jex jex) { + Server server = new Server(); + SslContextFactory.Server ssl = new SslContextFactory.Server(); + + RawHTTP2ServerConnectionFactory http2 = new RawHTTP2ServerConnectionFactory(this); + http2.setConnectProtocolEnabled(true); + + server.addConnector(new ServerConnector(server, ssl, http2)); + JettyHttpServerProvider.setServer(server); + + jex.config() + .serverProvider(new JettyHttpServerProvider()); + } +} diff --git a/avaje-jex-http2-jetty/src/main/java/module-info.java b/avaje-jex-http2-jetty/src/main/java/module-info.java new file mode 100644 index 00000000..e29ad81b --- /dev/null +++ b/avaje-jex-http2-jetty/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module io.avaje.jex.http2.jetty { + requires transitive io.avaje.jex.ssl; + requires transitive org.eclipse.jetty.server; + requires transitive org.eclipse.jetty.http.spi; + requires transitive org.eclipse.jetty.http2.common; + requires transitive org.eclipse.jetty.http2.server; + requires java.base; +} diff --git a/avaje-jex-http2-robaho/pom.xml b/avaje-jex-http2-robaho/pom.xml new file mode 100644 index 00000000..8bf082bb --- /dev/null +++ b/avaje-jex-http2-robaho/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + + io.avaje + avaje-jex-parent + 3.4-RC2 + + avaje-jex-http2-robaho + avaje-jex-http2-robaho + 0.1 + + 21 + 1.0.29 + + + + io.github.robaho + httpserver + ${robaho.version} + + + + io.avaje + avaje-jex-ssl + + + io.avaje + avaje-jex-test + test + + + + io.avaje + avaje-jsonb + test + + + + io.avaje + avaje-jsonb-generator + test + + + diff --git a/avaje-jex-http2-robaho/src/main/java/io/avaje/jex/http2/robaho/RobahoHttp2JexPlugin.java b/avaje-jex-http2-robaho/src/main/java/io/avaje/jex/http2/robaho/RobahoHttp2JexPlugin.java new file mode 100644 index 00000000..4a442435 --- /dev/null +++ b/avaje-jex-http2-robaho/src/main/java/io/avaje/jex/http2/robaho/RobahoHttp2JexPlugin.java @@ -0,0 +1,27 @@ +package io.avaje.jex.http2.robaho; + +import io.avaje.jex.Jex; +import io.avaje.jex.spi.JexPlugin; +import robaho.net.httpserver.DefaultHttpServerProvider; + +/** A plugin that configures Jex to enable HTTP/2 using Jetty. */ +public final class RobahoHttp2JexPlugin implements JexPlugin { + + private RobahoHttp2JexPlugin() {} + + /** + * Creates a new instance of the {@code RobahoHttp2JexPlugin}. + * + * @return The new plugin instance. + */ + public static RobahoHttp2JexPlugin create() { + return new RobahoHttp2JexPlugin(); + } + + @Override + public void apply(Jex jex) { + System.setProperty("robaho.net.httpserver.http2OverSSL", "true"); + jex.config() + .serverProvider(new DefaultHttpServerProvider()); + } +} diff --git a/avaje-jex-http2-robaho/src/main/java/module-info.java b/avaje-jex-http2-robaho/src/main/java/module-info.java new file mode 100644 index 00000000..f4ff945c --- /dev/null +++ b/avaje-jex-http2-robaho/src/main/java/module-info.java @@ -0,0 +1,5 @@ +module io.avaje.jex.http2.robaho { + requires transitive io.avaje.jex.ssl; + requires java.base; + requires robaho.httpserver; +} diff --git a/avaje-jex-http3-jetty/pom.xml b/avaje-jex-http3-jetty/pom.xml new file mode 100644 index 00000000..96313174 --- /dev/null +++ b/avaje-jex-http3-jetty/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + + io.avaje + avaje-jex-parent + 3.4-RC2 + + avaje-jex-http3-jetty + avaje-jex-http3-jetty + 0.1 + + 21 + 11.0.26 + + + + org.eclipse.jetty + jetty-http-spi + ${jetty.version} + + + org.eclipse.jetty.http3 + http3-server + ${jetty.version} + + + + io.avaje + avaje-jex-ssl + + + io.avaje + avaje-jex-test + test + + + + io.avaje + avaje-jsonb + test + + + + io.avaje + avaje-jsonb-generator + test + + + diff --git a/avaje-jex-http3-jetty/src/main/java/io/avaje/jex/http3/jetty/JettyHttp3JexPlugin.java b/avaje-jex-http3-jetty/src/main/java/io/avaje/jex/http3/jetty/JettyHttp3JexPlugin.java new file mode 100644 index 00000000..ec3861e2 --- /dev/null +++ b/avaje-jex-http3-jetty/src/main/java/io/avaje/jex/http3/jetty/JettyHttp3JexPlugin.java @@ -0,0 +1,54 @@ +package io.avaje.jex.http3.jetty; + +import io.avaje.applog.AppLog; +import io.avaje.jex.Jex; +import io.avaje.jex.spi.JexPlugin; +import org.eclipse.jetty.http.spi.JettyHttpServerProvider; +import org.eclipse.jetty.http3.api.Session; +import org.eclipse.jetty.http3.server.RawHTTP3ServerConnectionFactory; +import org.eclipse.jetty.quic.server.QuicServerConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +import java.net.DatagramSocket; +import java.net.SocketAddress; + +import static java.lang.System.Logger.Level.*; + +/** A plugin that configures Jex to enable HTTP/3 using Jetty. */ +public final class JettyHttp3JexPlugin implements JexPlugin, Session.Server.Listener { + + private static final System.Logger LOG = AppLog.getLogger(JettyHttp3JexPlugin.class); + + private JettyHttp3JexPlugin() {} + + /** + * Creates a new instance of the {@code JettyHttp3JexPlugin}. + * + * @return The new plugin instance. + */ + public static JettyHttp3JexPlugin create() { + return new JettyHttp3JexPlugin(); + } + + @Override + public void apply(Jex jex) { + Server server = new Server(); + SslContextFactory.Server ssl = new SslContextFactory.Server(); + + RawHTTP3ServerConnectionFactory http3 = new RawHTTP3ServerConnectionFactory(this); + http3.getHTTP3Configuration().setStreamIdleTimeout(15000); + + server.addConnector(new QuicServerConnector(server, ssl, http3)); + JettyHttpServerProvider.setServer(server); + + jex.config() + .serverProvider(new JettyHttpServerProvider()); + } + + @Override + public void onAccept(Session session) { + SocketAddress address = session.getRemoteSocketAddress(); + LOG.log(TRACE, "Connection from {0}", address); + } +} diff --git a/avaje-jex-http3-jetty/src/main/java/module-info.java b/avaje-jex-http3-jetty/src/main/java/module-info.java new file mode 100644 index 00000000..6d77e6c7 --- /dev/null +++ b/avaje-jex-http3-jetty/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module io.avaje.jex.http3.jetty { + requires transitive io.avaje.jex.ssl; + requires transitive org.eclipse.jetty.server; + requires transitive org.eclipse.jetty.http3.common; + requires transitive org.eclipse.jetty.http3.server; + requires transitive org.eclipse.jetty.http.spi; + requires java.base; +} diff --git a/pom.xml b/pom.xml index b32f6a8e..5f387010 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,10 @@ avaje-jex-static-content avaje-jex-test avaje-jex-ssl + avaje-jex-http2-jetty + avaje-jex-http2-robaho avaje-jex-http3-flupke + avaje-jex-http3-jetty