Important: This news article covers an old version of Javalin (v0.5.4).
The current version is v6.3.0.
See the documentation page for up-to-date information.
See the documentation page for up-to-date information.
Session attributes
You can now access session attributes more easily.
ctx.sessionAttribute("foo", "bar") // set session-attribute "foo" to "bar"
val foo = ctx.sessionAttribute<String>("foo") // get session-attribute "foo" as string
val sessionAttributeMap = ctx.sessionAttributeMap<Any>() // {foo=bar}
Improved request logging
LogLevel.EXTENSIVE
now includes matching endpoint-handlers
for a request. Given this app config:
app.before(ctx -> {...});
app.get("/matched/:param", ctx -> ctx.result(ctx.matchedPath()));
app.after(ctx -> {...});
A GET request to /matched/p1
gives this log output:
[qtp319977154-18] INFO io.javalin.core.JavalinServlet - JAVALIN EXTENSIVE REQUEST LOG (this clones the response, which is an expensive operation):
Request: GET [/matched/p1]
Matching endpoint-handlers: [BEFORE=*, GET=/matched/:param, AFTER=*]
Headers: {User-Agent=unirest-java/1.3.11, Connection=keep-alive, Host=localhost:7777, Accept-Encoding=gzip}
Cookies: {}
Body:
QueryString: null
QueryParams: {}
FormParams: {=[]}
Response: [200], execution took 1.65 ms
Headers: {Server=Javalin, Date=Sun, 22 Oct 2017 09:56:27 GMT, Content-Type=text/plain;charset=utf-8}
Body: (starts on next line)
/matched/:param
ctx.matchedPath()
Added a function for getting the current matched path (from the Javalin router) from the context.
app.get("/matched/:param", ...); // ctx.matchedPath() = "/matched/:param"