1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.embedded;
20
21 import java.io.File;
22 import java.io.FileNotFoundException;
23
24 import org.eclipse.jetty.server.HttpConfiguration;
25 import org.eclipse.jetty.server.HttpConnectionFactory;
26 import org.eclipse.jetty.server.SecureRequestCustomizer;
27 import org.eclipse.jetty.server.Server;
28 import org.eclipse.jetty.server.ServerConnector;
29 import org.eclipse.jetty.server.SslConnectionFactory;
30 import org.eclipse.jetty.spdy.server.NPNServerConnectionFactory;
31 import org.eclipse.jetty.spdy.server.SPDYServerConnectionFactory;
32 import org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory;
33 import org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy;
34 import org.eclipse.jetty.util.ssl.SslContextFactory;
35
36
37
38
39 public class SpdyConnector
40 {
41 public static void main(String[] args) throws Exception
42 {
43
44 String jettyHomeBuild = "../../jetty-distribution/target/distribution";
45
46
47 String homePath = System.getProperty("jetty.home", jettyHomeBuild);
48 File homeDir = new File(homePath);
49 if (!homeDir.exists())
50 {
51 throw new FileNotFoundException(homeDir.getAbsolutePath());
52 }
53 String jetty_home = homeDir.getAbsolutePath();
54 System.setProperty("jetty.home", jetty_home);
55
56
57 Server server = new Server();
58
59
60 HttpConfiguration http_config = new HttpConfiguration();
61 http_config.setSecureScheme("https");
62 http_config.setSecurePort(8443);
63
64
65 ServerConnector http = new ServerConnector(server,
66 new HttpConnectionFactory(http_config));
67 http.setPort(8080);
68 server.addConnector(http);
69
70
71 SslContextFactory sslContextFactory = new SslContextFactory();
72 sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore");
73 sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
74 sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
75
76
77 HttpConfiguration https_config = new HttpConfiguration(http_config);
78 https_config.addCustomizer(new SecureRequestCustomizer());
79
80
81 HTTPSPDYServerConnectionFactory spdy2 =
82 new HTTPSPDYServerConnectionFactory(2, https_config);
83
84 HTTPSPDYServerConnectionFactory spdy3 =
85 new HTTPSPDYServerConnectionFactory(3, https_config,
86 new ReferrerPushStrategy());
87
88
89 SPDYServerConnectionFactory.checkProtocolNegotiationAvailable();
90 NPNServerConnectionFactory npn = new NPNServerConnectionFactory(
91 spdy3.getProtocol(),
92 spdy2.getProtocol(),
93 http.getDefaultProtocol());
94 npn.setDefaultProtocol(http.getDefaultProtocol());
95
96
97 SslConnectionFactory ssl = new SslConnectionFactory(
98 sslContextFactory, npn.getProtocol());
99
100
101 ServerConnector spdyConnector = new ServerConnector(server, ssl,
102 npn, spdy3, spdy2,
103 new HttpConnectionFactory(https_config));
104 spdyConnector.setPort(8443);
105 server.addConnector(spdyConnector);
106
107
108 server.setHandler(new HelloHandler());
109
110
111 server.start();
112 server.join();
113 }
114 }