1

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

farrellmr
  • 1,815
  • 2
  • 15
  • 26

1 Answers1

2

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.

wtlucy
  • 704
  • 3
  • 10
  • 1
    from HTTPServletRequest javadoc: "A builder that can be used to generate push requests based on this request or null if push is not supported. " – covener Jan 30 '18 at 18:44
  • Thanks - Im doing the above,with the exception of 3? Ive updated my config - also Im running a nightly openliberty-all-17.0.0.4-201712100749.zip. Any ideas? – farrellmr Jan 30 '18 at 18:57
  • Also im using curl with http2 – farrellmr Jan 30 '18 at 19:07
  • In my curl 7.58.0 build it looks like curl is disabling push requests via HTTP/2 SETTINGS_ENABLE_PUSH - so that may be your issue. I'd recommend setting up ALPN and using push over secure h2. Also, I'd recommend using the most recent development versions of open liberty, since this code is actively developed. – wtlucy Jan 31 '18 at 15:03