//contextHandler.setContextPath(contextPath);
contextHandler.setContextPath("/");
server.setHandler(contextHandler);
SessionHandler sessionHandler = new SessionHandler();
ServletHandler servletHandler = new ServletHandler();
sessionHandler.addHandler(servletHandler);
contextHandler.setHandler(sessionHandler);
server.setStopAtShutdown(true);
server.setSendServerVersion(sendServerVersion);
server.start();
// Keep track of the new server and Servlet handler
port = new Port(server, servletHandler);
ports.put(portNumber, port);
} catch (Exception e) {
throw new ServletMappingException(e);
}
}
// Register the Servlet mapping
ServletHandler servletHandler = port.getServletHandler();
ServletHolder holder;
if (servlet instanceof DefaultResourceServlet) {
// Optimize the handling of resource requests, use the Jetty default Servlet
// instead of our default resource Servlet
String servletPath = uri.getPath();
if (servletPath.endsWith("*")) {
servletPath = servletPath.substring(0, servletPath.length()-1);
}
if (servletPath.endsWith("/")) {
servletPath = servletPath.substring(0, servletPath.length()-1);
}
if (!servletPath.startsWith("/")) {
servletPath = '/' + servletPath;
}
DefaultResourceServlet resourceServlet = (DefaultResourceServlet)servlet;
DefaultServlet defaultServlet = new JettyDefaultServlet(servletPath, resourceServlet.getDocumentRoot());
holder = new ServletHolder(defaultServlet);
} else {
holder = new ServletHolder(servlet);
}
servletHandler.addServlet(holder);
ServletMapping mapping = new ServletMapping();
mapping.setServletName(holder.getName());
String path = uri.getPath();
if (!path.startsWith("/")) {
path = '/' + path;
}
if (!path.startsWith(contextPath)) {
path = contextPath + path;
}
mapping.setPathSpec(path);
servletHandler.addServletMapping(mapping);
// Compute the complete URL
String host;
try {
host = InetAddress.getLocalHost().getHostName();