Search in sources :

Example 6 with Manager

use of org.apache.catalina.Manager in project tomcat70 by apache.

the class SingleSignOnListener method sessionEvent.

@Override
public void sessionEvent(SessionEvent event) {
    if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) {
        return;
    }
    Session session = event.getSession();
    Manager manager = session.getManager();
    if (manager == null) {
        return;
    }
    Context context = (Context) manager.getContainer();
    Authenticator authenticator = context.getAuthenticator();
    if (!(authenticator instanceof AuthenticatorBase)) {
        return;
    }
    SingleSignOn sso = ((AuthenticatorBase) authenticator).sso;
    if (sso == null) {
        return;
    }
    sso.sessionDestroyed(ssoId, session);
}
Also used : Context(org.apache.catalina.Context) Manager(org.apache.catalina.Manager) Authenticator(org.apache.catalina.Authenticator) Session(org.apache.catalina.Session)

Example 7 with Manager

use of org.apache.catalina.Manager in project tomcat70 by apache.

the class ContainerBase method backgroundProcess.

/**
 * Execute a periodic task, such as reloading, etc. This method will be
 * invoked inside the classloading context of this container. Unexpected
 * throwables will be caught and logged.
 */
@Override
public void backgroundProcess() {
    if (!getState().isAvailable())
        return;
    Cluster cluster = getClusterInternal();
    if (cluster != null) {
        try {
            cluster.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);
        }
    }
    Loader loader = getLoaderInternal();
    if (loader != null) {
        try {
            loader.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.loader", loader), e);
        }
    }
    Manager manager = getManagerInternal();
    if (manager != null) {
        try {
            manager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.manager", manager), e);
        }
    }
    Realm realm = getRealmInternal();
    if (realm != null) {
        try {
            realm.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.realm", realm), e);
        }
    }
    Valve current = pipeline.getFirst();
    while (current != null) {
        try {
            current.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.valve", current), e);
        }
        current = current.getNext();
    }
    fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
}
Also used : Cluster(org.apache.catalina.Cluster) Loader(org.apache.catalina.Loader) Valve(org.apache.catalina.Valve) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) Realm(org.apache.catalina.Realm) ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException)

Example 8 with Manager

use of org.apache.catalina.Manager in project tomcat70 by apache.

the class ContainerBase method startInternal.

/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    // Start our subordinate components, if any
    Loader loader = getLoaderInternal();
    if ((loader != null) && (loader instanceof Lifecycle))
        ((Lifecycle) loader).start();
    logger = null;
    getLogger();
    Manager manager = getManagerInternal();
    if ((manager != null) && (manager instanceof Lifecycle))
        ((Lifecycle) manager).start();
    Cluster cluster = getClusterInternal();
    if ((cluster != null) && (cluster instanceof Lifecycle))
        ((Lifecycle) cluster).start();
    Realm realm = getRealmInternal();
    if ((realm != null) && (realm instanceof Lifecycle))
        ((Lifecycle) realm).start();
    DirContext resources = getResourcesInternal();
    if ((resources != null) && (resources instanceof Lifecycle))
        ((Lifecycle) resources).start();
    // Start our child containers, if any
    Container[] children = findChildren();
    List<Future<Void>> results = new ArrayList<Future<Void>>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StartChild(children[i])));
    }
    boolean fail = false;
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Exception e) {
            log.error(sm.getString("containerBase.threadedStartFailed"), e);
            fail = true;
        }
    }
    if (fail) {
        throw new LifecycleException(sm.getString("containerBase.threadedStartFailed"));
    }
    // Start the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle)
        ((Lifecycle) pipeline).start();
    setState(LifecycleState.STARTING);
    // Start our thread
    threadStart();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Loader(org.apache.catalina.Loader) Cluster(org.apache.catalina.Cluster) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) Container(org.apache.catalina.Container) Future(java.util.concurrent.Future) Realm(org.apache.catalina.Realm)

Example 9 with Manager

use of org.apache.catalina.Manager in project tomcat70 by apache.

