public SeleniumServer(int port, boolean slowResources) throws Exception {
this(port, slowResources, false);
}
private void assembleHandlers(boolean slowResources) {
HttpContext root = new HttpContext();
root.setContextPath("/");
ProxyHandler proxyHandler;
if (customProxyHandler == null) {
proxyHandler = new ProxyHandler(trustAllSSLCertificates);
root.addHandler(proxyHandler);
} else {
proxyHandler = customProxyHandler;
root.addHandler(proxyHandler);
}
// pre-compute the 1-16 SSL relays+certs for the logging hosts (see selenium-remoterunner.js sendToRCAndForget for more info)
if (browserSideLogEnabled) {
proxyHandler.generateSSLCertsForLoggingHosts(server);
}
server.addContext(root);
HttpContext context = new HttpContext();
context.setContextPath("/selenium-server");
context.setMimeMapping("xhtml", "application/xhtml+xml");
SecurityConstraint constraint = new SecurityConstraint();
constraint.setName(SecurityConstraint.__BASIC_AUTH);;
constraint.addRole("user");
constraint.setAuthenticate(true);
context.addSecurityConstraint("/tests/html/basicAuth/*", constraint);
HashUserRealm realm = new HashUserRealm("MyRealm");
realm.put("alice", "foo");
realm.addUserToRole("alice", "user");
context.setRealm(realm);
SecurityHandler sh = new SecurityHandler();
context.addHandler(sh);
StaticContentHandler.setSlowResources(slowResources);
staticContentHandler = new StaticContentHandler();
String overrideJavascriptDir = System.getProperty("selenium.javascript.dir");
if (overrideJavascriptDir != null) {
staticContentHandler.addStaticContent(new FsResourceLocator(new File(overrideJavascriptDir)));
}
staticContentHandler.addStaticContent(new ClasspathResourceLocator());
context.addHandler(staticContentHandler);
context.addHandler(new SingleTestSuiteResourceHandler());
postResultsHandler = new SeleniumHTMLRunnerResultsHandler();
context.addHandler(postResultsHandler);
CachedContentTestHandler cachedContentTestHandler = new CachedContentTestHandler();
context.addHandler(cachedContentTestHandler);
// Associate the SeleniumDriverResourceHandler with the /selenium-server/driver context
HttpContext driverContext = new HttpContext();
driverContext.setContextPath("/selenium-server/driver");
driver = new SeleniumDriverResourceHandler(this);
context.addHandler(driver);
server.addContext(context);
server.addContext(driverContext);