Search in sources :

Example 21 with Session

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

the class HASessionStoreValve method doPostInvoke.

/**
 * A post-request processing implementation that does the valveSave.
 * @param request
 * @param response
 */
private void doPostInvoke(Request request, Response response) throws IOException, ServletException {
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("IN HASessionStoreValve>>postInvoke()");
    }
    String sessionId = null;
    Session session;
    StandardContext context;
    Manager manager;
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    HttpSession hsess = hreq.getSession(false);
    if (hsess != null) {
        sessionId = hsess.getId();
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("IN HASessionStoreValve:postInvoke:sessionId=" + sessionId);
        }
    }
    if (sessionId != null) {
        context = (StandardContext) request.getContext();
        manager = context.getManager();
        session = manager.findSession(sessionId);
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("IN HASessionStoreValve:postInvoke:session=" + session);
        }
        if (session != null) {
            WebEventPersistentManager pMgr = (WebEventPersistentManager) manager;
            pMgr.doValveSave(session);
        }
    }
    HACookieManager.reset();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) StandardContext(org.apache.catalina.core.StandardContext) HACookieManager(org.glassfish.ha.common.HACookieManager) Manager(org.apache.catalina.Manager) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.catalina.Session)

Example 22 with Session

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

the class HASessionStoreValve method invoke.

/**
 * invoke call-back; nothing to do on the way in
 * @param request
 * @param response
 */
public int invoke(org.apache.catalina.Request request, org.apache.catalina.Response response) throws java.io.IOException, javax.servlet.ServletException {
    // FIXME this is for 7.0PE style valves
    // left here if the same optimization is done to the valve architecture
    String sessionId = null;
    ReplicationWebEventPersistentManager manager;
    StandardContext context;
    HttpServletRequest httpServletrequest = (HttpServletRequest) request.getRequest();
    HttpSession session = httpServletrequest.getSession(false);
    if (session != null) {
        sessionId = session.getId();
        if (sessionId != null) {
            context = (StandardContext) request.getContext();
            manager = (ReplicationWebEventPersistentManager) context.getManager();
            String oldJreplicaValue = null;
            Cookie[] cookies = httpServletrequest.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equalsIgnoreCase(Globals.JREPLICA_COOKIE_NAME)) {
                        oldJreplicaValue = cookie.getValue();
                    }
                }
                String replica = manager.getReplicaFromPredictor(sessionId, oldJreplicaValue);
                if (replica != null) {
                    Session sess = request.getSessionInternal(false);
                    if (sess != null) {
                        sess.setNote(Globals.JREPLICA_SESSION_NOTE, replica);
                    }
                }
            }
        }
    }
    return INVOKE_NEXT;
// return 0;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) HttpSession(javax.servlet.http.HttpSession) StandardContext(org.apache.catalina.core.StandardContext) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.catalina.Session)

Example 23 with Session

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

the class ReplicationManagerBase method findSession.

public Session findSession(String id, String version) throws IOException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("in findSession: version=" + version);
    }
    if (!this.isSessionIdValid(id) || version == null) {
        return null;
    }
    Session loadedSession = null;
    long requiredVersion = 0L;
    long cachedVersion = -1L;
    try {
        requiredVersion = Long.parseLong(version);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Required version " + requiredVersion);
        }
    } catch (NumberFormatException ex) {
        _logger.log(Level.INFO, LogFacade.REQUIRED_VERSION_NFE, ex);
    // deliberately do nothing
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("findSession:requiredVersion=" + requiredVersion);
    }
    Session cachedSession = sessions.get(id);
    if (cachedSession != null) {
        cachedVersion = cachedSession.getVersion();
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("findSession:cachedVersion=" + cachedVersion);
    }
    // cached version even if it is greater than the required version
    if (cachedVersion == requiredVersion || (isRelaxCacheVersionSemantics() && (cachedVersion > requiredVersion))) {
        return cachedSession;
    } else {
        // though stale we might return it as the best we can do
        if (cachedVersion < requiredVersion && (!isRelaxCacheVersionSemantics())) {
            this.removeSessionFromManagerCache(cachedSession);
            cachedSession = null;
            cachedVersion = -1L;
        }
    }
    // See if the Session is in the Store
    if (requiredVersion != -1L) {
        loadedSession = swapIn(id, version);
    } else {
        loadedSession = swapIn(id);
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("findSession:swappedInSession=" + loadedSession);
    }
    if (loadedSession == null || loadedSession.getVersion() < cachedVersion) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationManagerBase>>findSession:returning cached version:" + cachedVersion);
        }
        return cachedSession;
    }
    if (loadedSession.getVersion() < requiredVersion && (!isRelaxCacheVersionSemantics())) {
        loadedSession = null;
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("ReplicationManagerBase>>findSession:returning:" + loadedSession);
    }
    return (loadedSession);
}
Also used : Session(org.apache.catalina.Session)

