Mais conteĂșdo relacionado Semelhante a 2015 UJUG, Servlet 4.0 portion (20) 2015 UJUG, Servlet 4.0 portion2. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction.
It is intended for information purposes only, and may not be
incorporated into any contract. It is not a commitment to deliver
any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and
timing of any features or functionality described for Oracleâs
products remains at the sole discretion of Oracle.
2
3. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Agenda
Why HTTP/2?
HTTP/2 Big Features
How Servlet Might Expose These Features
Server Push and JSF/MVC
Summary and Current Status
1
2
3
4
5
3
4. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
A Real Life Example
index.htm
l
style1.css
style2.css
.
.
.
script1.js
script9.js
pic1.jpg
pic8.jpg
.
.
.
photo1.p
ng
photo2.p
ng
.
.
.
5. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
âą HTTP Pipelining
âą Head-of-Line
blocking
Problems in HTTP/1.1
style1.css
style2.css
Client Server
index.html
index.html
style1.css
style2.css
script1.js
.
.
.
script2.js
.
.
.
script1.js
script2.js
6. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
âą Inefficient use of TCP sockets
Problems in HTTP/1.1
Client ServerClient Server
Client Server
Client Server
Client Server
Client Server
7. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
âą Much of what we do in web-apps is a hack to work
around shortcomings in HTTP/1.1
â File concatenation and image sprites
â Domain sharding
â Inlined assets
What is an optimization?
7
8. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
File Concatenation and Image Sprites
TCP Efficiency Improves with Larger Files
8
âą Modern web page now consists of more than 90
resources fetched from 15 distinct hosts
âą Solution:
â Just work around it by shoving more than one logical file into
one physical file.
â Seminal article: A List Apart
http://alistapart.com/article/sprites
â Useful tool: SpritePad http://spritepad.wearekiss.com/
9. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
File Concatenation and Image Sprites
TCP Efficiency Improves with Larger Files
9
.ic-AerospaceAndDefense-wht-on-gray, .ic-
AerospaceAndDefense-wht-on-red, .ic-Airline-wht-on-
gray, .ic-Airline-wht-on-red{
background: url(sprites.png) no-repeat;
}
.ic-AerospaceAndDefense-wht-on-gray{
background-position: 0 0;
width: 80px;
height: 80px;
}
.ic-AerospaceAndDefense-wht-on-red{
background-position: -81px 0;
width: 80px;
height: 80px;
}
.ic-Airline-wht-on-gray{
background-position: 0 -80px ;
width: 80px;
height: 80px;
}
.ic-Airline-wht-on-red{
background-position: -81px -79px ;
width: 80px;
height: 80px;
}
10. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Domain Sharding
Split page resources across several hosts to work around browser
limits
10
11. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Inlined Assets
âą data URLs
âą <img
src="data:image/gif;base64,R0lGODlhEAAOALMAAOazT
oeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAA
AAAAQAA4âŠ" />
Base64 Encoding Will Never Die
11
12. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Our Plan for Your Time Investment
Why HTTP/2?
HTTP/2 Big Features
How Servlet Might Expose These Features
Server Push and JSF/MVC
Summary and Current Status
1
2
3
4
5
12
13. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
13
14. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
14
The Socket Angle
âą It would be like if we took
the existing Servlet
specification
15. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
15
The Socket Angle
âą It would be like if we took
the existing Servlet
specification
and added a new layer
underneath it
16. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
The Socket Angle
Client ServerClient Server
Client Server
Client Server
Client Server
17. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
Solution in HTTP/2
Client Server
18. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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.
18
Lets you do more things with a single TCP connection
19. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP/2 Request Response Multiplexing
19
Connections, Streams, Messages, Frames
20. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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.
20
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'
21. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
21
S
A
B C
4 12
A
B CD
4 16 12
exclusive = 0
A
B C
D
4 12
16
exclusive = 1
22. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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).
22
E
23. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP/2 Upgrade from HTTP/1.1
âą Not secure
â We have to use port 80
â Use existing 101 Switching Protocols from HTTP/1.1
âą Secure
â Next Protocol Negotiation (NPN)
â Application Layer Protocol Negotiation (ALPN)
23
Secure or not-secure?
24. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Agenda
Why HTTP/2?
HTTP/2 Big Features
How Servlet Might Expose These Features
Server Push and JSF/MVC
Summary and Current Status
1
2
3
4
5
24
25. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
âą Existing API is 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.
âą We must not simply bolt the âOne or More Responsesâ
concept onto some convenient part of the existing API.
25
Challenges in Exposing HTTP/2 Features in Servlet API
Servlet 4.0 Big Ticket New Features
26. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
âą Request/Response multiplexing
âą Stream Prioritization
âą Server Push
âą Upgrade from HTTP/1.1
â 101 Switching Protocols
26
HTTP/2 Features Potentially Exposed in Servlet API
Servlet 4.0 Big Ticket New Features
27. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
âą Add method HttpServletRequest and
HttpServletResponse
â int getStreamId()
27
Request/Response Multiplexing
Servlet 4.0 Big Ticket New Features
28. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
âą Add a new class Priority
â boolean exclusive
â int streamId
â int weight
âą Add method to HttpServletRequest
â Priority getPriority()
âą Add methods to HttpServletResponse
â Priority getPriority()
â void setPriority(Priority p)
28
Stream Prioritization
Servlet 4.0 Big Ticket New Features
29. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
âą Push resource to client for a given url and headers
âą May add callback for completion or error of a push
âą Not at all a replacement for WebSocket
âą Really useful for frameworks that build on Servlet, such
as JSF
29
Server Push
Servlet 4.0 Big Ticket New Features
30. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 30
Server Push
Servlet 4.0
Big Ticket
New Features
Browser
Server Thread A
servlet.service()
GET /index.html
Server
discovers
browser will
need style.css
and script.js
request.dispatchPushRequest("style.css")
request.dispatchPushRequest("script.js")
Server Thread B
servlet.service()
synthetic GET /style.css
synthetic GET /script.js
Server Thread C
servlet.service()
style.css
script.js
index.html
31. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
31
32. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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);
}
Map attrs = getResourceAttrs();
((HttpServletRequest) request).dispatchPushRequest(
url, attrs);
return ((HttpServletResponse) response).encodeURL(url);
}
}
Example of Potential Use from JSF
32
33. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Server Push
âą The MVC EG needs to see how this will be integrated
into the MVC specification so no example at the
moment.
Example for MVC
33
34. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Our Plan for Your Time Investment
Why HTTP/2?
HTTP/2 Big Features
How Servlet Might Expose These Features
Server Push and JSF/MVC
Summary and Current Status
1
2
3
4
5
34
35. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Summary and Current Status
âą Servlet 4.0 brings HTTP/2 to Java EE
â 100% compliant implementation of HTTP/2
â Expose key features to the API
âą Server Push
âą Stream Prioritization
âą Request/Response multiplexing
35
36. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Summary and Current Status
âą JSR-369 just formed on 22 September
âą Tentative Delivery Schedule
â Q3 2014: expert group formed
â Q2 2015: early draft
â Q3 2015: public review
â Q4 2015: proposed final draft
â Q3 2016: final release
36
37. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
How to Get Involved
âą Adopt a JSR
â http://glassfish.org/adoptajsr/
âą The Aquarium
â http://blogs.oracle.com/theaquarium/
âą Java EE 8 Reference Implementation
â http://glassfish.org
37
Notas do Editor out additional information/disclaimers required depending on your audience. Those are the big problems that are out there in the world. This is important because HTTP/2 is essentially a new transport layer underneath the existing HTTP/1.1 semantics + a header compression specification.
Same request/response model
No new HTTP methods (except for PRI but that's just for the protocol)
No new headers (but new names/concepts for old headers)
No new usage pattern from application level
Same usage of URL spec and TCP ports
Another illustration of the socket angle. what can we do at the application level to work around them? Fully bi-directional at the protocol level, no HOL blocking.
Message, not just request and response, there are also control messages. Headers must precede data. Two ways to specify priority: in headers or in a separate frame. Make sure people understand that this is not just an integer. It's not just like, "a bigger integer means it is more important."
B and C depend on A. This information is included as a header in the HEADERS frame.
These numbers are weights that correspond to the priority.
If A is stuck, you can't do anything on A, you would like to do the things that are lower priority, which is B and C in this case. You would distribute the resources in the ratio of 4 to 12.
An exclusive flag allows for the insertion of a new level of dependencies. The exclusive flag causes the stream to become the sole dependency of its parent stream, causing other dependencies to become dependent on the prioritized stream. Patterns: Foreshadow use of Server Push with JSF later
It's a facility to allow the server to pre-populate the browser's cache with data it knows the browser will need anyway.
Here is where you mention that this is not a replacement for WebSocket. It can be used in concert with SSE
----- Meeting Notes (3/11/15 17:16) -----
page speed chrome plugibn