use of org.apache.catalina.loader.WebappLoader in project uavstack by uavorg.
the class SpringBootTomcatPlusIT method onDeployUAVApp.
public void onDeployUAVApp(Object... args) {
if (UAVServer.ServerVendor.SPRINGBOOT != UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR)) {
return;
}
Tomcat tomcat = (Tomcat) args[0];
String mofRoot = (String) args[1];
// add uavApp
StandardContext context = new StandardContext();
context.setName("com.creditease.uav");
context.setPath("/com.creditease.uav");
context.setDocBase(mofRoot + "/com.creditease.uav");
context.addLifecycleListener(new Tomcat.FixContextListener());
tomcat.getHost().addChild(context);
// add default servlet
Wrapper servlet = context.createWrapper();
servlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
servlet.setName("default");
context.addChild(servlet);
servlet.setOverridable(true);
context.addServletMapping("/", "default");
// init webapp classloader
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.setDelegate(true);
// after tomcat8, skip jarscan
Object obj = ReflectionHelper.newInstance("org.apache.tomcat.util.scan.StandardJarScanner", Thread.currentThread().getContextClassLoader());
if (obj != null) {
ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllFiles", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanClassPath", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllDirectories", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
context.setJarScanner((JarScanner) obj);
}
}
use of org.apache.catalina.loader.WebappLoader in project Payara by payara.
the class DynamicWebServletRegistrationImpl method configureLoader.
/**
* Configure the class loader for the web module based on the
* settings in sun-web.xml's class-loader element (if any).
*/
Loader configureLoader(SunWebApp bean) {
org.glassfish.web.deployment.runtime.ClassLoader clBean = null;
WebappLoader loader = new V3WebappLoader(wmInfo.getAppClassLoader());
loader.setUseMyFaces(isUseMyFaces());
if (bean != null) {
clBean = ((SunWebAppImpl) bean).getClassLoader();
}
if (clBean != null) {
configureLoaderAttributes(loader, clBean);
configureLoaderProperties(loader, clBean);
} else {
loader.setDelegate(true);
}
// START S1AS 6178005
String stubPath = wmInfo.getStubPath();
if (stubPath != null && stubPath.length() > 0) {
if (stubPath.charAt(0) != '/') {
stubPath = "/" + stubPath;
}
loader.addRepository("file:" + stubPath + File.separator);
}
// END S1AS 6178005
// START PE 4985680
/**
* Adds the given package name to the list of packages that may
* always be overriden, regardless of whether they belong to a
* protected namespace
*/
String packagesName = System.getProperty("com.sun.enterprise.overrideablejavaxpackages");
if (packagesName != null) {
List<String> overridablePackages = StringUtils.parseStringList(packagesName, " ,");
for (String overridablePackage : overridablePackages) {
loader.addOverridablePackage(overridablePackage);
}
}
// END PE 4985680
setLoader(loader);
return loader;
}
use of org.apache.catalina.loader.WebappLoader in project ofbiz-framework by apache.
the class CatalinaContainer method prepareContext.
private StandardContext prepareContext(Host host, ContainerConfig.Configuration configuration, ComponentConfig.WebappInfo appInfo, Property clusterProp) throws ContainerException {
StandardContext context = new StandardContext();
Tomcat.initWebappDefaults(context);
String location = getWebappRootLocation(appInfo);
boolean contextIsDistributable = isContextDistributable(configuration, location);
context.setParent(host);
context.setDocBase(location);
context.setPath(getWebappMountPoint(appInfo));
context.addLifecycleListener(new ContextConfig());
context.setJ2EEApplication("OFBiz");
context.setJ2EEServer("OFBiz Container");
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.setDisplayName(appInfo.name);
context.setDocBase(location);
context.setReloadable(ContainerConfig.getPropertyValue(configuration, "apps-context-reloadable", false));
context.setDistributable(contextIsDistributable);
context.setCrossContext(ContainerConfig.getPropertyValue(configuration, "apps-cross-context", true));
context.setPrivileged(appInfo.privileged);
context.getServletContext().setAttribute("_serverId", appInfo.server);
context.getServletContext().setAttribute("componentName", appInfo.componentConfig.getComponentName());
if (clusterProp != null && contextIsDistributable) {
context.setManager(prepareClusterManager(clusterProp));
}
StandardRoot resources = new StandardRoot(context);
resources.setAllowLinking(true);
context.setResources(resources);
JarScanner jarScanner = context.getJarScanner();
if (jarScanner instanceof StandardJarScanner) {
StandardJarScanner standardJarScanner = (StandardJarScanner) jarScanner;
standardJarScanner.setJarScanFilter(new FilterJars());
standardJarScanner.setScanClassPath(true);
}
Map<String, String> initParameters = appInfo.getInitParameters();
// request dumper filter
if ("true".equals(initParameters.get("enableRequestDump"))) {
FilterDef requestDumperFilterDef = new FilterDef();
requestDumperFilterDef.setFilterClass(RequestDumperFilter.class.getName());
requestDumperFilterDef.setFilterName("RequestDumper");
context.addFilterDef(requestDumperFilterDef);
FilterMap requestDumperFilterMap = new FilterMap();
requestDumperFilterMap.setFilterName("RequestDumper");
requestDumperFilterMap.addURLPattern("*");
context.addFilterMap(requestDumperFilterMap);
}
// set the init parameters
initParameters.entrySet().forEach(entry -> context.addParameter(entry.getKey(), entry.getValue()));
return context;
}
use of org.apache.catalina.loader.WebappLoader in project tomcat70 by apache.
the class MBeanFactory method createWebappLoader.
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent) throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getObjectName
// ObjectName oname = loader.getObjectName();
ObjectName oname = MBeanUtils.createObjectName(pname.getDomain(), loader);
return (oname.toString());
}
use of org.apache.catalina.loader.WebappLoader in project spring-boot by spring-projects.
the class TomcatServletWebServerFactory method prepareContext.
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
File documentRoot = getValidDocumentRoot();
TomcatEmbeddedContext context = new TomcatEmbeddedContext();
if (documentRoot != null) {
context.setResources(new LoaderHidingResourceRoot(context));
}
context.setName(getContextPath());
context.setDisplayName(getDisplayName());
context.setPath(getContextPath());
File docBase = (documentRoot != null) ? documentRoot : createTempDir("tomcat-docbase");
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader((this.resourceLoader != null) ? this.resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader());
resetDefaultLocaleMapping(context);
addLocaleMappings(context);
try {
context.setCreateUploadTargets(true);
} catch (NoSuchMethodError ex) {
// Tomcat is < 8.5.39. Continue.
}
configureTldPatterns(context);
WebappLoader loader = new WebappLoader();
loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
loader.setDelegate(true);
context.setLoader(loader);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
addJasperInitializer(context);
}
context.addLifecycleListener(new StaticResourceConfigurer(context));
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
host.addChild(context);
configureContext(context, initializersToUse);
postProcessContext(context);
}
Aggregations