Skip to content

GuicedEE/GuicedVertxWeb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GuicedEE Vert.x Web

Build Maven Central Maven Snapshot License

Java 25+ Guice 7 Vert.X 5 Maven 4

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+

πŸ“¦ Installation

<dependency>
  <groupId>com.guicedee</groupId>
  <artifactId>web</artifactId>
</dependency>
Gradle (Kotlin DSL)
implementation("com.guicedee:web:2.0.0-SNAPSHOT")

✨ Features

  • Auto-start HTTP/HTTPS servers β€” VertxWebServerPostStartup runs as an IGuicePostStartup hook 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 β€” BodyHandler pre-configured with file uploads, form merging, and configurable size limits
  • Per-verticle sub-routers β€” VertxWebVerticleStartup creates isolated routers for @Verticle-annotated packages
  • Jackson integration β€” DatabindCodec mapper configured via IJsonRepresentation at startup
  • Environment-driven β€” HTTP/HTTPS ports, TLS, body limits all controlled via system properties or environment variables

πŸš€ Quick Start

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;
}

πŸ“ Startup Flow

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

πŸ”Œ SPI Extension Points

All SPIs are discovered via ServiceLoader. Register implementations with JPMS provides...with or META-INF/services.

VertxHttpServerOptionsConfigurator

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;
    }
}

VertxHttpServerConfigurator

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;
    }
}

VertxRouterConfigurator

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
    }
}

βš™οΈ Configuration

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

HTTPS / TLS

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 changeit

Default server options

VertxWebServerPostStartup 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

Body handler defaults

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)

πŸ”€ Per-Verticle Sub-Routers

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.

πŸ—ΊοΈ Module Graph

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)

🧩 JPMS

Module name: com.guicedee.vertx.web

The module:

  • exports com.guicedee.vertx.web.spi
  • provides IGuicePostStartup with VertxWebServerPostStartup
  • uses VertxRouterConfigurator, VertxHttpServerConfigurator, VertxHttpServerOptionsConfigurator

πŸ—οΈ Key Classes

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

🀝 Contributing

Issues and pull requests are welcome β€” please add tests for new SPI implementations or server configurations.

πŸ“„ License

Apache 2.0

About

A Vertx Web Configuration module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages