Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 294
Nicolas Henneaux Avatar asked Feb 20 '17 15:02

Nicolas Henneaux


People also ask

Is HTTP 1.1 still supported?

The first usable version of HTTP was created in 1997. Because it went through several stages of development, this first version of HTTP was called HTTP/1.1. This version is still in use on the web.

What is JAX-RS Client API?

The JAX-RS client API is a Java based API used to access Web resources.


1 Answers

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

like image 154
Nicolas Henneaux Avatar answered Oct 08 '22 14:10

Nicolas Henneaux