Example 24 with Session

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

the class ReplicationStore method getSession.

public Session getSession(byte[] state, long version) throws IOException {
    Session _session = null;
    InputStream is;
    BufferedInputStream bis;
    ByteArrayInputStream bais;
    ObjectInputStream ois = null;
    Loader loader = null;
    ClassLoader classLoader = null;
    Container container = manager.getContainer();
    // MERGE chg added
    java.security.Principal pal = null;
    try {
        bais = new ByteArrayInputStream(state);
        bis = new BufferedInputStream(bais);
        if (isReplicationCompressionEnabled()) {
            is = new GZIPInputStream(bis);
        } else {
            is = bis;
        }
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("loaded session from replicationstore, length = " + state.length);
        }
        loader = container.getLoader();
        if (loader != null) {
            classLoader = loader.getClassLoader();
        }
        if (classLoader != null) {
            try {
                ois = ioUtils.createObjectInputStream(is, true, classLoader, getUniqueId());
            } catch (Exception ex) {
                _logger.log(Level.WARNING, LogFacade.ERROR_CREATING_INPUT_STREAM, ex);
            }
        }
        if (ois == null) {
            ois = new ObjectInputStream(is);
        }
        try {
            _session = readSession(manager, ois);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                    bis = null;
                } catch (IOException e) {
                }
            }
        }
    } catch (ClassNotFoundException e) {
        IOException ex1 = (IOException) new IOException(_logger.getResourceBundle().getString(LogFacade.EXCEPTION_DESERIALIZING_SESSION) + e.getMessage()).initCause(e);
        _logger.log(Level.WARNING, LogFacade.EXCEPTION_DESERIALIZING_SESSION, ex1);
        throw ex1;
    } catch (IOException e) {
        if (_logger.isLoggable(Level.WARNING)) {
            _logger.log(Level.WARNING, LogFacade.EXCEPTION_GET_SESSION, e);
        }
        throw e;
    }
    String username = ((HASession) _session).getUserName();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("ReplicationStore>>getSession: username=" + username + " principal=" + _session.getPrincipal());
    }
    if ((username != null) && (!username.equals("")) && _session.getPrincipal() == null) {
        if (_debug > 0) {
            debug("Username retrieved is " + username);
        }
        pal = ((com.sun.web.security.RealmAdapter) container.getRealm()).createFailOveredPrincipal(username);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationStore>>getSession:created pal=" + pal);
        }
        if (_debug > 0) {
            debug("principal created using username  " + pal);
        }
        if (pal != null) {
            _session.setPrincipal(pal);
            if (_debug > 0) {
                debug("getSession principal=" + pal + " was added to session=" + _session);
            }
        }
    }
    // --SRI
    _session.setNew(false);
    ((HASession) _session).setVersion(version);
    ((HASession) _session).setDirty(false);
    ((HASession) _session).setPersistent(false);
    return _session;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Loader(org.apache.catalina.Loader) LifecycleException(org.apache.catalina.LifecycleException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) GZIPInputStream(java.util.zip.GZIPInputStream) Container(org.apache.catalina.Container) Session(org.apache.catalina.Session)

Example 25 with Session

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

the class ReplicationWebEventPersistentManager method getSession.

private Session getSession(ServletRequest request) {
    javax.servlet.http.HttpServletRequest httpReq = (javax.servlet.http.HttpServletRequest) request;
    javax.servlet.http.HttpSession httpSess = httpReq.getSession(false);
    if (httpSess == null) {
        return null;
    }
    String id = httpSess.getId();
    Session sess = null;
    try {
        sess = this.findSession(id);
    } catch (java.io.IOException ex) {
    }
    return sess;
}
Also used : Session(org.apache.catalina.Session)

Aggregations

Session (org.apache.catalina.Session)58 HttpSession (javax.servlet.http.HttpSession)17 Manager (org.apache.catalina.Manager)16 IOException (java.io.IOException)13 StandardSession (org.apache.catalina.session.StandardSession)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Context (org.apache.catalina.Context)7 StringManager (org.apache.tomcat.util.res.StringManager)7 StandardContext (org.apache.catalina.core.StandardContext)5 Principal (java.security.Principal)3 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 Realm (org.apache.catalina.Realm)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 ServletRequest (javax.servlet.ServletRequest)2 Cookie (javax.servlet.http.Cookie)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Loader (org.apache.catalina.Loader)2