http/2 in the java platform -- java champions call february 2016
TRANSCRIPT
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java HTTP/2 Update
Edward BurnsJava EE Specifications TeamFebruary 2016
Java Champions Call
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor StatementThe 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.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
• Ed Burns Credentials–Working on Web technologies since 1994– JCP Star Spec-lead 2009– Spec lead for JSF and Servlet
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
My Plan for Your Time Investment
HTTP/2 protocol and justification
HTTP/Related Developments in Java
Q&A
1
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
My Plan for Your Time Investment
HTTP/2 protocol and justification
HTTP/Related Developments in Java
Q&A
1
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?A Real Life Example
index.html
style1.css
style2.css...
script1.js
script9.js
pic1.jpg
pic8.jpg
.
.
.
photo1.png
photo2.png
.
.
.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
• Head of Line Blocking• Inefficient Use of Sockets• Wasteful Use of Network Resources• Not resilient to pervasive monitoring by default
Problems with HTTP/1.1
7 S
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?
8 S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Why HTTP/2?
• Head of Line Blocking – Frame Based Binary Protocol
• Inefficient Use of Sockets– Stream Multiplexing
• Wasteful Use of Network Resources– Header “compression”– Server push
• Not resilient to pervasive monitoring by default– Per RFC-7258, TLS is the default, clear text is optional
Problems with HTTP/1.1
9 S
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
10 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Standing on the Shoulders
11 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
12 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
13 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
14 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
15 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
16 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
17 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Network Programming Review
18 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
• Request/Response multiplexing• Binary Framing• Stream Prioritization• Server Push• Header Compression• Upgrade from HTTP/1.1– Application Layer Protocol Negotiation (ALPN)– 101 Switching Protocols
19
HTTP/2 Big Ticket New Features
S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
1
My Plan for Your Time Investment
HTTP/2 protocol and justification
HTTP/Related Developments in Java
Q&A
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP/2 Related Developments in Java• Java SE JDK 9– JEP 110: HTTP/2 Client– JEP 244: TLS ALPN
• Java EE 8– Servlet 4.0
• Open Source– Jetty– Netty– Grizzly– Undertow
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP/2 Related Developments in Java
• Not yet in Early Access Release – Build 104• Fully functional in internal builds• JEP 110 http://openjdk.java.net/jeps/110• Easy to use API• Covers only the most common use cases• Supports both HTTP/1.1 and 2• Builds on Java API classes going back to Java 1.2!
Java SE JDK 9
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java SE 9 Support for HTTP/2
23
HttpClientHttpClient.Builder
HttpRequest.Builder
HttpRequest
GET
HttpRequest
POST
E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java SE 9 Support for HTTP/2
• Blocking mode: one thread per request/response– send request– get response
• Non-blocking mode– Using ExecutorService and CompletableFuture
• Full support for HTTP/2 Server Push
Small footprint
24 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java SE 9 Support for HTTP/2
HttpResponse response = HttpRequest .create(new URI("http://www.foo.com")) .headers("Foo", "foovalue", "Bar", "barvalue”) .GET() .response();
int statusCode = response.statusCode(); String responseBody = response.body(asString());
25 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java SE 9 Support for HTTP/2: Async CaseList<URI> targets = ... // fetch list of URIs async and store in FilesList<CompletableFuture<File>> futures = targets.stream() .map(target -> { return HttpRequest .create(target).GET().responseAsync().thenCompose(response -> { Path dest = Paths.get("base", target.getPath()); if (response.statusCode() == 200) { return response.bodyAsync(asFile(dest)); } else { return CompletableFuture.completedFuture(dest); } }) // convert Path -> File .thenApply((Path dest) -> { return dest.toFile(); }); }).collect(Collectors.toList());// all async operations waited for hereCompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).join();
26 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java SE 9 Support for HTTP/2
• Negotiation of HTTP/2 from 1.1– ALPN or plaintext
• Server Push– Support for PUSH_PROMISE frames
• HPACK parameters
HTTP/2 features
27 E
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP/2 Related Developments in Java
• Request/Response multiplexing• Binary Framing• Stream Prioritization• Server Push• Header Compression• Upgrade from HTTP/1.1– ALPN– 101 Switching Protocols
Java EE 8 Servlet 4.0
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
29 S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
javax.servlet.http.PushBuilder
S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 31
Server Push via Builder API
Servlet 4.0Big TicketNew Features
S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor StatementThe preceding 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.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Questions?