Search in sources :

Example 1 with PersistentManager

use of org.apache.catalina.session.PersistentManager in project tomcat by apache.

the class PersistentManagerSF method storeChildren.

/**
 * Store the specified PersistentManager properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aManager
 *            PersistentManager whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aManager, StoreDescription parentDesc) throws Exception {
    if (aManager instanceof PersistentManager) {
        PersistentManager manager = (PersistentManager) aManager;
        // Store nested <Store> element
        Store store = manager.getStore();
        storeElement(aWriter, indent, store);
        // Store nested <SessionIdGenerator> element
        SessionIdGenerator sessionIdGenerator = manager.getSessionIdGenerator();
        if (sessionIdGenerator != null) {
            storeElement(aWriter, indent, sessionIdGenerator);
        }
    }
}
Also used : PersistentManager(org.apache.catalina.session.PersistentManager) Store(org.apache.catalina.Store) SessionIdGenerator(org.apache.catalina.SessionIdGenerator)

Example 2 with PersistentManager

use of org.apache.catalina.session.PersistentManager in project Payara by payara.

the class PersistentValve method invoke.

// --------------------------------------------------------- Public Methods
/**
 * 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 int invoke(Request request, Response response) throws IOException, ServletException {
    // Select the Context to be used for this Request
    Context context = request.getContext();
    if (context == null) {
        ((HttpServletResponse) response.getResponse()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rb.getString(LogFacade.NO_CONTEXT_CONFIGURED));
        return END_PIPELINE;
    }
    // Bind the context CL to the current thread
    Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
    // Update the session last access time for our session (if any)
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    String sessionId = hreq.getRequestedSessionId();
    Manager manager = context.getManager();
    if (sessionId != null && manager != null) {
        if (manager instanceof PersistentManager) {
            Store store = ((PersistentManager) manager).getStore();
            if (store != null) {
                Session session = null;
                try {
                    session = store.load(sessionId);
                } catch (Exception e) {
                    log("deserializeError");
                }
                if (session != null) {
                    if (!session.isValid() || isSessionStale(session, System.currentTimeMillis())) {
                        log("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();
                    }
                }
            }
        }
    }
    log("sessionId: " + sessionId);
    // Ask the next valve to process the request.
    return INVOKE_NEXT;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PersistentManager(org.apache.catalina.session.PersistentManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) PersistentManager(org.apache.catalina.session.PersistentManager) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpSession(javax.servlet.http.HttpSession)

Example 3 with PersistentManager

use of org.apache.catalina.session.PersistentManager in project tomcat70 by apache.

the class PersistentValve method invoke.

// --------------------------------------------------------- Public Methods
/**
 * 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 {
    // 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 PersistentManager) {
        Store store = ((PersistentManager) 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 PersistentManager) {
                    Session session = manager.findSession(newsessionId);
                    Store store = ((PersistentManager) manager).getStore();
                    if (store != null && session != null && session.isValid() && !isSessionStale(session, System.currentTimeMillis())) {
                        store.save(session);
                        ((PersistentManager) manager).removeSuper(session);
                        session.recycle();
                    } else {
                        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();
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) PersistentManager(org.apache.catalina.session.PersistentManager) Store(org.apache.catalina.Store) PersistentManager(org.apache.catalina.session.PersistentManager) Manager(org.apache.catalina.Manager) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Session(org.apache.catalina.Session)

Example 4 with PersistentManager

use of org.apache.catalina.session.PersistentManager in project Payara by payara.

the class PersistentValve method postInvoke.

@Override
public void postInvoke(Request request, Response response) throws IOException, ServletException {
    Context context = request.getContext();
    if (context == null) {
        ((HttpServletResponse) response.getResponse()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rb.getString(LogFacade.NO_CONTEXT_CONFIGURED));
        return;
    }
    // Bind the context CL to the current thread
    Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
    // Update the session last access time for our session (if any)
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    Manager manager = context.getManager();
    // Read the sessionid after the response.
    // HttpSession hsess = hreq.getSession(false);
    String newsessionId = null;
    if (request instanceof org.apache.catalina.connector.Request) {
        Session sess;
        try {
            sess = ((org.apache.catalina.connector.Request) request).getSessionInternal();
        } catch (Exception ex) {
            sess = null;
        }
        if (sess != null) {
            newsessionId = sess.getIdInternal();
        }
    } else {
        HttpSession hsess;
        try {
            hsess = hreq.getSession();
        } catch (Exception ex) {
            hsess = null;
        }
        if (hsess != null) {
            newsessionId = hsess.getId();
        }
    }
    log("newsessionId: " + newsessionId);
    if (newsessionId != null) {
        /* store the session in the store and remove it from the manager */
        if (manager instanceof PersistentManager) {
            Session session = manager.findSession(newsessionId);
            Store store = ((PersistentManager) manager).getStore();
            if (store != null && session != null && session.isValid() && !isSessionStale(session, System.currentTimeMillis())) {
                // ((StandardSession)session).passivate();
                store.save(session);
                ((PersistentManager) manager).removeSuper(session);
                session.recycle();
            } else if (session != null) {
                log("newsessionId store: " + store + " session: " + session + " valid: " + session.isValid() + " Staled: " + isSessionStale(session, System.currentTimeMillis()));
            }
        } else {
            log("newsessionId Manager: " + manager);
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) PersistentManager(org.apache.catalina.session.PersistentManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) PersistentManager(org.apache.catalina.session.PersistentManager) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) org.apache.catalina(org.apache.catalina) HttpSession(javax.servlet.http.HttpSession)

Example 5 with PersistentManager

use of org.apache.catalina.session.PersistentManager in project Payara by payara.

the class FileStrategyBuilder method initializePersistenceStrategy.

public void initializePersistenceStrategy(Context ctx, SessionManager smBean, ServerConfigLookup serverConfigLookup) {
    if (_logger.isLoggable(Level.INFO)) {
        _logger.log(Level.INFO, LogFacade.FILE_PERSISTENCE, ctx.getPath());
    }
    super.initializePersistenceStrategy(ctx, smBean, serverConfigLookup);
    PersistentManager mgr = new PersistentManager();
    mgr.setMaxActiveSessions(maxSessions);
    mgr.setMaxIdleBackup(maxIdleBackup);
    mgr.setMinIdleSwap(minIdleSwap);
    mgr.setMaxIdleSwap(maxIdleSwap);
    FileStore store = new FileStore();
    store.setDirectory(directory);
    mgr.setStore(store);
    // START OF 6364900
    mgr.setSessionLocker(new PESessionLocker(ctx));
    // END OF 6364900
    ctx.setManager(mgr);
    if (!((StandardContext) ctx).isSessionTimeoutOveridden()) {
        mgr.setMaxInactiveInterval(sessionMaxInactiveInterval);
    }
    // Special code for Java Server Faces
    if (ctx.findParameter(JSF_HA_ENABLED) == null) {
        ctx.addParameter(JSF_HA_ENABLED, "true");
    }
}
Also used : FileStore(org.apache.catalina.session.FileStore) PersistentManager(org.apache.catalina.session.PersistentManager)

Aggregations

PersistentManager (org.apache.catalina.session.PersistentManager)5 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 Store (org.apache.catalina.Store)2 org.apache.catalina (org.apache.catalina)1 Context (org.apache.catalina.Context)1 Manager (org.apache.catalina.Manager)1 Session (org.apache.catalina.Session)1 SessionIdGenerator (org.apache.catalina.SessionIdGenerator)1 FileStore (org.apache.catalina.session.FileStore)1