Jetty HTTP/2 Client example

2019-05-17 16:33发布

问题:

I used the client code Jetty provide to us. And some problem occurs. The code I wanna run is here https://github.com/eclipse/jetty.project/blob/master/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/Client.java

And actually I know I come across the same problem like this Jetty HTTP/2 client receive server push example I stopped at this guy's update 2 and I have built a new project under the http2-client folder. But the problem still remains.

INFO::main: Logging initialized @170ms
Exception in thread "main" java.util.concurrent.TimeoutException
at org.eclipse.jetty.util.FuturePromise.get(FuturePromise.java:130)
at org.eclipse.jetty.http2.client.Client.main(Client.java:56)

The jar I use is Jetty-9.3.3. I completely don't know what's wrong. The dev environment is eclipse luna.

回答1:

Make sure you are adding the ALPN jar to the boot classpath and that the jar is the right version for your version of Java. See this table: https://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions

If you are using Java version "1.8.0_51" then the additional VM parameter should be:

-Xbootclasspath/p:/full/path/to/alpn-boot-8.1.4.v20150727.jar

I was getting the same timeout exception, and in my case it turned out that I was not adding the alpn-boot jar to the boot classpath correctly. Specifically, I was not using the full absolute path to the jar. The VM does not give any errors if the boot classpath is invalid. Giving the absolute path fixed the issue for me.