Search in sources :

Example 11 with WebappLoader

use of org.apache.catalina.loader.WebappLoader in project pinpoint by pinpoint-apm.

the class WebappLoaderStartInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    // target should be an instance of WebappLoader.
    if (target instanceof WebappLoader) {
        WebappLoader webappLoader = (WebappLoader) target;
        try {
            String contextKey = extractContextKey(webappLoader);
            List<String> loadedJarNames = extractLibJars(webappLoader);
            dispatchLibJars(contextKey, loadedJarNames);
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.warn(e.getMessage(), e);
            }
        }
    } else {
        logger.warn("Webapp loader is not an instance of org.apache.catalina.loader.WebappLoader. Found [{}]", target.getClass().toString());
    }
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with WebappLoader

use of org.apache.catalina.loader.WebappLoader in project today-framework by TAKETODAY.

the class TomcatReactiveWebServerFactory method prepareContext.

protected void prepareContext(Host host, TomcatHttpHandlerAdapter servlet) {
    File docBase = createTempDir("tomcat-docbase");
    TomcatEmbeddedContext context = new TomcatEmbeddedContext();
    context.setPath("");
    context.setDocBase(docBase.getAbsolutePath());
    context.addLifecycleListener(new Tomcat.FixContextListener());
    context.setParentClassLoader(ClassUtils.getDefaultClassLoader());
    skipAllTldScanning(context);
    WebappLoader loader = new WebappLoader();
    loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
    loader.setDelegate(true);
    context.setLoader(loader);
    Tomcat.addServlet(context, "httpHandlerServlet", servlet).setAsyncSupported(true);
    context.addServletMappingDecoded("/", "httpHandlerServlet");
    host.addChild(context);
    configureContext(context);
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) WebappLoader(org.apache.catalina.loader.WebappLoader) File(java.io.File)

Example 13 with WebappLoader

use of org.apache.catalina.loader.WebappLoader 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)

Example 14 with WebappLoader

use of org.apache.catalina.loader.WebappLoader in project pkslow-samples by LarryDpk.

the class UaaServer method servletContainer.

@Bean
public ServletWebServerFactory servletContainer() throws IOException {
    final File tempDirectory = Files.createTempDirectory("uaa").toFile();
    final File tempUaaYmlFile = new File(tempDirectory, "uaa.yml");
    final File tempUaaWarFile = new File(tempDirectory, "uaa.war");
    FileCopyUtils.copy(new ClassPathResource("uaa-postgresql-ldap.yml").getInputStream(), new FileOutputStream(tempUaaYmlFile));
    FileCopyUtils.copy(new ClassPathResource("uaa.war").getInputStream(), new FileOutputStream(tempUaaWarFile));
    System.out.println("uaa.yml: " + tempUaaYmlFile.getAbsolutePath());
    System.out.println("uaa.war: " + tempUaaWarFile.getAbsolutePath());
    System.setProperty("UAA_CONFIG_FILE", tempUaaYmlFile.getAbsolutePath());
    return new TomcatServletWebServerFactory() {

        protected TomcatWebServer getTomcatWebServer(org.apache.catalina.startup.Tomcat tomcat) {
            final Server tomcatServer = tomcat.getServer();
            final File catalinaBase = new File(tempDirectory, "catalina");
            catalinaBase.mkdirs();
            tomcatServer.setCatalinaBase(catalinaBase);
            new File(tomcatServer.getCatalinaBase(), "webapps").mkdirs();
            try {
                Context context = tomcat.addWebapp("/uaa", tempUaaWarFile.toString());
                final ClassLoader properClassLoader = UaaServer.class.getClassLoader();
                WebappLoader loader = new WebappLoader(properClassLoader);
                context.setLoader(loader);
            } catch (Exception ex) {
                throw new IllegalStateException("Failed to add webapp", ex);
            }
            return super.getTomcatWebServer(tomcat);
        }
    };
}
Also used : Context(org.apache.catalina.Context) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) Server(org.apache.catalina.Server) ClassPathResource(org.springframework.core.io.ClassPathResource) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) WebappLoader(org.apache.catalina.loader.WebappLoader) File(java.io.File) Bean(org.springframework.context.annotation.Bean)

Example 15 with WebappLoader

use of org.apache.catalina.loader.WebappLoader in project pulsar-manager by apache.

the class EmbeddedTomcatCustomizer method servletContainer.

@Bean
public ServletWebServerFactory servletContainer() {
    log.info("Starting servletContainer");
    return new TomcatServletWebServerFactory() {

        @Override
        protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
            try {
                log.info("Catalina base is " + tomcat.getServer().getCatalinaBase().getAbsolutePath());
                File lib = new File("lib").getAbsoluteFile();
                if (lib.isDirectory()) {
                    File bkvmWar = searchWar(lib, "bkvm", ".war");
                    if (bkvmWar != null) {
                        File configFile = new File("bkvm.conf");
                        log.info("looking for BKVM configuration file at " + configFile.getAbsolutePath());
                        if (configFile.isFile()) {
                            Properties props = new Properties();
                            try (FileReader reader = new FileReader(configFile)) {
                                props.load(reader);
                            }
                            boolean bkvmEnabled = Boolean.parseBoolean(props.getProperty("bkvm.enabled", "false"));
                            log.info("Read bkvm.enabled = {}", bkvmEnabled);
                            if (bkvmEnabled) {
                                System.setProperty("bookkeeper.visual.manager.config.path", configFile.getAbsolutePath());
                                File file = new File(tomcat.getServer().getCatalinaBase(), "/webapps");
                                log.info("Tomcat Webapps directory is " + file.getAbsolutePath());
                                file.mkdirs();
                                File bkvmDirectory = new File(file, "bkvm");
                                log.info("Deploying BKVM to " + bkvmDirectory.getAbsolutePath());
                                unZip(bkvmWar, bkvmDirectory);
                                Context context = tomcat.addWebapp("/bkvm", bkvmDirectory.getAbsolutePath());
                                WebappLoader loader = new WebappLoader(Thread.currentThread().getContextClassLoader());
                                context.setLoader(loader);
                            }
                        }
                    }
                }
                return super.getTomcatWebServer(tomcat);
            } catch (IOException | ServletException ex) {
                throw new RuntimeException(ex);
            }
        }
    };
}
Also used : Context(org.apache.catalina.Context) ServletException(javax.servlet.ServletException) Tomcat(org.apache.catalina.startup.Tomcat) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) WebappLoader(org.apache.catalina.loader.WebappLoader) File(java.io.File) Bean(org.springframework.context.annotation.Bean)

Aggregations

WebappLoader (org.apache.catalina.loader.WebappLoader)21 File (java.io.File)9 IOException (java.io.IOException)6 StandardContext (org.apache.catalina.core.StandardContext)5 Tomcat (org.apache.catalina.startup.Tomcat)5 ServletException (javax.servlet.ServletException)4 Container (org.apache.catalina.Container)4 LifecycleException (org.apache.catalina.LifecycleException)4 MalformedURLException (java.net.MalformedURLException)3 Notification (javax.management.Notification)3 NamingException (javax.naming.NamingException)3 Context (org.apache.catalina.Context)3 Loader (org.apache.catalina.Loader)3 StandardRoot (org.apache.catalina.webresources.StandardRoot)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2