HTTP/2 Java 8, Jetty and ALPN

11,862

Solution 1

Netty is preferred for several reasons for making Http/2 connections. Few advantages I have seen using it are :

  • No need for the ALPN jar to be added to the boot classpath. Adding maven dependency "netty-tcnative-boringssl-static" does the job
  • It inherently support a asynchronous model of using the API. Hence it makes it simpler to handle data pushed by the server in case of HTTP/2

Solution 2

Jetty's ALPN boot jar works with both OpenJDK and Oracle's JDK (which is based on OpenJDK).

Jetty's ALPN boot jar must be in the boot classpath, not the regular classpath, like the documentation you linked says.

As such, you must not declare it as a dependency in your pom.xml files (there is no need to, like there is no need for you to specify a dependency on the JDK classes).

JDK 9 will have ALPN support native, there is already some work in that direction.

Share:
11,862
serverfaces
Author by

serverfaces

Updated on June 04, 2022

Comments

  • serverfaces
    serverfaces about 2 years

    I went thru this page: https://www.eclipse.org/jetty/documentation/9.3.x/alpn-chapter.html to have an ALPN boot jar in my classpath and still I can't get it working.

    I am confused as to know if I need an Open SDK Java 8 than Oracle Java 8.

    My Java version is:

    java -version
    java version "1.8.0_11"
    Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
    

    And I'm using the following versions of Jetty and ALPN boot:

    <jetty-version>9.4.0.M1</jetty-version>
    <alpn-version>8.1.9.v20160720</alpn-version>    
    <dependency>
            <groupId>org.mortbay.jetty.alpn</groupId>
            <artifactId>alpn-boot</artifactId>
            <version>${alpn-version}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-client</artifactId>
        <version>${jetty-version}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty.http2</groupId>
        <artifactId>http2-client</artifactId>
        <version>${jetty-version}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty.http2</groupId>
        <artifactId>http2-http-client-transport</artifactId>
        <version>${jetty-version}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty.http2</groupId>
        <artifactId>http2-common</artifactId>
        <version>${jetty-version}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty.http2</groupId>
        <artifactId>http2-hpack</artifactId>
        <version>${jetty-version}</version>
    </dependency>
    

    Also I tried using different versions of Jetty and ALPN which I found here https://mvnrepository.com/artifact/org.mortbay.jetty.alpn/alpn-boot and here https://mvnrepository.com/search?q=org.eclipse.jetty

    Whichever ways I tried I never got it working submitting a POST request to an HTTP/2 endpoint.

    However with Netty and the following dependency my tests were successful:

    <dependency>
               <groupId>io.netty</groupId>
               <artifactId>netty-tcnative-boringssl-static</artifactId>
               <version>1.1.33.Fork22</version>
           </dependency>
    

    Where do I find the documentation to see which version of ALPN boot is compatible with Oracle JDK? Is ALPN boot only compatible with OpenJDK?

    I read that starting Java 9 support for ALPN will be native.

    On a side note, which one is better? Netty or Jetty for HTTP/2 calls.

  • serverfaces
    serverfaces over 7 years
    Thanks, I tried setting it this way too: -Xbootclasspath/p:/Users/foo/.m2/repository/org/mortbay/jett‌​y/alpn/alpn-boot/8.1‌​.5.v20150921/alpn-bo‌​ot-8.1.5.v20150921.j‌​ar
  • sbordet
    sbordet over 7 years
    You are on JDK 8u11 (very old, please update), so you must use ALPN boot jar version 8.1.0.v20141016. You want to refer to this table for the right match of JDK and ALPN.
  • nilskp
    nilskp over 6 years
    What is needed for 9.4.x to work with Java 9? Are there any docs published?
  • Thunderforge
    Thunderforge almost 6 years
    Is there any reason that Netty would be preferred over Java 9's native support for HTTP/2 connections?