News Ticker

Servlet 4.0: 100DaysOfJavaEE8

100 Days Of Java EE 8: Solution

Servlet 4.0 API Challenge

Servlets 4.0 introduces support for HTTP/2 feature ServerPush. What happens when a request is made to the URI /duke over an insecure connection. i.e. over HTTP connection?

servlets_4_serverpush

Answer

The features of HTTP/2 are only enabled over secure TLS connection when the request is made from a browser that only supports HTTP/2 over a secure connection and as all major browsers fall into this category a request to the URI /duke will not be made over HTTP/2 but rather via HTTP 1.x. This means that the server push feature will not be enabled and the call to newPushBuilder() will return null. As there are no null checks the code in the doGet() method will throw a NullPointerException.

This was a tricky question.

Further Reading

For further information on how to use the new JSON Binding API take a look at my new book Java EE 8: Only What’s New.

GitHub Repository

The code from this and all other #100DaysOfJavaEE8 can be found in my GitHub repository.

1 Trackback / Pingback

  1. #100DaysOfJavaEE8: Weekly Round Up

Leave a Reply

%d bloggers like this: