}
/*
* Create the collection of webapp contexts
*/
ContextHandlerCollection contexts = new ContextHandlerCollection();
/*
* Loop through the webapps defined in the configuration
*/
for (Map<String,Object> webappConfig : (List<Map<String,Object>>) config.get("webapps")) {
try {
WebAppContext webAppContext = new WebAppContext();
webAppContext.setDisplayName((String) webappConfig.get("name"));
String base = (String) config.get("webappBase");
String contextPath = (String) webappConfig.get("contextPath");
if (contextPath == null) contextPath = "";
webAppContext.setContextPath("/" + contextPath);
String filePath = ((base != null) ? base : "") + webappConfig.get("filePath");
if (filePath.toLowerCase().endsWith(".war")) {
webAppContext.setWar(filePath);
} else {
webAppContext.setResourceBase(filePath);
}
/*
* Standard Jetty WebApp Configuration
*/
webAppContext.setConfigurationClasses(new String[] {
"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.MetaInfConfiguration",
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration"
});
/*
* Add the data sources
*/
if (webappConfig.get("dataSource") != null) createDataSource(webAppContext, (Map<String, String>) webappConfig.get("dataSource"));
if (webappConfig.get("dataSources") != null) {
for (Map<String,String> dataSourceConfig : (List<Map<String,String>>) webappConfig.get("dataSources")) {
createDataSource(webAppContext, dataSourceConfig);
}
}
/*
* Add the default jetty servlet
*/
ServletHolder defaultServlet = new ServletHolder(new DefaultServlet());
Map<String,String> params = new HashMap<String,String>();
params.put("dirAllowed", "false");
params.put("aliases", "true");
params.put("acceptRanges", "true");
params.put("welcomeServlets", "false");
params.put("redirectWelcome", "false");
params.put("maxCacheSize", "256000000");
params.put("maxCachedFileSize", "20000000");
params.put("maxCachedFiles", "2048");
params.put("gzip", "true");
params.put("useFileMappedBuffer", "true");
params.put("resourceCache", "resourceCache");
defaultServlet.setInitParameters(params);
//defaultServlet.setInitOrder(0);
webAppContext.addServlet(defaultServlet, "/");
contexts.addHandler(webAppContext);
} catch (Exception e) {
String msg = "Error Configuring Webapp:\n" + e.getClass().getSimpleName() + "\n" + Arrays.toString(e.getStackTrace()).replaceAll(",", "\n");
System.out.println(msg);
log.warn(msg);
}