connector.setPort(port);
connector.setResolveNames(false);
server.addConnector(connector);
// create a list of handlers
HandlerList list = new HandlerList();
server.addHandler(list);
if (debug) {
LOG.info("* Added debug handler.");
list.addHandler(new LogDebugHandler());
}
if (delay) {
LOG.info("* Added delay handler: " + (delayVal < 0 ? "random delay up to " + (-delayVal) : "constant delay of " + delayVal));
list.addHandler(new DelayHandler(delayVal));
}
// XXX alternatively, we can add the DispatchHandler as the first one,
// XXX to activate handler plugins and redirect requests to appropriate
// XXX handlers ... Here we always load these handlers
Iterator<Path> it = segs.iterator();
while (it.hasNext()) {
Path p = it.next();
try {
SegmentHandler segment = new SegmentHandler(conf, p);
list.addHandler(segment);
LOG.info("* Added segment handler for: " + p);
} catch (Exception e) {
LOG.warn("Skipping segment '" + p + "': " + StringUtils.stringifyException(e));
}
}
if (forward) {
LOG.info("* Adding forwarding proxy for all unknown urls ...");
ServletHandler servlets = new ServletHandler();
servlets.addServletWithMapping(AsyncProxyServlet.class, "/*");
servlets.addFilterWithMapping(LogDebugHandler.class, "/*", Handler.ALL);
list.addHandler(servlets);
}
if (fake) {
LOG.info("* Added fake handler for remaining URLs.");
list.addHandler(new FakeHandler());
}
list.addHandler(new NotFoundHandler());
// Start the http server
server.start();
server.join();
}