Servlet 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 Java ecosystem including the foundational Servlet 4 specification included in Java/Jakarta EE 8.
Strategies for Landing an Oracle DBA Job as a Fresher
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE ecosystem
1. HTTP/2 on Java
And what it means for the Java/Jakarta EE ecosystem
Ed Burns @edburns
Principal Architect Java on Azure Developer Experiences
2020-07
2. HTTP/2 Comes to Java
Servlet 4.0 and what it means to the Java/Jakarta EE
Ecosystem
Ed Burns @edburns
Principal Architect Java on Azure Developer Experiences
2020-07
3. • Brief Personal Journey
• Java/Jakarta EE on Azure
• Servlet 4
• HTTP/2 and Servlet 4
• New Improvements
• Summary
My Plan for Your Time Investment
4. Professional Biography
Client
NCSA Mosaic (1994)
SGI Cosmo Web Authoring
Sun Netscape 6 OJI
Server
J2EE JSF (2002)
Oracle Java EE
Servlet, JSF, Bean Validation, etc.
Microsoft Azure Cloud (2019)
Books
5. Starting on the Client: Birth of a Big Thing
Oil and Chemistry Building at University of
Illinois in Urbana-Champaign
Home of NCSA Mosaic
First Graphical Web Browser
Gratis and Free software
Built on prior work really well
Ubiquitous (cross platform)
Delivered something everyone
wanted
Easy to author: copy and paste from
view source!
6. Cobbles existing things together in an
exciting new way.
Simplicity: HTTP/1.0, TCP/IP sockets
Anyone can add new servers, no need
to ask permission.
Leverages network effect
Dabbling on the Server
7. Birth of the Monolith: Spring and J2EE
Addressed shared pain points
Transparent development process
Spring rode the crest of vendor
marketing efforts, differentiated
with operational excellence
J2EE had multi-vendor concept,
strong community governance
Photo: Les Chatfield
8. My First “War”: Web Frameworks
Good variety of “good enough” tools
Created a component ecosystem
Lots of buzz around this space due to
“Web Framework Wars”
9. The Cloud: Birth of Another Big Thing
2004: Sun Utility Computing
before it’s time…and at the wrong home
10. I’m Ready for the Cloud
My response to cloud disruption
Get out from inside of the monolith
Work with the hosting platform
Monolith
Microservices
Helps enterprises scale
11. Java EE on Azure with Oracle WebLogic
Azure Marketplace Solution for WebLogic
Published, maintained and supported by Oracle
Based on Oracle Linux 7.6, Oracle JDK and WebLogic 12c R2
(12.2.1.3)
Bring your own license
Supports common use-cases such as load-balancing and clustering
12.
13. WebLogic Server on Azure IaaS
Script file
ARM template
Virtual Network
Admin Server Public IP
Admin Server NIC
Admin Sever VM
Managed Sever Public IPs
Managed Server NICs
Managed Server VMs
Storage
14. WebLogic on Azure IaaS
Four Azure Application Offers in the Marketplace
• Create a single VM with WebLogic Admin Only
domain pre-configured
• Create an N-node WebLogic cluster with the admin
server on one VM and cluster members on
other VMs
• Create an N-node WebLogic cluster as in the
preceding offer, but with an Azure LoadBalancer
automatically configured for the cluster
• Create an N-node WebLogic dynamic cluster with
the admin server on one VM and managed servers in
a Dynamic cluster on the other nodes
20. HTTP/2
Perception is Reality (especially with Web Browsers)
Reduced perception of
latency
Header field
compression
21. HTTP/2
Perception is Reality (especially with Web Browsers)
Reduced perception of
latency
Header field
compression
Multiple
concurrent
exchanges
22. HTTP/2 is really just a new transport
layer underneath HTTP/1.1
– same request/response model
– no new methods
– no new headers
– no new usage patterns from
application layer
– no new usage of URL spec and other
lower level specs
Network Programming Review
31. • HTTP/1.0
– Sockets are a throwaway resource
– Specification says very little about how
sockets are to be used
– Browsers free to open many sockets to
the same server
Network Programming Review
Credit: chrisjstanley flickr
The Socket Angle
32. Network Programming Review
The Socket Angle
• HTTP/2
– Sockets seen as a scarce resource
– Specification says much about how
they are to be used
– Only one open per server
33. Network Programming Review
The Socket Angle
Client ServerClient Server
Client Server
Client Server
Client Server
Client Server
35. Network Programming Review
• HTTP/1.0 was designed to be easy to implement with contemporary
development practices of 1991
– text based protocol
– leaves flow control to the TCP layer
– easy to write a parser
– simple socket lifecycle
The Adoption Angle
36. Network Programming Review
• HTTP/2 is much more complicated to implement
– state machine
– flow control
– header compression
– binary framing (arguably easier than text based for parsing)
The Adoption Angle
38. HTTP/2 Request Response Multiplexing
• Fully bi-directional
• Enabled by defining some terms
– Connection
A TCP socket
– Stream
A “channel” within a connection
– Message
A logical message, such as a request or a response
– Frame
The smallest unit of communication in HTTP/2.
Lets the protocol do more things with a single TCP connection
39. HTTP/2 Request Response Multiplexing
• Fully bi-directional
• Enabled by defining some terms
– Connection
A TCP socket
– Stream
A “channel” within a connection
– Message
A logical message, such as a request or a response
– Frame
The smallest unit of communication in HTTP/2.
Lets the protocol do more things with a single TCP connection
Back pressure?
40. HTTP/2 Request Response Multiplexing
• Fully bi-directional
• Enabled by defining some terms
– Connection
A TCP socket
– Stream
A “channel” within a connection
– Message
A logical message, such as a request or a response
– Frame
The smallest unit of communication in HTTP/2.
Lets the protocol do more things with a single TCP connection
Flow control
42. HTTP/2 Request Response Multiplexing
• Once you break the communication down into frames, you can interweave
the logical streams over a single TCP connection.
• Yet another idea from the 1960s is new again.
Connections, Streams, Messages, Frames
Browser
ServerSingle TCP connection for HTTP 2
STREAM'4'
HEADERS'
STREAM'9'
HEADERS'
STREAM'7'
DATA'
STREAM'7'
HEADERS'
STREAM'2'
HEADERS'
STREAM'2'
DATA'
43. HTTP/2 Binary Framing
• Solves Head-Of-Line (HOL) blocking problem
• Type field can be DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS,
PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION
Enabled by dumping newline delimited ASCII
Length (24)
Type (8) Flags (8)
R Stream Identifier (31)
Frame Payload (0 …)
44. HTTP/2 Header Compression
• Observation: most of the headers
are the same in a given connection
– Host: Accept: user-agent: etc.
• Why send them every time?
• Have the server and the client keep
tables of headers, then just send
references and updates to the
tables.
Known as HPACK
45. HTTP/2 Stream Prioritization
• Stream Dependency in HEADERS Frame
• PRIORITY frame type
• An additional 40 bytes
– Stream id (31)
– Weight (8): [1, 256]
– Exclusive bit (1)
• Only a suggestion
A
B C
4 12
A
B CD
4 16 12
exclusive = 0
A
B C
D
4 12
16
exclusive = 1
46. HTTP/2 Server Push
• Eliminates the need for resource inlining.
• Lets the server populate the browser’s cache in advance of the browser
asking for the resource to put in the cache.
• No corresponding JavaScript API, but can be combined with SSE
– Server pushes stuff into the browser’s cache.
– Server uses SSE to tell the browser to go fetch it (but we know it’s already in the
browser’s cache).
47. HTTP/2 Upgrade from HTTP/1.1
• Not secure (h2c)
– We have to use port 80
– Use existing 101 Switching Protocols from HTTP/1.1
– No Browsers implement this!
• Secure (h2)
– Application Layer Protocol Negotiation (ALPN)
Secure or not-secure?
48. • Allow frameworks to effectively
leverage server push
– flexible strategies for leveraging push
• Leverage ALPN
Abstractions Endure
Servlet API is Well Positioned to Enable HTTP/2 Optimizations
49. • Request/Response multiplexing
• Binary Framing/Flow Control
• Stream Prioritization
• Server Push
• Header Compression
• Upgrade from HTTP/1.1
– ALPN
– 101 Switching Protocols
HTTP/2 Features
Servlet 4.0 Big Ticket New Features
50. • Request/Response multiplexing
• Binary Framing/Flow Control
• Stream Prioritization
• Server Push
• Header Compression
• Upgrade from HTTP/1.1
– ALPN
– 101 Switching Protocols
HTTP/2 Features Potentially Exposed in Servlet API
Servlet 4.0 Big Ticket New Features
51. Servlet 4.0 Big Ticket New Features
• HTTP/2 Required, including ALPN and HPACK
• HTTP/2 Server Push
– Push resource to client for a given url and headers
– Not at all a replacement for WebSocket
– Really useful for frameworks that build on Servlet, such as JSF
– Builder API
• Ease of Use
53. Server Push via Builder API
Servlet 4.0
Big Ticket
New Features
54. Server Push
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);
}
}
}
Example of Potential Use from JSF
55. Server Push
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);
}
//…
}
Example of Potential Use from JSF