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
1
vote
0 answers

Unit Testing Javalin Framework, Mocking Context doesn't work

I'm using Javalin 4 and Mockito 4, and I want to test a simple controller method. I was reading a tutorial in here : https://javalin.io/tutorials/testing here is my controller : package mhndev.controller; import io.javalin.http.Context; public…
Majid Abdolhosseini
  • 2,191
  • 4
  • 31
  • 59
1
vote
1 answer

Javalin 4: How to write properly check in call to Validator.check()?

I am trying to adopt existing code of parameter validation from Javalin 3 to Javalin 4. It uses Javalin's Validator class. Here's the code I've got (rewritten): val messageId = ctx.pathParamAsClass("messageId") .check(check = {…
ivan.ukr
  • 2,853
  • 1
  • 23
  • 41
1
vote
1 answer

How can I properly set up this endpoint?

I'm making an URL shortener with the Javalin framework and have this endpoint set up: app.routes(()->{ path("",()->{ get("/:id", ctx->{ //do stuff ctx.redirect("somewhere.com"); …
1
vote
0 answers

How to I read in Array formParams using Javalin's swagger/OpenAPI user interface?

The current annotation I'm using is as follows: @OpenApi( summary = "Update Camera", tags = ["Camera"], formParams = [ OpenApiFormParam(name = "groupIds", type = List::class, required = true) ] ) Swagger correctly identifies…
mooglin
  • 500
  • 5
  • 17
1
vote
1 answer

How can I solve "org.slf4j.impl.StaticLoggerBinder" error to run my Javalin web app?

I am using IntelliJ IDE where I created a maven project to build a website. I am trying to use Javalin as it is a lightweight framework to use. As per the documentation of Javalin, my pom.xml files is:
1
vote
1 answer

CORS blocking post requests in javascript

im making an api using Javalin and trying to send data to it from javascript, however i get cors errors whenever i try to do so. i can recieve data just fine but not send data. Here is my error: Response to preflight request doesn't pass access…
protein
  • 37
  • 3
1
vote
1 answer

JSON response from string in Javalin

I am trying to create the response in JSON format from a string in Javalin. JSON object must be from a string, not from class. public static void main(String[] args) { Javalin app = Javalin.create().start(9000); String jsonString =…
napster993
  • 165
  • 3
  • 10
1
vote
1 answer

Javalin hot reload of static files

I configured a static folder to be served by Javalin: Javalin.create { it.addStaticFiles("/public") } In Javalin logs I see: [main] INFO io.javalin.Javalin - Static file handler added: {urlPathPrefix: "/", path: "/public", location:…
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
1
vote
1 answer

file.getName() cannot find symbol for method getName() (using Gradle and Javalin)

When i try to run this code: FileUtils.copyInputStreamToFile(file.getContent(), new File("upload/" + file.getName())); I get this error: error: cannot find symbol symbol: method getName() location: variable file of type UploadedFile I have…
ALU
  • 353
  • 2
  • 4
  • 18
1
vote
0 answers

How to create a long lived cassandra CqlSession in a Javalin app

I have an app built with Javalin (a simple HTTP framework in Java) that leverages Cassandra as the backend. According to Datastax docs https://docs.datastax.com/en/developer/java-driver/4.9/manual/core/#quick-start CqlSession is the main entry…
yiksanchan
  • 1,890
  • 1
  • 13
  • 37
1
vote
2 answers

Jetty Async not working as anticipated, experiencing worse performance than sync

Thanks in advance for any pointers or help. Basically I was expecting the async version of this to perform far better than the sync version, but instead the sync version performs equivalent or somehow better. Am I doing something wrong, what…
1
vote
0 answers

how to import/link to a local css stylesheet file in app.vue

im working with Java, Javalin and vue. I cant figure out how to get css working without just having it all in-line within the tags in my app.vue. so i dont want: what i found while…
Walter
  • 11
  • 1
1
vote
1 answer

Can two java applications talk over javelin web sockets?

I'm developing a distributed Java application that implements state machines in a master -> slave/s configuration. I would like the master to be able to communicate with each slave asynchronously. To my novice eye, Javelin Websockets looks like a…
Kaliklipper
  • 355
  • 5
  • 19
1
vote
1 answer

Javalin, cannot get request body , except from HttpServlet directly

i cannot get request body from Javalin's context object like context.formParam,context.body(),context.bodyAsClass() i've tried like this, and i can get request body, i use HttpServletRequest directly to get request body public void…
Arief Kahfi
  • 25
  • 1
  • 5
1
vote
1 answer

Dao Services as Singletons?

I'm developing a web app using Javalin. I have multiple controller classes that handle my routing for me. Each controller is supposed to be associated with a single POJO/DB Table type. So for instance I have an Employee controller that routes and…
TheFunk
  • 981
  • 11
  • 39