Custom jetty handlers

Javalin 1.2.0 introduces the possibility of adding custom jetty handlers, such as StatisticsHandler and RequestLogHandler.
You can configure your embedded jetty-server with a handler-chain (example), and Javalin will attach it’s own handlers to the end of this chain.

  • Kotlin
  • Java
val statisticsHandler = StatisticsHandler()

Javalin.create().apply {
    embeddedServer(EmbeddedJettyFactory({
        Server(queuedThreadPool).apply {
            handler = statisticsHandler
        }
    }))
}.start();
StatisticsHandler statisticsHandler = new StatisticsHandler();

Javalin.create()
    .embeddedServer(new EmbeddedJettyFactory(() -> {
        Server server = new Server();
        server.setHandler(statisticsHandler);
        return server;
    }))
    .start();

Doing this will allow you to integrate Javalin with for example prometheus easily, by exposing statistics collected by the StatisticsHandler.
There’s even a tutorial to show you how that’s done: /tutorials/prometheus-example

EventManager cleanup

There was a bug in the Event data class, where properties were declared as var instead of val. The Javalin val was nullable for no apparent reason, so that’s been fixed too.

Kotlin 1.2.0

Kotlin has been bumped to 1.2.0