HTTP/2 and What it Means for the Jakarta EE Ecosystem

Cd94eaef7b2860c41cb0612720137e2b?s=47 Reza Rahman
October 24, 2017

HTTP/2 and What it Means for the Jakarta EE Ecosystem

HTTP is very easily the most important standard in server-side Java. The much awaited HTTP/2 standard is now complete, was fifteen years in the making and promises to radically speed up the entire web through a series of fundamental protocol optimizations.

In this session we will take a detailed look at the changes in HTTP/2 and discuss how it may change the Jakarta EE ecosystem including the foundational Jakarta Servlet 4 specification included in Jakarta EE 8.

Cd94eaef7b2860c41cb0612720137e2b?s=128

Reza Rahman

October 24, 2017
Tweet

Transcript

  1. HTTP/2 and What it Means for the Jakarta EE Ecosystem

    Reza Rahman Principal Program Manager, Author, Speaker reza_rahman@lycos.com @reza_rahman
  2. Jakarta EE https://jakarta.ee

  3. Why HTTP/2? The Web of the Past

  4. Why HTTP/2? The Web Today

  5. HTTP Pipelining/Head-of-Line Blocking style1.css style2.css Client Server index.html index.html style1.css

    style2.css script1.js . . . script2.js . . . script1.js script2.js
  6. Socket Abuse/Max Connections Client Server Client Server Client Server Client

    Server Client Server Client Server
  7. HTTP 1.1 Hacks • File concatenation and image sprites •

    Domain sharding • Inlined assets
  8. • HTTP/2 is new transport layer underneath HTTP/1.1 • Same

    request/response model • No new methods • No new headers • No new URLs or ports HTTP/2 At the Network Layer
  9. • Sockets scarce resource • Only one open per server

    HTTP/2 At the Socket Layer
  10. Socket Abuse/Max Connections Client Server Client Server Client Server Client

    Server Client Server Client Server
  11. Sockets in HTTP/2 Client Server

  12. HTTP/2 Big Ticket Features • Request/response multiplexing • Binary framing

    • Stream prioritization • Server push • Header compression • HTTP/2 upgrade • ALPN • 101 Switching Protocols
  13. HTTP/2 Request/Response Multiplexing

  14. HTTP/2 Request/Response Multiplexing Browser Server Single TCP connection for HTTP

    2 STREAM'4' HEADERS' STREAM'9' HEADERS' STREAM'7' DATA' STREAM'7' HEADERS' STREAM'2' HEADERS' STREAM'2' DATA'
  15. HTTP/2 Header Compression

  16. HTTP/2 Stream Prioritization A B C 4 12 A B

    C D 4 16 12 A B C D 4 12 16
  17. HTTP/2 Server Push • Eliminates need for resource in-lining •

    Lets server populate browser’s cache in advance
  18. • Not secure • Use port 80 • Use existing

    101 Switching Protocols from HTTP/1.1 • Secure • Application Layer Protocol Negotiation (ALPN) HTTP/2 Upgrade from HTTP/1.1
  19. http://www.http2demo.io

  20. Jakarta Servlet 4 Abstracts All This

  21. Jakarta Servlet 4 • Jakarta Servlet well positioned to enable

    HTTP/2 • Low-level protocol changes absorbed transparently • Allow frameworks to effectively leverage server push
  22. • Existing API designed for one request == one response

    • HTTP/2 destroys this assumption • It will be challenging to do justice to the new reality of one request == one or more responses Challenges Exposing HTTP/2 Features in Jakarta Servlet
  23. HTTP/2 Features Exposed in Jakarta Servlet • Request/response multiplexing •

    Binary framing • Stream prioritization • Server push • Header compression • HTTP/2 upgrade • ALPN • 101 Switching Protocols
  24. • HTTP/2 required • Server push • Push resource to

    client for a given URL and headers • Really useful for frameworks that build on Jakarta Servlet, such as Jakarta Faces • Builder API Jakarta Servlet 4 New Features
  25. javax.servlet.http.PushBuilder

  26. Server Push via Builder API

  27. Server Push in Jakarta Faces public class FacesServlet implements Servlet

    { public void service(ServletRequest req, ServletResponse resp) throws IOException, ServletException { //... HttpServletRequest request = (HttpServletRequest) req; try { ResourceHandler handler = context.getApplication().getResourceHandler(); if (handler.isResourceRequest(context)) { handler.handleResourceRequest(context); } else { lifecycle.attachWindow(context); lifecycle.execute(context); lifecycle.render(context); } } }
  28. Server Push in Jakarta Faces public class ExternalContextImpl extends ExternalContext

    { //... public String encodeResourceURL(String url) { if (null == url) { String message = MessageUtils.getExceptionMessageString (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "url"); throw new NullPointerException(message); } ((HttpServletRequest) request).getPushBuilder().path(url).push(); return ((HttpServletResponse) response).encodeURL(url); } //... }
  29. Jakarta EE 8 Implementations https://jakarta.ee/compatibility/ Eclipse GlassFish

  30. Summary • HTTP/2 long in the making and promises to

    speed up the web • Primary focus of Jakarta Servlet 4 is to fully support HTTP/2 • Try it out now!
  31. Resources • http2 explained • https://daniel.haxx.se/http2/ • Jakarta Servlet 4

    Specification • https://jakarta.ee/specifications/servlet/4.0/
  32. None