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
1 answer

Jetty/javalin getting HttpSession from websocket returns null always

Hello guys so am using javalin(uses jetty) and trying to get HttpSession but it returns null always! is there any better way i can get HttpSession in websockets without context? app.ws("/console",webSocketHandler -> { …
0
votes
0 answers

Register custom annotation in Java

I’m working on a project using only the Javalin framework and google Guice inject. I’m having a hard time recording a custom annotation in the project to be used by any class I created a custom annotation to make a regex in a string of a…
Ger
  • 583
  • 2
  • 13
  • 35
0
votes
0 answers

Creating a register and log in endpoints with Java and Javalin

I'm trying to create endpoints to register and log in with java and javalin. and it has some test cases that I have to pass. So far I've passed 6 out of 7, but I can't get to pass the last test case of the login. Here is what I have for both…
0
votes
1 answer

How to enable proxy protocol in javalin?

I bought a load balancer at hetzner and for my backend (written in Java, Web-Server is Javalin) I want to use the Proxy Protocol, that the IP-Adresses will be redirected to my web-services. Hetzner Load Balancer enable Proxy Protocol Hetzner says,…
Lvkas_
  • 3
  • 1
0
votes
0 answers

Manipulating response with AsyncProxyServlet

Given the Proxy.java below: import io.javalin.Javalin; import org.eclipse.jetty.proxy.AsyncProxyServlet; import org.eclipse.jetty.servlet.ServletHolder; public class Proxy { public static void main(String[] args) { Javalin app =…
0
votes
1 answer

Picocli with long running Javalin Thread

I want to build a simple Javalin API and configure the HTTP port with a command line arg with Picocli. It looks a bit like this: public class Main implements Runnable { @CommandLine.Option(names = {"-p", "--port"}) int httpPort = 9080; …
Thomas
  • 793
  • 1
  • 8
  • 16
0
votes
0 answers

I was creating endpoints in javalin and I tried to run but it gave me the message that " connection refused"

app.get("/firstname/{Kevin}", ctx -> { ctx.result("Kevin"); }); return app; } } i dont get my mistake app.get("/firstname/{Kevin}", ctx -> { ctx.result("Kevin"); }); return app; } } i did this
0
votes
1 answer

What is (Cannot resolve method 'result(java.lang.String)' ) error in java?

hi i'm trying to print a simple "hello world" with Javalin in my local host but i keep getting this error "Cannot resolve method 'result(java.lang.String)'"and i don't know how to fix it and this is my code with i copied it from Javalin doc…
0
votes
0 answers

What is the best way to write a response from a HttpURLConnection inputStream in Javalin?

i'm writing a simple API that read a file from a remote server and return it to the caller using Javalin. This is my simple code: class FileReader{ public []byte getFileBytes(String fileURL){ ... HttpURLConnection con = null; …
Ve9
  • 345
  • 3
  • 15
0
votes
0 answers

How to serve static file with Javalin

Building a web app with Javalin. How do I display a PDF from my staticfiles folder in the app.post function? I can't use .getResourceAsStream because it has images, and the function couldn't parse it. I can serve html files using ctx.html but can't…
vvv
  • 1
0
votes
2 answers

Removing .html from end of url in javalin

I'm using Javalin to serve my static web pages, which I've never done before. I know it's possible in Nginx to remove the .html from the end of your url but still route to the correct page, for example mysite.com/login would replace…
jchernin4
  • 11
  • 2
  • 7
0
votes
1 answer

How to enable "dev logging" 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 enable "dev logging": var javalin = Javalin.create(cfg -> { cfg.enableDevLogging(); …
Johan
  • 37,479
  • 32
  • 149
  • 237
0
votes
0 answers

Custom Http Response Exception Mapper in Javalin Server

How can we implement a custom exception mapper in the Javalin frame work? The main issue I am having with the default one is that it includes a type field in its json responses that identifies it as a javalin exception. I don't wish to expose this…
Peter McKinney
  • 463
  • 3
  • 13
0
votes
1 answer

JWT token with Auth0 Java using Javalin

I'm using Javalin and want to build authentication flow, with Auth0 I can make token and send it with header in request, But how I can get my User data from that token? How I can check which user is authenticated at that moment
0
votes
0 answers

Javalin - HTTP handler - redirect and download file from byte array

I am trying to return a byte array result from a generated excel file on the back-end. I want to send it to the React front-end to automatically download after the redirect. I have been trying to do something like this, but with no success, because…
Emi
  • 1,165
  • 4
  • 15
  • 26