Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

java - How to run Jetty with SPDY using ALPN?

I have returned to JDK8 with Jetty and SPDY and I see that now Jetty 9.2 supports ALPN protocol instead of NPN (see my question How to run Jetty with SPDY on JDK8?). So I set bootclasspath:

java -Xbootclasspath/p:c:/jars/alpn-boot/alpn-boot-8.0.0.v2014031 ...

But now I got exception:

Exception in thread "xyz.server" java.lang.NoClassDefFoundError:
        org/eclipse/jetty/npn/NextProtoNego$ServerProvider
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    ...
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnector.<init>(HTTPSPDYServerConnector.java:63)
    at org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnector.<init>(HTTPSPDYServerConnector.java:53)
    at org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnector.<init>(HTTPSPDYServerConnector.java:43)
    at xyz.my.my_httpsrv_jetty.startHTTPSServer(my_httpsrv_jetty.java:359)
    ...

I use java version "1.8.0_05" and jetty 9.2.2.v20140723.

The same error I got with JDK 1.7 and alpn-boot-7.0.0.v20140317.jar on WinXP where I changed if from -Xbootclasspath/p:c:/jars/npn-boot/npn-boot-1.1.7.v20140316.jar

This execption points in my code into:

SSLconnector = new HTTPSPDYServerConnector(server, sslContextFactory);

It seems that even with ALPN jetty needs classes from npn-boot. Is it a bug or I have done something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

HTTPSPDYServerConnector was not updated to ALPN and currently hardcodes usage of NPN.

In order to use ALPN with SPDY you have to configure a ServerConnector instead in this way:

SslContextFactory sslContextFactory = new SslContextFactory();
HttpConfiguration httpConfig = new HttpConfiguration();

SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, "alpn");
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory("spdy/3", "http/1.1");
alpn.setDefaultProtocol("http/1.1");
HTTPSPDYServerConnectionFactory spdy = new HTTPSPDYServerConnectionFactory(SPDY.V3, httpConfig);
HttpConnectionFactory http = new HttpConnectionFactory(httpConfig);

Server server = new Server();
ServerConnector connector = new ServerConnector(server, new ConnectionFactory[]{ssl, alpn, spdy, http});

server.start();

I tracked this as https://bugs.eclipse.org/bugs/show_bug.cgi?id=440756.

Finally, if you don't use the code directly, but use Jetty as a server and deploy webapps to it, Jetty already configures properly either ALPN or NPN depending on the modules that are activated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...