将HTTP / 2与JAX-RS客户端一起使用

时间:2016-10-27 09:22:26

标签: java jersey jetty jax-rs http2

我正在尝试使用JAX-RS HTTP / 2服务器和客户端。服务器端工作,但我不能使用JAX-RS抽象使客户端正常工作。我使用Jersey2 JAX-RS实现和嵌入式Jetty HTTP服务器。我还使用Jersey代理客户端通过接口直接使用API​​。构建客户端的方法如下。

<div class="mc_wrapper">
  <div class="mp-pusher" id="mp-pusher">
    <nav>Side Nav</nav>
    <div class="scroller">
      <header>
        <h1>this is header</h1>
      </header>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
      <p>this is content lkdzfljljsdf </p>
    </div>
  </div>
</div>

您是否有使用相同抽象级别的解决方案?

修改

根据@sbordet的回答,我实现了一个支持基于JettyClient的HTTP / 2的客户端连接器。代码位于GitHub

1 个答案:

答案 0 :(得分:3)

Jersey允许使用transport connectors自定义传输。

已经有使用Jetty HttpClient的Jersey客户端传输,但它配置为使用HTTP / 1.1而不是HTTP / 2,请参阅https://github.com/jersey/jersey/blob/master/connectors/jetty-connector/src/main/java/org/glassfish/jersey/jetty/connector/JettyConnector.java

我猜你的选择是自己实现泽西ConnectorProviderConnector,主要是基于那些已经可用的,但是如Jetty {{中所述'配置HTTP / 2传输3}};或要求Jersey开发人员在现有HttpClient覆盖中创建JettyConnector实例,以便您可以使用HTTP / 2自定义HttpClient传输。

请注意,如果您使用HTTP / 2,则需要支持ALPN,如documentation中所述。