Important: This news article covers an old version of Javalin (v2.1.0). The current version is v6.3.0.
See the documentation page for up-to-date information.

Custom SessionHandler

Javalin 2.1.0 will let you supply your own SessionHandler which will be attached to HTTP handler in Jetty.

This will allow multiple Javalin instances to share the same session data, as well as persist sessions after server restart/redeploy.

You can configure the SessionHandler by calling app.sessionHandler(...).

If you just want to persist sessions to the file system, you could use a FileSessionDataStore:

private fun fileSessionHandler() = SessionHandler().apply {
    httpOnly = true
    sessionCache = DefaultSessionCache(this).apply {
        sessionDataStore = FileSessionDataStore().apply {
            val baseDir = File(System.getProperty("java.io.tmpdir"))
            storeDir = File(baseDir, "javalin-session-store").apply { mkdir() }
        }
    }
}

If you want to use MongoDB, Jetty has a built in MongoSessionDataStore:

fun mongoSessionHandler() = SessionHandler().apply {
    httpOnly = true
    sessionCache = DefaultSessionCache(this).apply {
        sessionDataStore = MongoSessionDataStoreFactory().apply {
            connectionString = "mongodb://<user>:<pass>@<adr>:<port>/session_db"
            dbName = "session_db"
            collectionName = "sessions"
        }.getSessionDataStore(sessionHandler)
    }
}

Jetty also has built in functionality for JDBC more. Check the Jetty docs for a full list.

Easier testing in Java

Version 2.0 of Javalin removed the all-args constructor from Context. This caused some problems for some of our Java users, so we’ve added a init method to the ContextUtil which can be used to construct Context objects for testing.

More default responses

Default responses for 409, 410, 502 and 504 have been added.

Exceptional events

You can now throw Exceptions in an EventListener.