farrellmr
farrellmr

Reputation: 1905

HTTP/2 Support on Open Liberty

Does Open Liberty support HTTP/2, or does it need a setting on server.xml? Ive had a look around but cant find anything relating to this

I have a push servlet at the moment -

public class PushServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        PushBuilder pushBuilder = req.newPushBuilder();
         pushBuilder.path("push.css").push();


        try (PrintWriter respWriter = resp.getWriter();) {
            respWriter.write("<html>" +
                    "<img src='images/kodedu-logo.png'>" +
                    "</html>");
        }

    }
}

And am getting a NullPointerException on newPushBuilder

I ran the Major/Minor version and it confirmed I'm running Servlet 4.0 in line with my pom -

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

My server.xml is configured as -

<!-- To access this server from a remote client add a host attribute to 
    the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" >
   <httpOptions http2="enabled" />
</httpEndpoint>

Also Im running Java9

Upvotes: 1

Views: 1006

Answers (1)

wtlucy
wtlucy

Reputation: 724

You're getting a NullPointerException because Push isn't supported for the request you're working with. You should check for null before using the PushBuilder object.

Open liberty support for HTTP/2 is still in development. In the most recent development builds, newPushBuilder() will return a PushBuilder if you:

  1. implement Servlet 4.0,
  2. enable the servlet-4.0 feature, and
  3. drive a request using insecure HTTP/2 (h2c) or secure HTTP/2 via ALPN (h2)

*Browsers don't support insecure h2c, and ALPN isn't supported on Java 8. So to use ALPN on open-liberty the current best approach is to run with a JDK from Oracle or openjdk along with a bootclasspath trick to enable ALPN. Oracle and Jetty provide bootclasspath jars - grizzly-npn-bootstrap and alpn-boot - that when configured allow open-liberty to use ALPN to negoiate secure HTTP/2.

Upvotes: 2

Related Questions