http/2 comes to java. what servlet 4.0 means to you. devnexus 2015

82
HTTP/2 Comes to Java What Servlet 4.0 Means to You Ed Burns Java EE Specification Team Oracle Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Upload: edward-burns

Post on 14-Jul-2015

6.429 views

Category:

Software


2 download

TRANSCRIPT

Page 1: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

HTTP/2 Comes to JavaWhat Servlet 4.0 Means to You

Ed BurnsJava EE Specification TeamOracle

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

Page 2: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Page 3: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

3

Page 4: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

4

Page 5: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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 6: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Why HTTP/2?

• Head-of-Line blocking

Problems in HTTP/1.1

Page 7: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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.cssstyle2.cssscript1.js

.

.

.

script2.js

.

.

.

script1.js

script2.js

Page 8: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Page 9: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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?

9

Page 10: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

File Concatenation and Image SpritesTCP Efficiency Improves with Larger Files

10

Page 11: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

File Concatenation and Image SpritesTCP Efficiency Improves with Larger Files

11

• 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/

Page 12: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

File Concatenation and Image SpritesTCP Efficiency Improves with Larger Files

12

.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;

}

Page 13: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Domain ShardingSplit page resources across several hosts to work around browser limits

13

Page 14: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Inlined Assets

• data URLs

• <imgsrc="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/ /ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4…" />

Base64 Encoding Will Never Die

14

Page 15: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

15

Page 16: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

16

Page 17: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Standing on the Shoulders

17

Page 18: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

18

Page 19: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

19

Page 20: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

20

Page 21: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

21

Page 22: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

22

Page 23: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

23

Page 24: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

24

Page 25: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

• 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

25

Credit: chrisjstanley flickr

The Socket Angle

Page 26: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

26

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

Page 27: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

27

The Socket Angle

• It would be like if we took the existing Servlet specification

Page 28: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

28

The Socket Angle

• It would be like if we took the existing Servlet specificationand added a new layer underneath it

Page 29: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming ReviewProblems in HTTP/1.1

Client ServerClient Server

Client Server

Client Server

Client Server

Client Server

Page 30: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming ReviewSolution in HTTP/2

Client Server

Page 31: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

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

31

Page 32: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Network Programming Review

• HTTP/2 is much more complicated to implement

– state machine

– header compression

– binary framing (arguably easier than text based for parsing)

The Adoption Angle

32

Page 33: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

• HTTP/2 is much more complicated to implement

– No moretelnet host 80

GET /somepage.html \r\n\r\n

33

Network Programming ReviewThe Adoption Angle

Page 34: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

• HTTP/2 is much more complicated to implement

– No moretelnet host 80

GET /somepage.html \r\n\r\n

34

Network Programming ReviewThe Adoption Angle

Page 35: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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• ALPN (or NPN)

• 101 Switching Protocols

35

HTTP/2 Big Ticket Feature Review

Page 36: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Big Ticket Feature Review

Page 37: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Request Response Multiplexing

• Fully bi-directional

• Enabled by defining some terms

– ConnectionA TCP socket

– StreamA “channel” within a connection

–MessageA logical message, such as a request or a response

– FrameThe smallest unit of communication in HTTP/2.

37

Lets you do more things with a single TCP connection

Page 38: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Request Response Multiplexing

38

Connections, Streams, Messages, Frames

Page 39: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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.

39

Connections, Streams, Messages, Frames

BrowserServerSingle TCP connection for HTTP 2

STREAM'4'HEADERS'

STREAM'9'HEADERS'

STREAM'7'DATA'

STREAM'7'HEADERS'

STREAM'2'HEADERS'

STREAM'2'DATA'

Page 40: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

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

40

Enabled by dumping newline delimited ASCII

Length (24)

Type (8) Flags (8)

R Stream Identifier (31)

Frame Payload (0 …)

Page 41: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Binary Framing

GET /index.html HTTP/1.1Host: example.comAccept: text/html

41

Example 1

HEADERS+ END_STREAM+ END_HEADERS

:method: GET:scheme: http:path: /index.html:authority: example.orgaccept: text/html

Page 42: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Binary Framing

HTTP/1.1 200 OKContent-Length: 11Content-Type: text/html

Hello World

42

Example 2

HEADERS- END_STREAM+ END_HEADERS

:status: 200content-length: 11content-type: text/html

DATA+ END_STREAM

Hello World

Page 43: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

43S

A

B C

4 12

A

B CD

4 16 12

exclusive = 0

A

B C

D

4 12

16

exclusive = 1

Page 44: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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).

44E

Page 45: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

HTTP/2 Header Compression

• Observation: most of the headers are the same in a given stream

– 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.

45

Known as HPACK

Page 46: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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)

46

Secure or not-secure?

Page 47: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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)

47

Secure or not-secure?

Page 48: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Criticism of HTTP/2

