PentaKon
PentaKon

Reputation: 4636

How can I support HTTP2 with Tomcat 8.5 and Java SE 8

I'm doing some research on HTTP2 and the possibility of us using it in our application. At the moment we are developing in Java 8 and use Tomcat 8.5.24 (this means we use Servlet 3.1). I have scoured the web but could not find any resources as to how to leverage the HTTP2 capabilities.

The only examples I could find were using Servlet 4.0 (which from what I saw is only supported by Tomcat 9) and the only thing that was showcased was the use of a PushBuilder to push css and js files when a client requests and html page.

Will I be able to use the Asynchronous api provided by Servlet 3.1 over HTTP2? Is HTTP2 supported by Servlet 3.1? If not, what's the point of Tomcat 8.5 supporting HTTP2? Only for pushing web resources?

Upvotes: 3

Views: 6024

Answers (1)

skomisa
skomisa

Reputation: 17343

First, some basic points:

  • You must use Servlet 4.0 to implement server push. The API does not exist in earlier versions such as 3.1.
  • The Servlet Specification is now under the umbrella of Java EE ("Jakarata EE"), and the Servlet 4.0 specification is part of Java EE 8.
  • Therefore, to implement server push in a servlet you must use EE 8. You can't use EE 7.
  • However, you can use JDK 8 or greater with EE 8. There is no need to go to JDK 9.
  • Tomcat provides a useful table for correlating any Tomcat version with supported Java and servlet versions.
  • The following servers support Java EE 8: GlassFish 5.x, Payara 5.x and Tomcat 9.x. You can't use Tomcat 8.5.

To address your specific questions:

Will I be able to use the Asynchronous api provided by Servlet 3.1 over HTTP2?

Yes. It's still there is the 4.0 specification.

Is HTTP2 supported by Servlet 3.1?

No. Appendix A1 of the Servlet 4.0 specification explicitly states that one change from 3.1 is the "Requirement to support HTTP/2".

If not, what's the point of Tomcat 8.5 supporting HTTP2?

Because there are features in HTTP/2 that exist independently of servlets. See the Tomcat 8.5 documentation on its HTTP/2 support. For example, while you could not implement HTTP/2 server push, you could still implement HTTP/2 header compression using Tomcat 8.5.

Only for pushing web resources?

No. HTTP/2 is all about performance, and server push is just one feature:

  • is binary, instead of textual
  • is fully multiplexed, instead of ordered and blocking
  • can therefore use one connection for parallelism
  • uses header compression to reduce overhead
  • allows servers to “push” responses proactively into client caches

Finally, there are also a few related matters worth noting:

  • While HTTP/2 itself does not require the use of https, as a practical matter it is required since "currently no browser supports HTTP/2 unencrypted".
  • All popular browsers already fully support HTTP/2.
  • As far as I know there is nothing that prevents the use of any of the major IDEs (Intellij IDEA, Eclipse, STS, NetBeans) for developing and testing HTTP/2 functionality.

Upvotes: 6

Related Questions