DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications
  • Connection Pooling With BoneCP, DBCP, and C3PO [Video Tutorials]
  • Building a REST Service That Collects HTML Form Data Using Netbeans, Jersey, Apache Tomcat, and Java
  • Troubleshooting HTTP 502 Bad Gateway in AWS EBS

Trending

  • Setting up Request Rate Limiting With NGINX Ingress
  • Running Unit Tests in GitHub Actions
  • Understanding Git
  • Using Open Source for Data Integration and Automated Synchronizations
  1. DZone
  2. Coding
  3. Languages
  4. Configure Tomcat 9 for HTTP/2

Configure Tomcat 9 for HTTP/2

HTTP/2 removes bottlenecks from client/server communication. With the specification now official, vendor support is become more mature.

Alex Theedom user avatar by
Alex Theedom
·
Apr. 12, 16 · Opinion
Like (16)
Save
Tweet
Share
33.91K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

One of the most important developments in JavaEE 8 will be support for HTTP/2 (now the official RFC 7540). The Java Community Process JSR-369 has been in development for almost 2 years now, and the specification leaders Ed Burns and Shing Wai Chan have done a great job in advancing its progress.

At the time of writing, three server vendors currently support Servlet 4.0: Apache Tomcat 9.0.0.M4, Jetty 9 and WildFly 10.0.0.Final. Let's have a look at how to configure Tomcat 9 to support it.

The Goal of HTTP2

The goal of HTTP/2 is to increase the perceived performance of the web browsing experience.

Why Do We Need HTTP2

A web page has many resources that need to be loaded. In HTTP 1.0, requests for all resources are sent all at once and the server responds to each request. If one of the resources takes extra time, then all other resources are blocked because of head-of-line blocking.

Upgrade From HTTP1.1

Most website are using HTTP1.1. To talk in HTTP/2 you can use the upgrade header (101 switching protocols) to send h2c to the server. The server will upgrade to h2c (c means clear text). Note that at the moment there is no h2c in Firefox or Chrome.

What if it is secure? We can use ALPN, which is a TLS extension. In the handshake you send an extension and the server will determine that the communication is h2.

Download Tomcat 9

Download the appropriate binary distribution of Tomcat 9 for your system and install by unpacking the bundle. Ensure that you have Java 8 SE installed.

Generate Certificate With OpenSSL

As we have discussed above, it is required to configure TLS to use HTTP/2 because of the lack of clear text support for Firefox and Chrome. For TLS we need a certificate. If you don’t already have a certificate you can generate one with OpenSSL.

Configure server.xml

One of the changes in Tomcat 9 is that TLS virtual hosting and multiple certificates are supported for a single connector, with each virtual host able to support multiple certificates.

Open the conf/server.xml file and make the following configuration changes.

<Connector port="8443"
protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"/>
<SSLHostConfig honorCipherOrder="false">
<Certificate certificateKeyFile="conf/ca.key"
certificateFile="conf/ca.crt"/>
</SSLHostConfig>
</Connector>

Restart Tomcat.

Conclusion

To test the configuration visit https://localhost:8443. If you see the Tomcat home page, then you have successfully configured TLS for Tomcat 9. You are now ready to develop using Servlet 4.0.

Watch this space for more tutorials about Servlet 4.0.

If you are interested in the HTTP/2 specification you might be interested in my HTTP/2 specification tutorial.

Apache Tomcat

Published at DZone with permission of Alex Theedom, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications
  • Connection Pooling With BoneCP, DBCP, and C3PO [Video Tutorials]
  • Building a REST Service That Collects HTML Form Data Using Netbeans, Jersey, Apache Tomcat, and Java
  • Troubleshooting HTTP 502 Bad Gateway in AWS EBS

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: