http/2 in the java platform -- java champions call february 2016

33
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Java HTTP/2 Update Edward Burns Java EE Specifications Team February 2016 Java Champions Call

Upload: ed-burns

Post on 09-Feb-2017

1.004 views

Category:

Software


0 download

TRANSCRIPT

Page 1: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Java HTTP/2 Update

Edward BurnsJava EE Specifications TeamFebruary 2016

Java Champions Call

Page 2: HTTP/2 in the Java Platform -- Java Champions call February 2016

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.

Page 3: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 4: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 5: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 6: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

.

.

.

Page 7: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 8: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 9: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 10: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 11: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Standing on the Shoulders

11 E

Page 12: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

12 E

Page 13: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

13 E

Page 14: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

14 E

Page 15: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

15 E

Page 16: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

16 E

Page 17: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

17 E

Page 18: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Network Programming Review

18 E

Page 19: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 20: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 21: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 22: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 23: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 24: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 25: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 26: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 27: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 28: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 29: HTTP/2 in the Java Platform -- Java Champions call February 2016

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

Page 30: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

javax.servlet.http.PushBuilder

S

Page 31: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 31

Server Push via Builder API

Servlet 4.0Big TicketNew Features

S

Page 32: HTTP/2 in the Java Platform -- Java Champions call February 2016

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.

Page 33: HTTP/2 in the Java Platform -- Java Champions call February 2016

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Questions?