Reactive HTTP/HTTPS server bootstrap for GuicedEE applications using Vert.x 5.
Provides the Router, HttpServer, and BodyHandler plumbing that higher-level modules (rest, websockets, etc.) build on top of. Configuration is environment-driven; extension is SPI-driven.
Built on Vert.x Web Β· GuicedEE Β· JPMS module com.guicedee.vertx.web Β· Java 25+
<dependency>
<groupId>com.guicedee</groupId>
<artifactId>web</artifactId>
</dependency>Gradle (Kotlin DSL)
implementation("com.guicedee:web:2.0.0-SNAPSHOT")- Auto-start HTTP/HTTPS servers β
VertxWebServerPostStartupruns as anIGuicePostStartuphook and creates servers from environment config - Three SPI extension points β
VertxHttpServerOptionsConfigurator,VertxHttpServerConfigurator,VertxRouterConfigurator - TLS/HTTPS β JKS and PKCS#12 keystores auto-detected by file extension
- Body handling β
BodyHandlerpre-configured with file uploads, form merging, and configurable size limits - Per-verticle sub-routers β
VertxWebVerticleStartupcreates isolated routers for@Verticle-annotated packages - Jackson integration β
DatabindCodecmapper configured viaIJsonRepresentationat startup - Environment-driven β HTTP/HTTPS ports, TLS, body limits all controlled via system properties or environment variables
Bootstrap GuicedEE β the web server starts automatically via the post-startup hook:
IGuiceContext.registerModuleForScanning.add("my.app");
IGuiceContext.instance();
// HTTP server is now listening on port 8080 (default)Add routes by implementing VertxRouterConfigurator:
public class MyRoutes implements VertxRouterConfigurator<MyRoutes> {
@Override
public Router builder(Router router) {
router.get("/health").handler(ctx ->
ctx.response().end("OK"));
return router;
}
@Override
public Integer sortOrder() {
return 500; // higher = later
}
}Register via JPMS:
module my.app {
requires com.guicedee.vertx.web;
provides com.guicedee.vertx.web.spi.VertxRouterConfigurator
with my.app.MyRoutes;
}IGuiceContext.instance()
ββ IGuicePostStartup hooks
ββ VertxWebServerPostStartup (sortOrder = MIN_VALUE + 500)
ββ Build HttpServerOptions (compression, keepalive, header limits)
ββ Apply VertxHttpServerOptionsConfigurator SPIs
ββ Create HTTP server (if HTTP_ENABLED=true)
ββ Create HTTPS server (if HTTPS_ENABLED=true, with TLS keystore)
ββ Apply VertxHttpServerConfigurator SPIs
ββ Create Router + BodyHandler
ββ Apply VertxRouterConfigurator SPIs (sorted, excluding per-verticle)
ββ Mount per-verticle sub-routers from VertxWebRouterRegistry
ββ Configure Jackson ObjectMapper via IJsonRepresentation
ββ Attach router to all servers
ββ server.listen() for each server
All SPIs are discovered via ServiceLoader. Register implementations with JPMS provides...with or META-INF/services.
Customize HttpServerOptions before servers are created β ports, TLS, compression, buffer sizes:
public class MyServerOptions implements VertxHttpServerOptionsConfigurator {
@Override
public HttpServerOptions builder(HttpServerOptions options) {
options.setIdleTimeout(60);
return options;
}
}Configure the HttpServer instance after creation β WebSocket upgrade handlers, connection hooks:
public class MyServerConfig implements VertxHttpServerConfigurator {
@Override
public HttpServer builder(HttpServer server) {
server.connectionHandler(conn ->
log.info("New connection from {}", conn.remoteAddress()));
return server;
}
}Add routes, middleware, and handlers to the Router. Implements IDefaultService so sortOrder() controls execution order:
public class StaticFiles implements VertxRouterConfigurator<StaticFiles> {
@Override
public Router builder(Router router) {
router.route("/static/*").handler(StaticHandler.create("webroot"));
return router;
}
@Override
public Integer sortOrder() {
return 900; // run after REST routes
}
}All configuration is driven by system properties or environment variables:
| Variable | Default | Purpose |
|---|---|---|
HTTP_ENABLED |
true |
Enable HTTP server |
HTTP_PORT |
8080 |
HTTP listen port |
HTTPS_ENABLED |
false |
Enable HTTPS server |
HTTPS_PORT |
443 |
HTTPS listen port |
HTTPS_KEYSTORE |
β | Path to JKS or PKCS#12 keystore |
HTTPS_KEYSTORE_PASSWORD |
β | Keystore password (changeit default for JKS) |
VERTX_MAX_BODY_SIZE |
524288000 (500 MB) |
Maximum request body size in bytes |
Keystore format is auto-detected by file extension:
| Extension | Format |
|---|---|
.jks |
JKS |
.pfx, .p12, .p8 |
PKCS#12 |
# Generate a self-signed JKS keystore for development
keytool -genkey -alias dev -keyalg RSA -keysize 2048 \
-validity 365 -keystore keystore.jks -storepass changeitVertxWebServerPostStartup applies these defaults before any SPI configurator runs:
| Option | Value |
|---|---|
| Compression | enabled, level 9 |
| TCP keep-alive | true |
| Max header size | 65 536 bytes |
| Max chunk size | 65 536 bytes |
| Max form attribute size | 65 536 bytes |
| Max form fields | unlimited (-1) |
| Max initial line length | 65 536 bytes |
A BodyHandler is installed on all routes with:
| Setting | Value |
|---|---|
| Uploads directory | uploads |
| Delete uploaded files on end | true |
| Handle file uploads | true |
| Merge form attributes | true |
| Body limit | VERTX_MAX_BODY_SIZE (default 500 MB) |
When a package is annotated with @Verticle, VertxWebVerticleStartup creates a dedicated Router for that package's VertxRouterConfigurator implementations. These sub-routers are mounted onto the main router automatically.
This means route configurators in @Verticle packages are excluded from the global router and instead run inside their verticle's isolated context.
@Verticle(workerPoolName = "api-pool", workerPoolSize = 8)
package com.example.api;Any VertxRouterConfigurator in com.example.api (or sub-packages) will be applied to a dedicated sub-router mounted by VertxWebVerticleStartup.
com.guicedee.vertx.web
βββ com.guicedee.vertx (Vert.x lifecycle, event bus, verticles)
βββ io.vertx.web (Vert.x Web β Router, BodyHandler, etc.)
βββ io.vertx.core (Vert.x core β HttpServer, HttpServerOptions)
βββ com.guicedee.client (GuicedEE SPI contracts)
Module name: com.guicedee.vertx.web
The module:
- exports
com.guicedee.vertx.web.spi - provides
IGuicePostStartupwithVertxWebServerPostStartup - uses
VertxRouterConfigurator,VertxHttpServerConfigurator,VertxHttpServerOptionsConfigurator
| Class | Role |
|---|---|
VertxWebServerPostStartup |
IGuicePostStartup β builds servers, router, and starts listening |
VertxWebVerticleStartup |
VerticleStartup β creates per-verticle sub-routers |
VertxWebRouterRegistry |
Thread-safe registry for sub-routers contributed by verticles |
VertxRouterConfigurator |
SPI β add routes and handlers to the Router |
VertxHttpServerConfigurator |
SPI β customize HttpServer instances |
VertxHttpServerOptionsConfigurator |
SPI β customize HttpServerOptions before server creation |
Issues and pull requests are welcome β please add tests for new SPI implementations or server configurations.