String websiteclass = config.getInitParameter("MainClass");
if (websiteclass == null) {
websiteclass = "Main";
}
final Object o = Dispatcher.class.getClassLoader().loadClass(websiteclass).newInstance();
WebSite website;
if (o instanceof WebApp) {
website = new WebSite() {
@Override
public void init() {
add((WebApp) o);
}
};
} else if (o instanceof WebSite) {
website = (WebSite) o;
} else {
throw new ServletException("JWIG main class does not extend dk.brics.jwig.WebSite or dk.brics.jwig.WebApp");
}
// set thread context, log4j properties, and Hibernate properties
ThreadContext.setWebSite(website);
String base_url = Config.get("jwig.base_url", (String) null);
String base_url_secure = Config.get("jwig.base_url_secure", (String) null);
boolean hibernate = Config.get("jwig.hibernate", false);
Properties properties = new Properties();
properties.putAll(website.getProperties());
if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
PropertyConfigurator.configure(properties);
}
log = Logger.getLogger(Dispatcher.class);
log.info("Initializing {"
+ "MainClass=" + websiteclass
+ ", jwig.hibernate=" + hibernate
+ (base_url != null ? ", jwig.base_url=" + base_url : "")
+ (base_url_secure != null ? ", jwig.base_url_secure=" + base_url_secure : "")
+ "}");
website.getQuerier().preInit(properties);
website.init();
if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
//Make absolutely sure that at least some logging can happen
BasicConfigurator.configure();
log.warn("Log4J logging not configured by the application. Initializing Log4J with a default setup.");
}
website.getQuerier().postInit();
List<RequestManager> requestmanagers = new ArrayList<RequestManager>();
ThreadContext.init(base_url, base_url_secure, website.getCache(), requestmanagers, new SessionManager(config.getServletContext()),
new DependencyMap(), config.getServletContext().getRealPath("/"), this);
// register request manager for each web app
for (WebApp app : website.getWebApps()) {
requestmanagers.add(new RequestManager(app));
addListener(app.getSecurityManager());
}
int fileupload_memory_threshold = Config.get("jwig.fileupload_memory_threshold", 100000);
String fileupload_tmpdir = Config.get("jwig.fileupload_tmpdir", System.getProperty("java.io.tmpdir"));
long multipart_maxsize = Config.get("jwig.multipart_maxsize", 100000000L);
long fileupload_maxsize = Config.get("jwig.fileupload_maxsize", -1L);
File repository = new File(fileupload_tmpdir);
if (!repository.isAbsolute()) {
repository = new File(ThreadContext.getServletHome(), fileupload_tmpdir);
}
fileupload = new ServletFileUpload(new DiskFileItemFactory(fileupload_memory_threshold, repository));
fileupload.setSizeMax(multipart_maxsize);
fileupload.setFileSizeMax(fileupload_maxsize);
log.debug("Initializing {jwig.fileupload_memory_threshold=" + fileupload_memory_threshold +
", jwig.fileupload_tmpdir=" + fileupload_tmpdir +
", jwig.multipart_maxsize=" + multipart_maxsize +
", jwig.fileupload_maxsize=" + fileupload_maxsize +
"}");
website.postInit();
} catch (Exception e) {
if (log != null) {
log.fatal("Exception in init", e);
} else {
e.printStackTrace();