Search in sources :

Example 1 with WebDocumentConfiguration

use of cn.taketoday.web.framework.config.WebDocumentConfiguration in project today-framework by TAKETODAY.

the class TomcatServer method doPrepareContext.

protected void doPrepareContext(Host host) {
    try {
        // 
        ServletWebServerApplicationLoader starter = new ServletWebServerApplicationLoader(obtainApplicationContext(), this::getMergedInitializers);
        TomcatEmbeddedContext context = new TomcatEmbeddedContext(sessionIdGenerator);
        context.setFailCtxIfServletStartFails(true);
        context.setName(getContextPath());
        context.setDisplayName(getDisplayName());
        context.setPath(getContextPath());
        WebDocumentConfiguration webDocumentConfiguration = getWebDocumentConfiguration();
        if (webDocumentConfiguration != null) {
            Resource validDocBase = webDocumentConfiguration.getValidDocumentDirectory();
            if (validDocBase != null && validDocBase.exists() && validDocBase.isDirectory()) {
                context.setDocBase(validDocBase.getFile().getAbsolutePath());
            }
        }
        context.addLifecycleListener(new FixContextListener());
        context.setParentClassLoader(ClassUtils.getDefaultClassLoader());
        resetDefaultLocaleMapping(context);
        addLocaleMappings(context);
        context.setUseRelativeRedirects(useRelativeRedirects);
        WebappLoader loader = new WebappLoader();
        loader.setLoaderClass(WebappClassLoader.class.getName());
        loader.setDelegate(true);
        context.setLoader(loader);
        configureJasperInitializer(context);
        host.addChild(context);
        context.addServletContainerInitializer(starter, Collections.emptySet());
        configureTomcatContext(context);
    } catch (IOException e) {
        throw new ConfigurationException(e);
    }
}
Also used : WebappClassLoader(org.apache.catalina.loader.WebappClassLoader) ConfigurationException(cn.taketoday.core.ConfigurationException) WebDocumentConfiguration(cn.taketoday.web.framework.config.WebDocumentConfiguration) Resource(cn.taketoday.core.io.Resource) IOException(java.io.IOException) WebappLoader(org.apache.catalina.loader.WebappLoader) FixContextListener(org.apache.catalina.startup.Tomcat.FixContextListener)

Aggregations

ConfigurationException (cn.taketoday.core.ConfigurationException)1 Resource (cn.taketoday.core.io.Resource)1 WebDocumentConfiguration (cn.taketoday.web.framework.config.WebDocumentConfiguration)1 IOException (java.io.IOException)1 WebappClassLoader (org.apache.catalina.loader.WebappClassLoader)1 WebappLoader (org.apache.catalina.loader.WebappLoader)1 FixContextListener (org.apache.catalina.startup.Tomcat.FixContextListener)1