Search in sources :

Example 1 with WebappLoader

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);
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 2 with WebappLoader

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;
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 3 with WebappLoader

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;
}
Also used : FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) RequestDumperFilter(org.apache.catalina.filters.RequestDumperFilter) StandardRoot(org.apache.catalina.webresources.StandardRoot) JarScanner(org.apache.tomcat.JarScanner) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) ContextConfig(org.apache.catalina.startup.ContextConfig) StandardContext(org.apache.catalina.core.StandardContext) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 4 with WebappLoader

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());
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) WebappLoader(org.apache.catalina.loader.WebappLoader) ObjectName(javax.management.ObjectName)

Example 5 with WebappLoader

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);
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader) File(java.io.File) FixContextListener(org.apache.catalina.startup.Tomcat.FixContextListener) ServletContextInitializer(org.springframework.boot.web.servlet.ServletContextInitializer)

Aggregations

WebappLoader (org.apache.catalina.loader.WebappLoader)13 File (java.io.File)4 Container (org.apache.catalina.Container)4 LifecycleException (org.apache.catalina.LifecycleException)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 Notification (javax.management.Notification)3 NamingException (javax.naming.NamingException)3 Lifecycle (org.apache.catalina.Lifecycle)3 Loader (org.apache.catalina.Loader)3 StandardContext (org.apache.catalina.core.StandardContext)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ListenerNotFoundException (javax.management.ListenerNotFoundException)2 ObjectName (javax.management.ObjectName)2