Search in sources :

Example 61 with Container

use of org.apache.catalina.Container in project tomee by apache.

the class OpenEJBContextConfig method webConfig.

@Override
protected void webConfig() {
    TomcatHelper.configureJarScanner(context);
    // read the real config
    super.webConfig();
    if (IgnoredStandardContext.class.isInstance(context)) {
        // no need of jsf
        return;
    }
    if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) {
        final FilterDef asyncOwbFilter = new FilterDef();
        asyncOwbFilter.setAsyncSupported("true");
        asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped in async tasks");
        asyncOwbFilter.setDisplayName("OpenEJB CDI");
        asyncOwbFilter.setFilterClass(EEFilter.class.getName());
        asyncOwbFilter.setFilterName(EEFilter.class.getName());
        context.addFilterDef(asyncOwbFilter);
        final FilterMap asyncOwbMapping = new FilterMap();
        asyncOwbMapping.setFilterName(asyncOwbFilter.getFilterName());
        asyncOwbMapping.addURLPattern("/*");
        context.addFilterMap(asyncOwbMapping);
    }
    if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jsp-development", "false"))) {
        for (final Container c : context.findChildren()) {
            if (Wrapper.class.isInstance(c)) {
                final Wrapper servlet = Wrapper.class.cast(c);
                if ("org.apache.jasper.servlet.JspServlet".equals(servlet.getServletClass())) {
                    servlet.addInitParameter("development", "true");
                }
            }
        }
    }
    final ClassLoader classLoader = context.getLoader().getClassLoader();
    // add myfaces auto-initializer if mojarra is not present
    try {
        classLoader.loadClass("com.sun.faces.context.SessionMap");
        return;
    } catch (final Throwable ignored) {
    // no-op
    }
    try {
        final Class<?> myfacesInitializer = Class.forName(MYFACES_TOMEEM_CONTAINER_INITIALIZER, true, classLoader);
        final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance();
        context.addServletContainerInitializer(instance, getJsfClasses(context));
        // cleanup listener
        context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER);
    } catch (final Exception | NoClassDefFoundError ignored) {
    // no-op
    }
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Container(org.apache.catalina.Container) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) EEFilter(org.apache.openejb.server.httpd.EEFilter) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Example 62 with Container

use of org.apache.catalina.Container in project tomee by apache.

the class TomcatLoader method processRunningApplications.

/**
 * Process running web applications for ejb deployments.
 *
 * @param tomcatWebAppBuilder tomcat web app builder instance
 * @param standardServer      tomcat server instance
 */
