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 import java.lang.management.ManagementFactory;
24
25 import org.eclipse.jetty.deploy.DeploymentManager;
26 import org.eclipse.jetty.deploy.providers.WebAppProvider;
27 import org.eclipse.jetty.jmx.MBeanContainer;
28 import org.eclipse.jetty.security.HashLoginService;
29 import org.eclipse.jetty.server.AsyncNCSARequestLog;
30 import org.eclipse.jetty.server.ForwardedRequestCustomizer;
31 import org.eclipse.jetty.server.Handler;
32 import org.eclipse.jetty.server.HttpConfiguration;
33 import org.eclipse.jetty.server.HttpConnectionFactory;
34 import org.eclipse.jetty.server.NCSARequestLog;
35 import org.eclipse.jetty.server.SecureRequestCustomizer;
36 import org.eclipse.jetty.server.Server;
37 import org.eclipse.jetty.server.ServerConnector;
38 import org.eclipse.jetty.server.SslConnectionFactory;
39 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
40 import org.eclipse.jetty.server.handler.DefaultHandler;
41 import org.eclipse.jetty.server.handler.HandlerCollection;
42 import org.eclipse.jetty.server.handler.RequestLogHandler;
43 import org.eclipse.jetty.server.handler.StatisticsHandler;
44 import org.eclipse.jetty.spdy.server.NPNServerConnectionFactory;
45 import org.eclipse.jetty.spdy.server.SPDYServerConnectionFactory;
46 import org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory;
47 import org.eclipse.jetty.spdy.server.http.PushStrategy;
48 import org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy;
49 import org.eclipse.jetty.util.ssl.SslContextFactory;
50 import org.eclipse.jetty.util.thread.QueuedThreadPool;
51
52 public class SpdyServer
53 {
54 public static void main( String[] args ) throws Exception
55 {
56
57 String jettyHomeBuild = "../../jetty-distribution/target/distribution";
58
59
60 String homePath = System.getProperty("jetty.home", jettyHomeBuild);
61 File homeDir = new File(homePath);
62 if (!homeDir.exists())
63 {
64 throw new FileNotFoundException(homeDir.getAbsolutePath());
65 }
66 String jetty_home = homeDir.getAbsolutePath();
67 System.setProperty("jetty.home", jetty_home);
68
69
70 QueuedThreadPool threadPool = new QueuedThreadPool(512);
71
72
73 Server server = new Server(threadPool);
74 server.manage(threadPool);
75 server.setDumpAfterStart(false);
76 server.setDumpBeforeStop(false);
77
78
79 MBeanContainer mbContainer = new MBeanContainer(
80 ManagementFactory.getPlatformMBeanServer());
81 server.addBean(mbContainer);
82
83
84 HttpConfiguration config = new HttpConfiguration();
85 config.setSecurePort(8443);
86 config.addCustomizer(new ForwardedRequestCustomizer());
87 config.addCustomizer(new SecureRequestCustomizer());
88 config.setSendServerVersion(true);
89
90
91
92
93
94
95
96
97 HttpConnectionFactory http = new HttpConnectionFactory(config);
98 ServerConnector httpConnector = new ServerConnector(server, http);
99 httpConnector.setPort(8080);
100 httpConnector.setIdleTimeout(10000);
101 server.addConnector(httpConnector);
102
103
104
105
106
107
108 SslContextFactory sslContextFactory = new SslContextFactory();
109 sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore");
110 sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
111 sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
112 sslContextFactory.setTrustStorePath(jetty_home + "/etc/keystore");
113 sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
114 sslContextFactory.setExcludeCipherSuites(
115 "SSL_RSA_WITH_DES_CBC_SHA",
116 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
117 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
118 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
119 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
120 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
121 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
122
123
124
125
126 SPDYServerConnectionFactory.checkProtocolNegotiationAvailable();
127
128
129
130
131
132 PushStrategy push = new ReferrerPushStrategy();
133 HTTPSPDYServerConnectionFactory spdy2 =
134 new HTTPSPDYServerConnectionFactory(2, config, push);
135 spdy2.setInputBufferSize(8192);
136 spdy2.setInitialWindowSize(32768);
137
138
139
140
141
142
143 HTTPSPDYServerConnectionFactory spdy3 =
144 new HTTPSPDYServerConnectionFactory(3, config, push);
145 spdy3.setInputBufferSize(8192);
146
147 NPNServerConnectionFactory npn = new NPNServerConnectionFactory(
148 spdy3.getProtocol(), spdy2.getProtocol(), http.getProtocol());
149 npn.setDefaultProtocol(http.getProtocol());
150 npn.setInputBufferSize(1024);
151
152 SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,
153 npn.getProtocol());
154
155
156 ServerConnector spdyConnector = new ServerConnector(server, ssl,
157 npn, spdy3, spdy2, http);
158 spdyConnector.setPort(8443);
159
160 server.addConnector(spdyConnector);
161
162
163
164
165
166
167
168 HandlerCollection handlers = new HandlerCollection();
169 ContextHandlerCollection contexts = new ContextHandlerCollection();
170 RequestLogHandler requestLogHandler = new RequestLogHandler();
171
172 handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(),
173 requestLogHandler });
174
175 StatisticsHandler stats = new StatisticsHandler();
176 stats.setHandler(handlers);
177
178 server.setHandler(stats);
179
180
181 DeploymentManager deployer = new DeploymentManager();
182 deployer.setContexts(contexts);
183 server.addBean(deployer);
184
185 WebAppProvider webapp_provider = new WebAppProvider();
186 webapp_provider.setMonitoredDirName(jetty_home + "/webapps");
187 webapp_provider.setParentLoaderPriority(false);
188 webapp_provider.setExtractWars(true);
189 webapp_provider.setScanInterval(2);
190 webapp_provider.setDefaultsDescriptor(jetty_home
191 + "/etc/webdefault.xml");
192 deployer.addAppProvider(webapp_provider);
193
194 HashLoginService login = new HashLoginService();
195 login.setName("Test Realm");
196 login.setConfig(jetty_home + "/etc/realm.properties");
197 server.addBean(login);
198
199 NCSARequestLog requestLog = new AsyncNCSARequestLog();
200 requestLog.setFilename(jetty_home + "/logs/jetty-yyyy_mm_dd.log");
201 requestLog.setExtended(false);
202 requestLogHandler.setRequestLog(requestLog);
203
204 server.setStopAtShutdown(true);
205
206 server.start();
207 server.dumpStdErr();
208 server.join();
209 }
210 }