3

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?

1
  • one solution would be to front tomcat with http2 enabled nginx. nginx will provide the http2 benefits (most of them) and your code can reside in tomcat with 3.1. Asynchronous API is more about how to handle threads, not much to do with http interaction. Commented Jun 5, 2018 at 17:29

1 Answer 1

6

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.
4
  • I looked over the servlet 4.0 api and didn't find anything related to me sending push response data (not resources like css files). Is this supported or are we just pre-emptively pushing resources to improve performance?
    – PentaKon
    Commented Jun 11, 2018 at 8:20
  • @Konstantine Correct: we are "just pre-emptively pushing resources to improve performance". In your servlet you specify the resources (e.g. images etc,) to be immediately sent to the client before completing the processing of the request. You can also do a similar thing with JSF 2.3 with no developer effort at all. But AFAIK server push does not support pushing data back to the client. (I suppose you could put the data in a resource file and push that, but that is against the intention of server push.)
    – skomisa
    Commented Jun 11, 2018 at 17:16
  • Ok. I thought that HTTP2 would essentially allow SSE and replace WebSockets. My goal is to initiate a server operations with one http request and then receive multiple responses for that operation. Is Websockets the only way to go or will HTTP2 support this functionality (at least in the future)?
    – PentaKon
    Commented Jun 12, 2018 at 9:10
  • @PentaKon HTTP2 is about sending your HTML and pushing the required JS. CSS and images you think will follow, not about sending arbitrary events at any time. Websocket is still the way to go for that (or polling but that's a different matter)
    – pieroxy
    Commented Aug 20, 2023 at 13:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.