the class ContainerBase method stopInternal.

/**
 * Stop this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {
    // Stop our thread
    threadStop();
    setState(LifecycleState.STOPPING);
    // Stop the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle && ((Lifecycle) pipeline).getState().isAvailable()) {
        ((Lifecycle) pipeline).stop();
    }
    // Stop our child containers, if any
    Container[] children = findChildren();
    List<Future<Void>> results = new ArrayList<Future<Void>>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StopChild(children[i])));
    }
    boolean fail = false;
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Exception e) {
            log.error(sm.getString("containerBase.threadedStopFailed"), e);
            fail = true;
        }
    }
    if (fail) {
        throw new LifecycleException(sm.getString("containerBase.threadedStopFailed"));
    }
    // Stop our subordinate components, if any
    DirContext resources = getResourcesInternal();
    if ((resources != null) && (resources instanceof Lifecycle)) {
        ((Lifecycle) resources).stop();
    }
    Realm realm = getRealmInternal();
    if ((realm != null) && (realm instanceof Lifecycle)) {
        ((Lifecycle) realm).stop();
    }
    Cluster cluster = getClusterInternal();
    if ((cluster != null) && (cluster instanceof Lifecycle)) {
        ((Lifecycle) cluster).stop();
    }
    Manager manager = getManagerInternal();
    if ((manager != null) && (manager instanceof Lifecycle) && ((Lifecycle) manager).getState().isAvailable()) {
        ((Lifecycle) manager).stop();
    }
    Loader loader = getLoaderInternal();
    if ((loader != null) && (loader instanceof Lifecycle)) {
        ((Lifecycle) loader).stop();
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Cluster(org.apache.catalina.Cluster) Loader(org.apache.catalina.Loader) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) Container(org.apache.catalina.Container) Future(java.util.concurrent.Future) Realm(org.apache.catalina.Realm)

Example 10 with Manager

use of org.apache.catalina.Manager in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method handleWebappDeployment.

/**
 * Deployment procedure of Jaggery apps
 *
 * @param webappFile                The Jaggery app file to be deployed
 * @param contextStr                jaggery app context string
 * @param webContextParams          context-params for this Jaggery app
 * @param applicationEventListeners Application event listeners
 * @throws CarbonException If a deployment error occurs
 */
