Search code examples
javahttpjerseyjettyhttp2

Support HTTP/1.1 and HTTP/2 with a JAX-RS client


I want to implement a JAX-RS client that support HTTP/1.1 and HTTP/2 for a JAX-RS client.

The idea is to use HTTP/2 if the server supports ALPN with HTTP/2 and uses HTTP/1.1 if the server does not provide any information.

I have read some articles about ALPN and it seems to be possible but I don't find anything supporting these protocol at the same time. I did not manage to plug these together.

I am currently using the Jetty HTTP/1.1 transport connector for Jersey and a custom implementation for HTTP/2 transport connector.


Solution

  • Java HTTP client provided with Java 11 is supporting HTTP/1.1 and HTTP/2 (see Introduction to the Java HTTP Client).

    I have built a connector using it Jersey Connector using java.net.http.HttpClient. You can use it adding the following dependency.

    <dependency>
      <groupId>com.github.nhenneaux.jersey.connector.httpclient</groupId>
      <artifactId>jersey-httpclient-connector</artifactId>
      <version>0.2.2</version>
    </dependency>
    

    Maven Central