private void processRunningApplications(final TomcatWebAppBuilder tomcatWebAppBuilder, final StandardServer standardServer) {
    for (final org.apache.catalina.Service service : standardServer.findServices()) {
        if (service.getContainer() instanceof Engine) {
            final Engine engine = (Engine) service.getContainer();
            for (final Container engineChild : engine.findChildren()) {
                if (engineChild instanceof Host) {
                    final Host host = (Host) engineChild;
                    for (final Container hostChild : host.findChildren()) {
                        if (hostChild instanceof StandardContext) {
                            final StandardContext standardContext = (StandardContext) hostChild;
                            final int state = TomcatHelper.getContextState(standardContext);
                            if (state == 0) {
                                // context only initialized
                                tomcatWebAppBuilder.init(standardContext);
                            } else if (state == 1) {
                                // context already started
                                standardContext.addParameter("openejb.start.late", "true");
                                final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
                                Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader());
                                try {
                                    tomcatWebAppBuilder.init(standardContext);
                                    tomcatWebAppBuilder.beforeStart(standardContext);
                                    tomcatWebAppBuilder.start(standardContext);
                                    tomcatWebAppBuilder.afterStart(standardContext);
                                } finally {
                                    Thread.currentThread().setContextClassLoader(oldCL);
                                }
                                standardContext.removeParameter("openejb.start.late");
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardContext(org.apache.catalina.core.StandardContext) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine)

Example 63 with Container

use of org.apache.catalina.Container in project tomee by apache.

the class GlobalListenerSupport method serviceRemoved.

/**
 * Service removed.
 *
 * @param service tomcat service
 */
private void serviceRemoved(final Service service) {
    final Container container = service.getContainer();
    if (container instanceof StandardEngine) {
        final StandardEngine engine = (StandardEngine) container;
        engineRemoved(engine);
    }
}
Also used : Container(org.apache.catalina.Container) StandardEngine(org.apache.catalina.core.StandardEngine)

Example 64 with Container

use of org.apache.catalina.Container in project tomee by apache.

the class GlobalListenerSupport method hostRemoved.

/**
 * Host is removed.
 *
 * @param host tomcat host
 */
private void hostRemoved(final StandardHost host) {
    for (final Container child : host.findChildren()) {
        if (child instanceof StandardContext) {
            final StandardContext context = (StandardContext) child;
            contextRemoved(context);
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardContext(org.apache.catalina.core.StandardContext)

Example 65 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class WebContainer method loadWebModule.

/**
 * Creates and configures a web module for each virtual server
 * that the web module is hosted under.
 * <p/>
 * If no virtual servers have been specified, then the web module will
 * not be loaded.
 * @param wmInfo
 * @param j2eeApplication
 * @param deploymentProperties
 * @return
 */
public List<Result<WebModule>> loadWebModule(WebModuleConfig wmInfo, String j2eeApplication, Properties deploymentProperties) {
    List<Result<WebModule>> results = new ArrayList<Result<WebModule>>();
    String vsIDs = wmInfo.getVirtualServers();
    List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
    if (vsList == null || vsList.isEmpty()) {
        if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO, LogFacade.WEB_MODULE_NOT_LOADED_NO_VIRTUAL_SERVERS, wmInfo.getName());
        }
        return results;
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, LogFacade.LOADING_WEB_MODULE, vsIDs);
    }
    List<String> nonProcessedVSList = new ArrayList<String>(vsList);
    Container[] vsArray = getEngine().findChildren();
    List<VirtualServer> vsToDeploy = new ArrayList<>(vsArray.length);
    for (Container aVsArray : vsArray) {
        if (aVsArray instanceof VirtualServer) {
            VirtualServer vs = (VirtualServer) aVsArray;
            boolean eqVS = vsList.contains(vs.getID());
            if (eqVS) {
                nonProcessedVSList.remove(vs.getID());
            }
            Set<String> matchedAliases = matchAlias(vsList, vs);
            final boolean hasMatchedAlias = (matchedAliases.size() > 0);
            if (hasMatchedAlias) {
                nonProcessedVSList.removeAll(matchedAliases);
            }
            if (eqVS || hasMatchedAlias) {
                vsToDeploy.add(vs);
            }
        }
    }
    final boolean moreThanOneVS = vsToDeploy.size() > 1;
    for (VirtualServer vs : vsToDeploy) {
        WebModule ctx = null;
        ClassLoader appClassLoader = wmInfo.getAppClassLoader();
        try {
            if (moreThanOneVS) {
                WebappClassLoader virtualServerClassLoader = new WebappClassLoader(appClassLoader, wmInfo.getDeploymentContext().getModuleMetaData(Application.class));
                virtualServerClassLoader.start();
                // for every virtual server, JSF and other extensions expect a separata class loader
                wmInfo.setAppClassLoader(virtualServerClassLoader);
            }
            ctx = loadWebModule(vs, wmInfo, j2eeApplication, deploymentProperties);
            results.add(new Result<>(ctx));
        } catch (Throwable t) {
            if (ctx != null) {
                ctx.setAvailable(false);
            }
            results.add(new Result<>(t));
        } finally {
            if (moreThanOneVS) {
                wmInfo.setAppClassLoader(appClassLoader);
            }
        }
    }
    if (nonProcessedVSList.size() > 0) {
        StringBuilder sb = new StringBuilder();
        boolean follow = false;
        for (String alias : nonProcessedVSList) {
            if (follow) {
                sb.append(",");
            }
            sb.append(alias);
            follow = true;
        }
        Object[] params = { wmInfo.getName(), sb.toString() };
        logger.log(Level.SEVERE, LogFacade.WEB_MODULE_NOT_LOADED_TO_VS, params);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Result(com.sun.enterprise.util.Result) Container(org.apache.catalina.Container) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Application(com.sun.enterprise.deployment.Application)

Aggregations

Container (org.apache.catalina.Container)163 Context (org.apache.catalina.Context)28 IOException (java.io.IOException)24 Host (org.apache.catalina.Host)22 StandardContext (org.apache.catalina.core.StandardContext)21 Engine (org.apache.catalina.Engine)18 LifecycleException (org.apache.catalina.LifecycleException)17 File (java.io.File)15 ObjectName (javax.management.ObjectName)15 Wrapper (org.apache.catalina.Wrapper)13 StandardHost (org.apache.catalina.core.StandardHost)13 ArrayList (java.util.ArrayList)12 ServletException (javax.servlet.ServletException)11 MalformedURLException (java.net.MalformedURLException)10 Valve (org.apache.catalina.Valve)10 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 NamingException (javax.naming.NamingException)9 Lifecycle (org.apache.catalina.Lifecycle)9 Realm (org.apache.catalina.Realm)9