• HOL blocking is still a problem, just shuffled around

– HOL blocking can still happen in HEADERS frames

• No h2c in Firefox or Chrome

– Mention the IETF RFC-7258

• Carbon footprint for all that HPACK encoding/decoding

• Numerous new DoS attack vectors

• HTTP/2 is orthogonal to WebSocket

Everybody's a Critic

48

Page 49: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Criticism of HTTP/2

• Poul Henning-Kamp's rant just before WGLC

– http://queue.acm.org/detail.cfm?id=2716278

Everybody's a Critic

49

Page 50: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Criticism of HTTP/2

• Poul Henning-Kamp's rant just before WGLC

– http://queue.acm.org/detail.cfm?id=2716278

Everybody's a Critic

50

Page 51: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Criticism of HTTP/2

• Poul Henning-Kamp's rant just before WGLC

– http://queue.acm.org/detail.cfm?id=2716278

Everybody's a Critic

51

Page 52: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Criticism of HTTP/2

• Poul Henning-Kamp's rant just before WGLC

– http://queue.acm.org/detail.cfm?id=2716278

Everybody's a Critic

52

Credit: Michael Fritz

Page 53: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Don't take my word for it

• HTTP/2 isn't one spec, it's two specs

– HTTP/2 protocol

– HPACK

• Built on top of many other specs

53

Page 54: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Don't take my word for it

54

Page 55: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Don't take my word for it

55

Page 56: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Aside

Servlet and Reactive Programming

56

Page 57: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Reactive Programming

57

Responsive

Message Driven

ResilientElastic

image credit: reactivemanifesto.org

Page 58: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Servlet 4.0 and Reactive Programming

• Non-blocking IO in Servlet 3.1

– ServletInputStream• #setReadListener, #isReady

– ServletOutputStream• #setWriteListener, #isReady

– ReadListener• #onDataAvailable, #onAllDataRead, #onError

– WriteListener• #onWritePossible, #onError

58

Page 59: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Servlet 4.0 and Reactive Programming

• Asynchronous in Servlet 3.0

– ServletRequest#startAsync

– AsyncContext• #addListener, #dispatch, #complete

– AsyncListener• #onComplete, #onError, #onStartAsync, #onTimeout

• Event-driven

– Server-Sent Events

59

Page 60: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

60

Page 61: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

61

Page 62: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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.

62

Challenges in Exposing HTTP/2 Features in Servlet API

Servlet 4.0 Big Ticket New Features

Page 63: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

– ALPN or (NPN)

– 101 Switching Protocols

63

HTTP/2 Features

Servlet 4.0 Big Ticket New Features

Page 64: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

– ALPN or (NPN)

– 101 Switching Protocols

64

HTTP/2 Features Potentially Exposed in Servlet API

Servlet 4.0 Big Ticket New Features

Page 65: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

• Add method HttpServletRequest and HttpServletResponse

– int getStreamId()

65

Request/Response Multiplexing

Servlet 4.0 Big Ticket New Features

Page 66: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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)

66

Stream Prioritization

Servlet 4.0 Big Ticket New Features

Page 67: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

67

Server Push

Servlet 4.0 Big Ticket New Features

Page 68: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Server Push

Servlet 4.0Big TicketNew Features

BrowserServer Thread Aservlet.service()

GET /index.html

Server discovers

browser will need style.css and script.js

request.dispatchPushRequest("style.css")

request.dispatchPushRequest("script.js")

Server Thread Bservlet.service()

synthetic GET /style.css

synthetic GET /script.js

Server Thread Cservlet.service()

style.css

script.js

index.html

Page 69: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

69

Page 70: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

70

Page 71: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

71

Page 72: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

• 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!

72

Page 73: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

73

HttpClientHttpClient.Builder

HttpRequest.Builder

HttpRequestHttpRequest

Page 74: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

• A handful of classes

– HttpClient, built by HttpClient.Builder• Holds information for creating one or more HttpRequests

– HttpRequest, built by HttpRequest.Builder• one request/response interaction

– HttpResponse

– Body Processors• HttpRequestBodyProcessor

• HttpResponseBodyProcessor

Small footprint

74

Page 75: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

75

Page 76: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

76

Page 77: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Java SE 9 Support for HTTP/2

Summary and Current Status

1

2

3

4

5

77

Page 78: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

78

Page 79: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Summary and Current Status: HTTP/2

• December 2015 Submit HTTP/2 to IESG for consideration as a Proposed Standard DONE

• January 2015 Submit HTTP/2 to RFC Editor DONE

• February 2015 Publish HTTP/2 as an RFC

79

Page 80: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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 2015: expert group formed

– Q2 2015: early draft

– Q3 2015: public review

– Q4 2015: proposed final draft

– Q3 2016: final release

80

Page 81: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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://glasfish.org

81

Page 82: HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015

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

Safe Harbor Statement

The 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.

82