protected void handleWebappDeployment(File webappFile, String contextStr, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
    String filename = webappFile.getName();
    ArrayList<Object> listeners = new ArrayList<Object>(1);
    // listeners.add(new CarbonServletRequestListener());
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.setName("ConfigDir");
    securityCollection.setDescription("Jaggery Configuration Dir");
    securityCollection.addPattern("/" + JaggeryCoreConstants.JAGGERY_CONF_FILE);
    securityConstraint.addCollection(securityCollection);
    WebApplicationsHolder webApplicationsHolder = WebAppUtils.getWebappHolder(webappFile.getAbsolutePath(), configurationContext);
    try {
        JSONObject jaggeryConfigObj = readJaggeryConfig(webappFile);
        Tomcat tomcat = DataHolder.getCarbonTomcatService().getTomcat();
        Context context = DataHolder.getCarbonTomcatService().addWebApp(contextStr, webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
        // deploying web app for url mapping inside virtual host
        if (DataHolder.getHotUpdateService() != null) {
            List<String> hostNames = DataHolder.getHotUpdateService().getMappigsPerWebapp(contextStr);
            for (String hostName : hostNames) {
                Host host = DataHolder.getHotUpdateService().addHost(hostName);
                /*                    ApplicationContext.getCurrentApplicationContext().putUrlMappingForApplication(hostName, contextStr);
  */
                Context contextForHost = DataHolder.getCarbonTomcatService().addWebApp(host, "/", webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
                log.info("Deployed JaggeryApp on host: " + contextForHost);
            }
        }
        Manager manager = context.getManager();
        if (isDistributable(context, jaggeryConfigObj)) {
            // Clusterable manager implementation as DeltaManager
            context.setDistributable(true);
            // Using clusterable manager
            CarbonTomcatClusterableSessionManager sessionManager;
            if (manager instanceof CarbonTomcatClusterableSessionManager) {
                sessionManager = (CarbonTomcatClusterableSessionManager) manager;
                sessionManager.setOwnerTenantId(tenantId);
            } else {
                sessionManager = new CarbonTomcatClusterableSessionManager(tenantId);
                context.setManager(sessionManager);
            }
            Object alreadyinsertedSMMap = configurationContext.getProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP);
            if (alreadyinsertedSMMap != null) {
                ((Map<String, CarbonTomcatClusterableSessionManager>) alreadyinsertedSMMap).put(context.getName(), sessionManager);
            } else {
                sessionManagerMap.put(context.getName(), sessionManager);
                configurationContext.setProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP, sessionManagerMap);
            }
        } else {
            if (manager instanceof CarbonTomcatSessionManager) {
                ((CarbonTomcatSessionManager) manager).setOwnerTenantId(tenantId);
            } else if (manager instanceof CarbonTomcatSessionPersistentManager) {
                ((CarbonTomcatSessionPersistentManager) manager).setOwnerTenantId(tenantId);
                log.debug(manager.getInfo() + " enabled Tomcat HTTP Session Persistent mode using " + ((CarbonTomcatSessionPersistentManager) manager).getStore().getInfo());
            } else {
                context.setManager(new CarbonTomcatSessionManager(tenantId));
            }
        }
        context.setReloadable(false);
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setServletContextParameters(webContextParams);
        webapp.setState("Started");
        webApplicationsHolder.getStartedWebapps().put(filename, webapp);
        webApplicationsHolder.getFaultyWebapps().remove(filename);
        registerApplicationEventListeners(applicationEventListeners, context);
        log.info("Deployed webapp: " + webapp);
    } catch (Throwable e) {
        // catching a Throwable here to avoid web-apps crashing the server during startup
        StandardContext context = new StandardContext();
        context.setName(webappFile.getName());
        context.addParameter(WebappsConstants.FAULTY_WEBAPP, "true");
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setProperty(WebappsConstants.WEBAPP_FILTER, JaggeryConstants.JAGGERY_WEBAPP_FILTER_PROP);
        String msg = "Error while deploying webapp: " + webapp;
        log.error(msg, e);
        webapp.setFaultReason(new Exception(msg, e));
        webApplicationsHolder.getFaultyWebapps().put(filename, webapp);
        webApplicationsHolder.getStartedWebapps().remove(filename);
        throw new CarbonException(msg, e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Tomcat(org.apache.catalina.startup.Tomcat) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) ArrayList(java.util.ArrayList) CarbonException(org.wso2.carbon.CarbonException) Host(org.apache.catalina.Host) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) Manager(org.apache.catalina.Manager) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) CarbonException(org.wso2.carbon.CarbonException) JSONObject(org.json.simple.JSONObject) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) StandardContext(org.apache.catalina.core.StandardContext) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Aggregations

Manager (org.apache.catalina.Manager)54 StringManager (org.apache.tomcat.util.res.StringManager)26 IOException (java.io.IOException)22 Session (org.apache.catalina.Session)22 Context (org.apache.catalina.Context)19 Container (org.apache.catalina.Container)13 LifecycleException (org.apache.catalina.LifecycleException)12 Lifecycle (org.apache.catalina.Lifecycle)11 Loader (org.apache.catalina.Loader)11 InstanceManager (org.apache.tomcat.InstanceManager)11 StandardManager (org.apache.catalina.session.StandardManager)10 Realm (org.apache.catalina.Realm)9 ServletException (javax.servlet.ServletException)7 ArrayList (java.util.ArrayList)6 NamingException (javax.naming.NamingException)6 Cluster (org.apache.catalina.Cluster)6 DistributedManager (org.apache.catalina.DistributedManager)6 StandardContext (org.apache.catalina.core.StandardContext)6 WebappLoader (org.apache.catalina.loader.WebappLoader)6 ServletException (jakarta.servlet.ServletException)5