带 SSL 的 Jetty HttpClientTransportOverHTTP2

Jetty HttpClientTransportOverHTTP2 with SSL

我正在尝试使用 Jetty 的 HttpClientTransportOverHTTP2 发出简单的 GET 请求,但它失败了。这是我的代码:

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.util.ssl.SslContextFactory;

public class JettyClientExample {

    public static void main(String[] args) throws Exception {
        HttpClientTransportOverHTTP2 clientTransport = new HttpClientTransportOverHTTP2(new HTTP2Client());
        HttpClient client = new HttpClient(clientTransport,  new SslContextFactory(true));
        client.start();
        ContentResponse response = client.GET("https://http2.akamai.com");
        System.out.println("Version: " + response.getVersion());
        System.out.println("Status: " + response.getStatus());
        System.out.println("Content: " + response.getContentAsString());
    }
}

这是我在行 client.GET("https://http2.akamai.com")

中得到的异常
Exception in thread "main" java.util.concurrent.ExecutionException: java.nio.channels.ClosedChannelException
    at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118)
    at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:653)
    at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:343)
    at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:328)
    at de.consol.labs.h2c.examples.client.okhttp.JettyClientExample.main(JettyClientExample.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.nio.channels.ClosedChannelException
    at org.eclipse.jetty.http2.HTTP2Session.onShutdown(HTTP2Session.java:779)
    at org.eclipse.jetty.http2.HTTP2Connection$HTTP2Producer.produce(HTTP2Connection.java:181)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:162)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.execute(ExecuteProduceConsume.java:101)
    at org.eclipse.jetty.http2.HTTP2Connection.onOpen(HTTP2Connection.java:80)
    at org.eclipse.jetty.http2.client.HTTP2ClientConnectionFactory$HTTP2ClientConnection.onOpen(HTTP2ClientConnectionFactory.java:105)
    at org.eclipse.jetty.io.ssl.SslConnection.onOpen(SslConnection.java:152)
    at org.eclipse.jetty.io.ClientConnectionFactory$Helper.open(ClientConnectionFactory.java:70)
    at org.eclipse.jetty.io.ClientConnectionFactory$Helper.replaceConnection(ClientConnectionFactory.java:63)
    at org.eclipse.jetty.io.NegotiatingClientConnection.replaceConnection(NegotiatingClientConnection.java:113)
    at org.eclipse.jetty.io.NegotiatingClientConnection.onFillable(NegotiatingClientConnection.java:89)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:192)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint.run(SelectChannelEndPoint.java:75)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:745)

我正在使用版本 9.3.3.v20150827,并且我将 ALPN JAR 放入我的引导类路径 -Xbootclasspath/p:<path>

出于某种原因,我没有在互联网上找到任何使用 SSL HttpClientTransportOverHTTP2 的工作示例。

我错过了什么?

您点击了 this bug,已在 Jetty 9.3.4 中修复。