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());
}
}
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);
}
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);
}
}
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);
}
};
}
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);
}
}
};
}
Aggregations