Tomcat 9 Http2



HTTP/1.x broken with Tomcat 9, Java 11 and Http11NioProtocol. I'm trying to get the following configuration working: - Tomcat 9.0.17 (also tested with 9.0.16) - AdoptOpenJDK Java 11.0.2 on Linux. So I'm having difficultly getting HTTP/2 working with the newer version of the AWS Application Load Balancer, and Tomcat 9. I added the to my connector on tomcat (the standard unencrypted 8080 connector). When I hit my site through the LB, I see the h2 protocol being used.

Tomcat 9 Http2

From version 9 onwards, Tomcat has support for HTTP/2 but not the default. Wanting to work with HTTP/2 with Tomcat, we must have some adjustments in its configuration. In this tutorial, I will guide you.

First of all, you have to make sure that you are using Java 9 or above.

Because of only Java 9 and above supporting for Application-Layer Protocol Negotiation (ALPN). ALPN is a Transport Layer Security extension, which allows Tomcat to choose the version of the HTTP protocol that it will work with.

Tomcat 9 Http2 Without Ssl

Currently, I have installed Java 9:

The second step we need to do is modify the server.xml file located in the conf directory of Tomcat.

Tomcat

The definition of HTTP/2 is not required to use a secure connection, but browsers implement it with a secure connection, so we will configure HTTP/2 support for Tomcat with HTTPS protocol.

Tomcat 9 Enable Http2

Tomcat

In the previous tutorial, I have shown you how to configure HTTPS for Tomcat, the content of the Tomcat Connector for HTTPS is as follows:

2
4
6
<Connector port='8443'protocol='HTTP/1.1'SSLEnabled='true'
clientAuth='false'sslProtocol='TLS'
keystoreFile='/Users/Khanh/Documents/tomcat_https'
<UpgradeProtocol className='org.apache.coyote.http2.Http2Protocol'/>

That’s all we need.

Tomcat 9 http2 without ssl

To check the results, just visit https://localhost:8443/. If you are using Chrome, right click on the site, select Inspect, then select the Network tab. Refresh the site, you will see the results as follows:

Note the localhost line in the picture, you will see the protocol is h2, which means HTTP/2.