开放自由上的HTTP/2支持 [英] HTTP/2 Support on Open Liberty

查看:121
本文介绍了开放自由上的HTTP/2支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Open Liberty是否支持HTTP/2,还是需要在server.xml上进行设置?香港专业教育学院环顾四周,但找不到与此有关的任何东西

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

此刻我有一个推式servlet-

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

    }
}

并且在newPushBuilder上收到NullPointerException

And am getting a NullPointerException on newPushBuilder

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

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>

我的server.xml配置为-

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>

我也正在运行Java9

Also Im running Java9

推荐答案

由于

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.

对HTTP/2的开放自由支持仍在开发中.在最新的开发版本中,如果您执行以下操作,则newPushBuilder()将返回PushBuilder:

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

  1. 实施Servlet 4.0,
  2. 启用servlet-4.0功能,然后
  3. 使用不安全的HTTP/2(h2c)或通过ALPN(h2)的安全HTTP/2驱动请求
  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)

*浏览器不支持不安全的h2c,Java 8不支持ALPN.因此,要在开放式自由环境中使用ALPN,当前的最佳方法是与Oracle或openjdk的JDK一起使用,并使用bootclasspath技巧来运行.启用ALPN. Oracle和Jetty提供了引导类路径jar- grizzly-npn-bootstrap

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

这篇关于开放自由上的HTTP/2支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