Questions tagged [javalin]

Use this tag for programming questions about the Javalin web framework for Java and Kotlin.

Overview

Javalin is a lightweight web framework built on the Jetty web server.

The framework can be integrated into Java and Kotlin projects.

Javalin supports several template engines including Thymeleaf and Velocity. It has built-in support for WebSockets, HTTP2, static file serving, exception mapping, server-sent events, asynchronous mode, as well as a variety of common tasks such as validation, access control, logging, and server configuration.

An OpenAPI (Swagger) plugin is also provided, as well as a GraphQL plugin.


Resources


Hello World

Java:

import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        Javalin app = Javalin.create().start(7070);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

Kotlin:

import io.javalin.Javalin

fun main() {
    val app = Javalin.create().start(7070)
    app.get("/") { ctx -> ctx.result("Hello World") }
}
86 questions
2
votes
1 answer

Replace Jackson with kotlinx.serialization in Javalin framework

I'm trying to replace the default Javalin JSON serializer Jackson by Kotlinx.serialization. The documentation show how to do it with GSON serializer. Unfortunately kotlinx serializer has a different function signature and I can't figure out how to…
Freezystem
  • 4,494
  • 1
  • 32
  • 35
2
votes
1 answer

Mockito calling real method on mocked Javalin context

I have a real strange behavior going on. It seems that Mockito is calling the real method on a mocked class, resulting in a NullPointerException. I am mocking the Context object present in the Javalin http framework for Java. This is the minimal…
feggak
  • 31
  • 4
2
votes
2 answers

JetBrains Exposed (DSL Api): Issue when using .regexp() where condition

I am building a small API using Javalin & Exposed ORM. I'm trying to use the regex where condition but an exception is thrown because the SQL query performed due to my code seems to be incomplete (the pattern is missing). fun…
2
votes
1 answer

How to give log path in javalin

public class App { //private static final Logger logger = LoggerFactory.getLogger(App.class); private static Logger logger = LoggerFactory.getLogger(App.class.getName()); private static ObjectMapper mapper = new ObjectMapper(); …
2
votes
1 answer

How to validate list body in Javalin

My DELETE request accepts a list of Items that should be deleted. I want to validate that the request body is a valid list of Item objects. The example given in the Javalin docs doesn't mention lists. In order to get the code to compile, I had to do…
Jolta
  • 2,620
  • 1
  • 29
  • 42
2
votes
1 answer

Javalin sessionAttribute() isn't Persisting Between Requests

I'm setting up Javalin as a microservice, providing API endpoints for my React app. Locally, Javalin is running on port 7070 and React is running on 3000 (via the built-in server with create-react-app). I'm attempting to wire up the login/logout…
bluedevil2k
  • 9,366
  • 8
  • 43
  • 57
2
votes
1 answer

InputStream does not read some files from a JAR

I've built a JAR file for my Javalin application, and the code runs just fine. However, reading some resource files from the JAR fails with inputStream.available() == 0, but it works just right for some other files. The following files should be…
Alexander Leithner
  • 3,169
  • 22
  • 33
2
votes
1 answer

Javalin tutorial yielding "Unresolved reference: AtomicInteger"

Title says it. Following the Javalin tutorial as part of learning kotlin and getting the Unresolved Reference on mvn package. I imagine I need to pull in a dependency, but the example doesn't show it and Google is failing me. My pom.xml is…
Paul
  • 35,689
  • 11
  • 93
  • 122
1
vote
1 answer

How to translate a simple web framework in Javalin into Clojure?

There is a simple web framework in Javalin import io.javalin.Javalin; public class HelloWorld { public static void main(String[] args) { var app = Javalin.create(/*config*/) .get("/", ctx -> ctx.result("Hello World")) …
madeinQuant
  • 1,721
  • 1
  • 18
  • 29
1
vote
1 answer

Using static methods in controller Javalin

after seeing few projects on GitHub I've been thinking, should I use static methods in my controller? I use Javalin and I created NoteController class to service all requests. What's the difference between my idea and the other one, to use static…
Samson
  • 11
  • 1
1
vote
1 answer

How to ignore trailing slashes in Javalin 5?

There have been a lot of changes to the configuration in Javalin 5. One thing that used to work in previous versions is to "ignore trailing slashes" like this: var javalin = Javalin.create(cfg -> { cfg.ignoreTrailingSlashes =…
Johan
  • 37,479
  • 32
  • 149
  • 237
1
vote
1 answer

How to disable Jetty logging inside Javalin?

I'm working on a Minecraft plugin and want to use Javalin. I can easily disable the Javali-logging with JavalinLogger.enabled = false but I can't disable the jetty log. I always get the following output when starting the Javalin server: [22:24:32…
Christian
  • 11
  • 3
1
vote
1 answer

Javalin hangs when asked to give 1XX HTTP status

I have a Javalin server, the relevant code called by the endpoint looks like this: ... if(!someFuture.isDone()){ ctx.status(102); return; } Javalin hangs and does not return anything* when the HTTP status is set to anything in the 1XX…
Dan
  • 12,157
  • 12
  • 50
  • 84
1
vote
1 answer

Javalin with JPMS and ServiceLoader results in NoClassDefFoundError: kotlin/NoWhenBranchMatchedException

Running Javalin with JPMS and ServiceLoader leads to a NoClassDefFoundError: kotlin/NoWhenBranchMatchedException. The same code following two other approaches works fine, though (see at the end of this post for details): No JPMS and ServiceLoader:…
baumgarb
  • 1,955
  • 3
  • 19
  • 30
1
vote
2 answers

How to configure the default Jackson JSON Mapper on Javalin

So far, i found how to replace Javalin json mapper: https://javalin.io/documentation#configuring-the-json-mapper But i don't want to replace it, just want to add a few jackson modules, like this…
Sombriks
  • 3,370
  • 4
  • 34
  • 54