Skip to content

tipsy/javalin-http2-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A fully working HTTP2 example with Jetty and Javalin

Javalin will run on any embedded Jetty server, and Jetty supports HTTP2 (with a few additional dependencies). This guide explains how to set it all up.

The example includes a generated keystore, but you'll need to generate your own if you intended to use this for anything:

  • Open a command prompt in the same directory as Java keytool and run:
  • keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048

The example uses Conscrypt as the SSL provider, which is recommended by Jetty.

The ALPN API version you need to use is specific to your JDK version. Find your correct version in the Jetty docs

The example has a HTTP1.1 connector on port 8080 and HTTP2 connector on 8443 (with fallback to SSL HTTP 1.1).

To verify that everything is working, open Chrome (or your browser of choice), go to https://localhost:8443, and open the network tab in the devtols. You should see "h2" in the "Protocol" column.

If you go to /static-files-test.html, open the Network tab and set your emulated network to 3G, you'll notice the difference:

Note: WebSockets via HTTP2 are currently not supported by the Jetty version used by Javalin. This functionality will be available in the upcoming Jetty version 10.0.

HTTP1.1

http1

HTTP2

http2

Releases

No releases published

Packages

No packages published

Languages

  • Java 43.3%
  • Kotlin 26.4%
  • HTML 16.3%
  • CSS 9.5%
  • JavaScript 4.5%