Jetty 客户端无法通过 HTTP/2 连接到 Jetty 服务器
Jetty client can't connect to Jetty server via HTTP/2
下面我使用 "HTTPS/1.1" 表示 HTTPS over HTTP1.1。以下所有连接都是 HTTPS,没有纯 HTTP。
我的服务器在端口 10443 上以 HTTPS/1.1 的形式运行嵌入式 Jetty,在端口 10444 上以 HTTPS/2 的形式运行。两个端口都可以工作,它们之间没有其他区别。 HTTPS/1 的回退也有效(使用 chromium-browser --disable-http2
测试)。这是整个客户端代码:
public static void main(String[] args) throws Exception {
final HttpClient httpClient = new HttpClient(new SslContextFactory());
httpClient.start();
httpClient.GET(TEST_URL);
}
测试URL是localhost
使用thawte签名的证书,是正确的,但显然对localhost
无效。
我很惊讶 HTTPS/1 有效,因为 curl 用
拒绝了它
curl: (51) SSL: certificate subject name (...) does not match target host name 'localhost'
我可能一直在愚弄全局 java 密钥库,这也许可以解释为什么它可以与 Jetty 一起使用。但是,使用 Jetty 的 HTTPS/2 不起作用,我得到的只是这两个神秘的堆栈跟踪:
17:28:23.870 [HttpClient@1729199940-16] WARN org.eclipse.jetty.http.HttpParser - Illegal character 0x0 in state=START for buffer DirectByteBuffer@7daa7e20[p=1,l=32,c=16384,r=31]={\x00<<<\x00\x17\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01invalid_preface>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
17:28:23.872 [HttpClient@1729199940-16] DEBUG org.eclipse.jetty.http.HttpParser - Parse exception: HttpParser{s=START,0 of 0} for HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=START,0 of 0}]
org.eclipse.jetty.http.HttpParser$IllegalCharacterException: 400: Illegal character 0x0
at org.eclipse.jetty.http.HttpParser.next(HttpParser.java:488)
at org.eclipse.jetty.http.HttpParser.quickStart(HttpParser.java:551)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1356)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:170)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:131)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:70)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:130)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:116)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:289)
at org.eclipse.jetty.io.ssl.SslConnection.succeeded(SslConnection.java:149)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:597)
at java.lang.Thread.run(Thread.java:748)
在日志中并且
Exception in thread "main" 17:28:23.897 [main] DEBUG org.eclipse.jetty.client.HttpExchange - Failed HttpExchange@6cace8ba req=TERMINATED/null@null res=TERMINATED/org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]@2577736b: req=false/rsp=false {}
java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]
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:682)
at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:343)
at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:328)
at ....main(OcJettyClientDemo.java:51)
Caused by: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.badMessage(HttpReceiverOverHTTP.java:331)
at org.eclipse.jetty.http.HttpParser.badMessage(HttpParser.java:1478)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1460)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:170)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:131)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:70)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:130)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:116)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:289)
at org.eclipse.jetty.io.ssl.SslConnection.succeeded(SslConnection.java:149)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:597)
at java.lang.Thread.run(Thread.java:748)
作为结果。只有上面的警告,日志中没有错误(有 400 行;我想这里 post 有点太多了)。
我可以想象,使用无效证书是浪费时间,我不在乎,如果没有可能相关的问题,我确实在乎(iOS 客户不能说话HTTP/2 在生产中;我目前没有关于它的数据)。
我的配置:
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
org.eclipse.jetty.alpn:alpn-api:1.1.3.v20160715
org.eclipse.jetty.http2:http2-server:9.4.7.v20170914
org.eclipse.jetty:jetty-alpn-server:9.4.7.v20170914
org.eclipse.jetty:jetty-client:9.4.7.v20170914
org.eclipse.jetty:jetty-servlets:9.4.7.v20170914
Linux 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
知道发生了什么事吗?
更新
Jetty 客户端也不适用于我们的生产站点(有有效证书)。当使用chromium-browser --disable-http2
连接到我们的生产站点时,它显示HTTP/1 headers,但是协议栏中有h2。
要让 Jetty 的 HttpClient
与 HTTP/2 一起工作,您需要使用 HTTP/2 传输 as explained in the documentation.
实例化它
在 HTTP/2 和 HTTP/1 之间自动切换的支持正在开发中,请参阅 https://github.com/eclipse/jetty.project/issues/1350。
另请记住,要 HTTP/2 通过 TLS 工作,您还需要设置 ALPN。
推荐的方法是使用内置支持 ALPN 的 JDK 9,因此您需要在类路径中添加 jetty-alpn-java-client
工件,另请参见 http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html.
下面我使用 "HTTPS/1.1" 表示 HTTPS over HTTP1.1。以下所有连接都是 HTTPS,没有纯 HTTP。
我的服务器在端口 10443 上以 HTTPS/1.1 的形式运行嵌入式 Jetty,在端口 10444 上以 HTTPS/2 的形式运行。两个端口都可以工作,它们之间没有其他区别。 HTTPS/1 的回退也有效(使用 chromium-browser --disable-http2
测试)。这是整个客户端代码:
public static void main(String[] args) throws Exception {
final HttpClient httpClient = new HttpClient(new SslContextFactory());
httpClient.start();
httpClient.GET(TEST_URL);
}
测试URL是localhost
使用thawte签名的证书,是正确的,但显然对localhost
无效。
我很惊讶 HTTPS/1 有效,因为 curl 用
拒绝了它curl: (51) SSL: certificate subject name (...) does not match target host name 'localhost'
我可能一直在愚弄全局 java 密钥库,这也许可以解释为什么它可以与 Jetty 一起使用。但是,使用 Jetty 的 HTTPS/2 不起作用,我得到的只是这两个神秘的堆栈跟踪:
17:28:23.870 [HttpClient@1729199940-16] WARN org.eclipse.jetty.http.HttpParser - Illegal character 0x0 in state=START for buffer DirectByteBuffer@7daa7e20[p=1,l=32,c=16384,r=31]={\x00<<<\x00\x17\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01invalid_preface>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
17:28:23.872 [HttpClient@1729199940-16] DEBUG org.eclipse.jetty.http.HttpParser - Parse exception: HttpParser{s=START,0 of 0} for HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=START,0 of 0}]
org.eclipse.jetty.http.HttpParser$IllegalCharacterException: 400: Illegal character 0x0
at org.eclipse.jetty.http.HttpParser.next(HttpParser.java:488)
at org.eclipse.jetty.http.HttpParser.quickStart(HttpParser.java:551)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1356)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:170)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:131)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:70)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:130)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:116)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:289)
at org.eclipse.jetty.io.ssl.SslConnection.succeeded(SslConnection.java:149)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:597)
at java.lang.Thread.run(Thread.java:748)
在日志中并且
Exception in thread "main" 17:28:23.897 [main] DEBUG org.eclipse.jetty.client.HttpExchange - Failed HttpExchange@6cace8ba req=TERMINATED/null@null res=TERMINATED/org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]@2577736b: req=false/rsp=false {}
java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]
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:682)
at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:343)
at org.eclipse.jetty.client.HttpClient.GET(HttpClient.java:328)
at ....main(OcJettyClientDemo.java:51)
Caused by: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]<-DecryptedEndPoint@7cd58c23{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=20/0}->HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]->SocketChannelEndPoint@36772236{localhost/127.0.0.1:10444<->/127.0.0.1:50040,OPEN,fill=-,flush=-,to=8/0}{io=0/0,kio=0,kro=1}->SslConnection@3fba7a47{NOT_HANDSHAKING,eio=31/-1,di=-1}=>HttpConnectionOverHTTP@409cfd31(l:/127.0.0.1:50040 <-> r:localhost/127.0.0.1:10444,closed=false)=>HttpChannelOverHTTP@17f52ec2(exchange=HttpExchange@6cace8ba req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6f458d2b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@653a2561{s=START}],recv=HttpReceiverOverHTTP@42e82982(rsp=IDLE,failure=null)[HttpParser{s=CLOSE,0 of 0}]]
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.badMessage(HttpReceiverOverHTTP.java:331)
at org.eclipse.jetty.http.HttpParser.badMessage(HttpParser.java:1478)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1460)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:170)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:131)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:70)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:130)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:116)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:289)
at org.eclipse.jetty.io.ssl.SslConnection.succeeded(SslConnection.java:149)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:597)
at java.lang.Thread.run(Thread.java:748)
作为结果。只有上面的警告,日志中没有错误(有 400 行;我想这里 post 有点太多了)。
我可以想象,使用无效证书是浪费时间,我不在乎,如果没有可能相关的问题,我确实在乎(iOS 客户不能说话HTTP/2 在生产中;我目前没有关于它的数据)。
我的配置:
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
org.eclipse.jetty.alpn:alpn-api:1.1.3.v20160715
org.eclipse.jetty.http2:http2-server:9.4.7.v20170914
org.eclipse.jetty:jetty-alpn-server:9.4.7.v20170914
org.eclipse.jetty:jetty-client:9.4.7.v20170914
org.eclipse.jetty:jetty-servlets:9.4.7.v20170914
Linux 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
知道发生了什么事吗?
更新
Jetty 客户端也不适用于我们的生产站点(有有效证书)。当使用chromium-browser --disable-http2
连接到我们的生产站点时,它显示HTTP/1 headers,但是协议栏中有h2。
要让 Jetty 的 HttpClient
与 HTTP/2 一起工作,您需要使用 HTTP/2 传输 as explained in the documentation.
在 HTTP/2 和 HTTP/1 之间自动切换的支持正在开发中,请参阅 https://github.com/eclipse/jetty.project/issues/1350。
另请记住,要 HTTP/2 通过 TLS 工作,您还需要设置 ALPN。
推荐的方法是使用内置支持 ALPN 的 JDK 9,因此您需要在类路径中添加 jetty-alpn-java-client
工件,另请参见 http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html.