Search in sources :

Example 51 with Manager

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

the class ReplicationValve method createPrimaryIndicator.

/**
 * Mark Request that processed at primary node with attribute
 * primaryIndicatorName
 *
 * @param request The Servlet request
 * @throws IOException IO error finding session
 */
protected void createPrimaryIndicator(Request request) throws IOException {
    String id = request.getRequestedSessionId();
    if ((id != null) && (id.length() > 0)) {
        Manager manager = request.getContext().getManager();
        Session session = manager.findSession(id);
        if (session instanceof ClusterSession) {
            ClusterSession cses = (ClusterSession) session;
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("ReplicationValve.session.indicator", request.getContext().getName(), id, primaryIndicatorName, Boolean.valueOf(cses.isPrimarySession())));
            }
            request.setAttribute(primaryIndicatorName, cses.isPrimarySession() ? Boolean.TRUE : Boolean.FALSE);
        } else {
            if (log.isDebugEnabled()) {
                if (session != null) {
                    log.debug(sm.getString("ReplicationValve.session.found", request.getContext().getName(), id));
                } else {
                    log.debug(sm.getString("ReplicationValve.session.invalid", request.getContext().getName(), id));
                }
            }
        }
    }
}
Also used : ClusterSession(org.apache.catalina.ha.ClusterSession) DeltaManager(org.apache.catalina.ha.session.DeltaManager) ClusterManager(org.apache.catalina.ha.ClusterManager) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ClusterSession(org.apache.catalina.ha.ClusterSession) Session(org.apache.catalina.Session) DeltaSession(org.apache.catalina.ha.session.DeltaSession)

Example 52 with Manager

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

the class HostConfig method checkUndeploy.

/**
 * Check for old versions of applications using parallel deployment that are
 * now unused (have no active sessions) and undeploy any that are found.
 */
public synchronized void checkUndeploy() {
    if (deployed.size() < 2) {
        return;
    }
    // Need ordered set of names
    SortedSet<String> sortedAppNames = new TreeSet<>(deployed.keySet());
    Iterator<String> iter = sortedAppNames.iterator();
    ContextName previous = new ContextName(iter.next(), false);
    do {
        ContextName current = new ContextName(iter.next(), false);
        if (current.getPath().equals(previous.getPath())) {
            // Current and previous are same path - current will always
            // be a later version
            Context previousContext = (Context) host.findChild(previous.getName());
            Context currentContext = (Context) host.findChild(current.getName());
            if (previousContext != null && currentContext != null && currentContext.getState().isAvailable() && tryAddServiced(previous.getName())) {
                try {
                    Manager manager = previousContext.getManager();
                    if (manager != null) {
                        int sessionCount;
                        if (manager instanceof DistributedManager) {
                            sessionCount = ((DistributedManager) manager).getActiveSessionsFull();
                        } else {
                            sessionCount = manager.getActiveSessions();
                        }
                        if (sessionCount == 0) {
                            if (log.isInfoEnabled()) {
                                log.info(sm.getString("hostConfig.undeployVersion", previous.getName()));
                            }
                            DeployedApplication app = deployed.get(previous.getName());
                            String[] resources = app.redeployResources.keySet().toArray(new String[0]);
                            // Version is unused - undeploy it completely
                            // The -1 is a 'trick' to ensure all redeploy
                            // resources are removed
                            undeploy(app);
                            deleteRedeployResources(app, resources, -1, true);
                        }
                    }
                } finally {
                    removeServiced(previous.getName());
                }
            }
        }
        previous = current;
    } while (iter.hasNext());
}
Also used : StandardContext(org.apache.catalina.core.StandardContext) Context(org.apache.catalina.Context) TreeSet(java.util.TreeSet) DistributedManager(org.apache.catalina.DistributedManager) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ContextName(org.apache.catalina.util.ContextName) DistributedManager(org.apache.catalina.DistributedManager)

Example 53 with Manager

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

the class ManagerSF method storeChildren.

@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aManager, StoreDescription parentDesc) throws Exception {
    if (aManager instanceof Manager) {
        Manager manager = (Manager) aManager;
        // Store nested <SessionIdGenerator> element;
        SessionIdGenerator sessionIdGenerator = manager.getSessionIdGenerator();
        if (sessionIdGenerator != null) {
            storeElement(aWriter, indent, sessionIdGenerator);
        }
    }
}
Also used : SessionIdGenerator(org.apache.catalina.SessionIdGenerator) StandardManager(org.apache.catalina.session.StandardManager) Manager(org.apache.catalina.Manager)

Example 54 with Manager

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

the class Request method isRequestedSessionIdValid.

/**
 * @return <code>true</code> if the session identifier included in this
 * request identifies a valid session.
 */
@Override
public boolean isRequestedSessionIdValid() {
    if (requestedSessionId == null) {
        return false;
    }
    Context context = getContext();
    if (context == null) {
        return false;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        return false;
    }
    Session session = null;
    try {
        session = manager.findSession(requestedSessionId);
    } catch (IOException e) {
    // Can't find the session
    }
    if ((session == null) || !session.isValid()) {
        // Check for parallel deployment contexts
        if (getMappingData().contexts == null) {
            return false;
        } else {
            for (int i = (getMappingData().contexts.length); i > 0; i--) {
                Context ctxt = getMappingData().contexts[i - 1];
                try {
                    if (ctxt.getManager().findSession(requestedSessionId) != null) {
                        return true;
                    }
                } catch (IOException e) {
                // Ignore
                }
            }
            return false;
        }
    }
    return true;
}
Also used : ServletRequestContext(org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext) ServletContext(jakarta.servlet.ServletContext) AsyncContext(jakarta.servlet.AsyncContext) Context(org.apache.catalina.Context) IOException(java.io.IOException) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) HttpSession(jakarta.servlet.http.HttpSession) Session(org.apache.catalina.Session)

Example 55 with Manager

use of org.apache.catalina.Manager in project spring-boot by spring-projects.

the class TomcatServletWebServerFactory method configureSession.

private void configureSession(Context context) {
    long sessionTimeout = getSessionTimeoutInMinutes();
    context.setSessionTimeout((int) sessionTimeout);
    Boolean httpOnly = getSession().getCookie().getHttpOnly();
    if (httpOnly != null) {
        context.setUseHttpOnly(httpOnly);
    }
    if (getSession().isPersistent()) {
        Manager manager = context.getManager();
        if (manager == null) {
            manager = new StandardManager();
            context.setManager(manager);
        }
        configurePersistSession(manager);
    } else {
        context.addLifecycleListener(new DisablePersistSessionListener());
    }
}
Also used : StandardManager(org.apache.catalina.session.StandardManager) Manager(org.apache.catalina.Manager) StandardManager(org.apache.catalina.session.StandardManager)

Aggregations

Manager (org.apache.catalina.Manager)56 StringManager (org.apache.tomcat.util.res.StringManager)26 IOException (java.io.IOException)24 Session (org.apache.catalina.Session)24 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 HttpSession (javax.servlet.http.HttpSession)8 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