Search in sources :

Example 16 with Manager

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

the class StandardContext method setManager.

@Override
public void setManager(Manager manager) {
    Lock writeLock = managerLock.writeLock();
    writeLock.lock();
    Manager oldManager = null;
    try {
        // Change components if necessary
        oldManager = this.manager;
        if (oldManager == manager) {
            return;
        }
        this.manager = manager;
        // Stop the old component if necessary
        if (oldManager instanceof Lifecycle) {
            try {
                ((Lifecycle) oldManager).stop();
                ((Lifecycle) oldManager).destroy();
            } catch (LifecycleException e) {
                log.error(sm.getString("standardContext.setManager.stop"), e);
            }
        }
        // Start the new component if necessary
        if (manager != null) {
            manager.setContext(this);
        }
        if (getState().isAvailable() && manager instanceof Lifecycle) {
            try {
                ((Lifecycle) manager).start();
            } catch (LifecycleException e) {
                log.error(sm.getString("standardContext.setManager.start"), e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("manager", oldManager, manager);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 17 with Manager

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

the class StandardContext method destroyInternal.

/**
 * Destroy needs to clean up the context completely.
 *
 * The problem is that undoing all the config in start() and restoring
 * a 'fresh' state is impossible. After stop()/destroy()/init()/start()
 * we should have the same state as if a fresh start was done - i.e
 * read modified web.xml, etc. This can only be done by completely
 * removing the context object and remapping a new one, or by cleaning
 * up everything.
 */
@Override
protected void destroyInternal() throws LifecycleException {
    // have been set so the notification can't be created
    if (getObjectName() != null) {
        // Send j2ee.object.deleted notification
        Notification notification = new Notification("j2ee.object.deleted", this.getObjectName(), sequenceNumber.getAndIncrement());
        broadcaster.sendNotification(notification);
    }
    if (namingResources != null) {
        namingResources.destroy();
    }
    Loader loader = getLoader();
    if (loader instanceof Lifecycle) {
        ((Lifecycle) loader).destroy();
    }
    Manager manager = getManager();
    if (manager instanceof Lifecycle) {
        ((Lifecycle) manager).destroy();
    }
    if (resources != null) {
        resources.destroy();
    }
    super.destroyInternal();
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) Notification(javax.management.Notification)

Example 18 with Manager

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

the class StandardContext method backgroundProcess.

@Override
public void backgroundProcess() {
    if (!getState().isAvailable()) {
        return;
    }
    Loader loader = getLoader();
    if (loader != null) {
        try {
            loader.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.loader", loader), e);
        }
    }
    Manager manager = getManager();
    if (manager != null) {
        try {
            manager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.manager", manager), e);
        }
    }
    WebResourceRoot resources = getResources();
    if (resources != null) {
        try {
            resources.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.resources", resources), e);
        }
    }
    InstanceManager instanceManager = getInstanceManager();
    if (instanceManager != null) {
        try {
            instanceManager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.instanceManager", resources), e);
        }
    }
    super.backgroundProcess();
}
Also used : InstanceManager(org.apache.tomcat.InstanceManager) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) ServletException(jakarta.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) ListenerNotFoundException(javax.management.ListenerNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) MalformedURLException(java.net.MalformedURLException) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 19 with Manager

use of org.apache.catalina.Manager in project tomcat 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 = manager.getContext();
    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 20 with Manager

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

the class PersistentValve method invoke.

/**
 * Select the appropriate child Context to process this request,
 * based on the specified request URI.  If no matching Context can
 * be found, return an appropriate HTTP error.
 *
 * @param request Request to be processed
 * @param response Response to be produced
 *
 * @exception IOException if an input/output error occurred
 * @exception ServletException if a servlet error occurred
 */
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
    // request without session
    if (isRequestWithoutSession(request.getDecodedRequestURI())) {
        getNext().invoke(request, response);
        return;
    }
    // Select the Context to be used for this Request
    Context context = request.getContext();
    if (context == null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext"));
        return;
    }
    // Update the session last access time for our session (if any)
    String sessionId = request.getRequestedSessionId();
    Manager manager = context.getManager();
    if (sessionId != null && manager instanceof StoreManager) {
        Store store = ((StoreManager) manager).getStore();
        if (store != null) {
            Session session = null;
            try {
                session = store.load(sessionId);
            } catch (Exception e) {
                container.getLogger().error("deserializeError");
            }
            if (session != null) {
                if (!session.isValid() || isSessionStale(session, System.currentTimeMillis())) {
                    if (container.getLogger().isDebugEnabled()) {
                        container.getLogger().debug("session swapped in is invalid or expired");
                    }
                    session.expire();
                    store.remove(sessionId);
                } else {
                    session.setManager(manager);
                    // session.setId(sessionId); Only if new ???
                    manager.add(session);
                    // ((StandardSession)session).activate();
                    session.access();
                    session.endAccess();
                }
            }
        }
    }
    if (container.getLogger().isDebugEnabled()) {
        container.getLogger().debug("sessionId: " + sessionId);
    }
    // Ask the next valve to process the request.
    getNext().invoke(request, response);
    // If still processing async, don't try to store the session
    if (!request.isAsync()) {
        // Read the sessionid after the response.
        // HttpSession hsess = hreq.getSession(false);
        Session hsess;
        try {
            hsess = request.getSessionInternal(false);
        } catch (Exception ex) {
            hsess = null;
        }
        String newsessionId = null;
        if (hsess != null) {
            newsessionId = hsess.getIdInternal();
        }
        if (container.getLogger().isDebugEnabled()) {
            container.getLogger().debug("newsessionId: " + newsessionId);
        }
        if (newsessionId != null) {
            try {
                bind(context);
                /* store the session and remove it from the manager */
                if (manager instanceof StoreManager) {
                    Session session = manager.findSession(newsessionId);
                    Store store = ((StoreManager) manager).getStore();
                    boolean stored = false;
                    if (session != null) {
                        synchronized (session) {
                            if (store != null && session.isValid() && !isSessionStale(session, System.currentTimeMillis())) {
                                store.save(session);
                                ((StoreManager) manager).removeSuper(session);
                                session.recycle();
                                stored = true;
                            }
                        }
                    }
                    if (!stored) {
                        if (container.getLogger().isDebugEnabled()) {
                            container.getLogger().debug("newsessionId store: " + store + " session: " + session + " valid: " + (session == null ? "N/A" : Boolean.toString(session.isValid())) + " stale: " + isSessionStale(session, System.currentTimeMillis()));
                        }
                    }
                } else {
                    if (container.getLogger().isDebugEnabled()) {
                        container.getLogger().debug("newsessionId Manager: " + manager);
                    }
                }
            } finally {
                unbind(context);
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) Store(org.apache.catalina.Store) StoreManager(org.apache.catalina.StoreManager) Manager(org.apache.catalina.Manager) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) StoreManager(org.apache.catalina.StoreManager) Session(org.apache.catalina.Session)

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