Open Liberty上的HTTP / 2支持

时间:2018-01-30 11:11:14

标签: java open-liberty

Open Liberty是否支持HTTP / 2,还是需要在server.xml上进行设置?我环顾四周,但无法找到与此有关的任何内容

我现在有一个推送servlet -

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>");
        }

    }
}

我在newPushBuilder上得到NullPointerException

我运行了Major / Minor版本,它确认我正在运行与我的pom一致的Servlet 4.0 -

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

我的server.xml配置为 -

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

我也在运行Java9

1 个答案:

答案 0 :(得分:2)

您获得PushBuilder因为Push isn't supported for the request you're working with。在使用newPushBuilder()对象之前,应检查null。

HTTP / 2的开放自由支持仍处于开发阶段。在最近的development builds中,PushBuilder如果您符合以下情况,则会返回servlet-4.0

  1. 实现Servlet 4.0,
  2. 启用h2c功能和
  3. 使用不安全的HTTP / 2(h2)驱动请求或通过ALPN(def compare_locality(p,p_loc,s0,s0_loc,s1,s1_loc,s2,s2_loc,s3,s3_loc,s4,s4_loc,s5,s5_loc,s6,s6_loc,s7,s7_loc,s8,s8_loc,s9,s9_loc,s10,s10_loc,s11,s11_loc,s12,s12_loc): locs = [] ss = [s0, s1, s2, ..., s12] s_locs = [s0_loc, ..., s12_loc] for s, s_loc in zip(ss, s_locs): if s == '': break locs.append(s_loc) if len(locs) == 0: return '' else: return compare(p_loc,*locs) )安全HTTP / 2
  4. *浏览器不支持不安全的h2c,并且Java 8不支持ALPN。因此,要在开放自由上使用ALPN,目前最好的方法是使用Oracle的JDK或openjdk以及启用ALPN的bootclasspath技巧。 Oracle和Jetty提供了bootclasspath jar - grizzly-npn-bootstrapalpn-boot - 当配置允许open-liberty使用ALPN来连接安全HTTP / 2时。