Java Code Examples for org.apache.catalina.Session#getIdInternal()

The following examples show how to use org.apache.catalina.Session#getIdInternal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagerBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void remove(Session session, boolean update) {
    // If the session has expired - as opposed to just being removed from
    // the manager because it is being persisted - update the expired stats
    if (update) {
        long timeNow = System.currentTimeMillis();
        int timeAlive =
            (int) (timeNow - session.getCreationTimeInternal())/1000;
        updateSessionMaxAliveTime(timeAlive);
        expiredSessions.incrementAndGet();
        SessionTiming timing = new SessionTiming(timeNow, timeAlive);
        synchronized (sessionExpirationTiming) {
            sessionExpirationTiming.add(timing);
            sessionExpirationTiming.poll();
        }
    }

    if (session.getIdInternal() != null) {
        sessions.remove(session.getIdInternal());
    }
}
 
Example 2
Source File: ManagerBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove this Session from the active Sessions for this Manager.
 *
 * @param session   Session to be removed
 * @param update    Should the expiration statistics be updated
 */
@Override
public void remove(Session session, boolean update) {
    
    // If the session has expired - as opposed to just being removed from
    // the manager because it is being persisted - update the expired stats
    if (update) {
        long timeNow = System.currentTimeMillis();
        int timeAlive =
            (int) (timeNow - session.getCreationTimeInternal())/1000;
        updateSessionMaxAliveTime(timeAlive);
        expiredSessions.incrementAndGet();
        SessionTiming timing = new SessionTiming(timeNow, timeAlive);
        synchronized (sessionExpirationTiming) {
            sessionExpirationTiming.add(timing);
            sessionExpirationTiming.poll();
        }
    }

    if (session.getIdInternal() != null) {
        sessions.remove(session.getIdInternal());
    }
}
 
Example 3
Source File: ManagerBase.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void remove(Session session, boolean update) {
    // If the session has expired - as opposed to just being removed from
    // the manager because it is being persisted - update the expired stats
    if (update) {
        long timeNow = System.currentTimeMillis();
        int timeAlive =
            (int) (timeNow - session.getCreationTimeInternal())/1000;
        updateSessionMaxAliveTime(timeAlive);
        expiredSessions.incrementAndGet();
        SessionTiming timing = new SessionTiming(timeNow, timeAlive);
        synchronized (sessionExpirationTiming) {
            sessionExpirationTiming.add(timing);
            sessionExpirationTiming.poll();
        }
    }

    if (session.getIdInternal() != null) {
        sessions.remove(session.getIdInternal());
    }
}
 
Example 4
Source File: PersistentManagerBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 */
@Override
public Session findSession(String id) throws IOException {

    Session session = super.findSession(id);
    // OK, at this point, we're not sure if another thread is trying to
    // remove the session or not so the only way around this is to lock it
    // (or attempt to) and then try to get it by this session id again. If
    // the other code ran swapOut, then we should get a null back during
    // this run, and if not, we lock it out so we can access the session
    // safely.
    if(session != null) {
        synchronized(session){
            session = super.findSession(session.getIdInternal());
            if(session != null){
               // To keep any external calling code from messing up the
               // concurrency.
               session.access();
               session.endAccess();
            }
        }
    }
    if (session != null)
        return session;

    // See if the Session is in the Store
    session = swapIn(id);
    return session;
}
 
Example 5
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Session session, boolean update) {
    super.remove(session, update);
    
    if (session.getIdInternal() != null) {
        ((RedissonSession)session).delete();
    }
}
 
Example 6
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Session session, boolean update) {
    super.remove(session, update);
    
    if (session.getIdInternal() != null) {
        ((RedissonSession)session).delete();
    }
}
 
Example 7
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Session session, boolean update) {
    super.remove(session, update);
    
    if (session.getIdInternal() != null) {
        ((RedissonSession)session).delete();
    }
}
 
Example 8
Source File: ManagerBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void changeSessionId(Session session) {
    String oldId = session.getIdInternal();
    session.setId(generateSessionId(), false);
    String newId = session.getIdInternal();
    container.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
            new String[] {oldId, newId});
}
 
Example 9
Source File: PersistentManagerBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 */
@Override
public Session findSession(String id) throws IOException {

    Session session = super.findSession(id);
    // OK, at this point, we're not sure if another thread is trying to
    // remove the session or not so the only way around this is to lock it
    // (or attempt to) and then try to get it by this session id again. If
    // the other code ran swapOut, then we should get a null back during
    // this run, and if not, we lock it out so we can access the session
    // safely.
    if(session != null) {
        synchronized(session){
            session = super.findSession(session.getIdInternal());
            if(session != null){
               // To keep any external calling code from messing up the
               // concurrency.
               session.access();
               session.endAccess();
            }
        }
    }
    if (session != null)
        return session;

    // See if the Session is in the Store
    session = swapIn(id);
    return session;
}
 
Example 10
Source File: ReplicationValve.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
* Send message delta message from request session 
* @param session current session
* @param manager session manager
* @param cluster replication cluster
*/
protected void sendMessage(Session session,
         ClusterManager manager, CatalinaCluster cluster) {
    String id = session.getIdInternal();
    if (id != null) {
        send(manager, cluster, id);
    }
}
 
Example 11
Source File: ManagerBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Change the session ID of the current session to a new randomly generated
 * session ID.
 * 
 * @param session   The session to change the session ID for
 */
@Override
public void changeSessionId(Session session) {
    String oldId = session.getIdInternal();
    session.setId(generateSessionId(), false);
    String newId = session.getIdInternal();
    container.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
            new String[] {oldId, newId});
}
 
Example 12
Source File: PersistentManagerBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the active Session, associated with this Manager, with the
 * specified session id (if any); otherwise return <code>null</code>.
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 *
 * @param id The session id for the session to be returned
 *
 * @exception IllegalStateException if a new session cannot be
 *  instantiated for any reason
 * @exception IOException if an input/output error occurs while
 *  processing this request
 */
@Override
public Session findSession(String id) throws IOException {

    Session session = super.findSession(id);
    // OK, at this point, we're not sure if another thread is trying to
    // remove the session or not so the only way around this is to lock it
    // (or attempt to) and then try to get it by this session id again. If
    // the other code ran swapOut, then we should get a null back during
    // this run, and if not, we lock it out so we can access the session
    // safely.
    if(session != null) {
        synchronized(session){
            session = super.findSession(session.getIdInternal());
            if(session != null){
               // To keep any external calling code from messing up the
               // concurrency.
               session.access();
               session.endAccess();
            }
        }
    }
    if (session != null)
        return session;

    // See if the Session is in the Store
    session = swapIn(id);
    return session;

}
 
Example 13
Source File: ReplicationValve.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
* Send message delta message from request session 
* @param session current session
* @param manager session manager
* @param cluster replication cluster
*/
protected void sendMessage(Session session,
         ClusterManager manager, CatalinaCluster cluster) {
    String id = session.getIdInternal();
    if (id != null) {
        send(manager, cluster, id);
    }
}
 
Example 14
Source File: ManagerBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void changeSessionId(Session session, String newId,
        boolean notifySessionListeners, boolean notifyContainerListeners) {
    String oldId = session.getIdInternal();
    session.setId(newId, false);
    session.tellChangedSessionId(newId, oldId,
            notifySessionListeners, notifyContainerListeners);
}
 
Example 15
Source File: ReplicationValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
* Send message delta message from request session
* @param session current session
* @param manager session manager
*/
protected void sendMessage(Session session,
         ClusterManager manager) {
    String id = session.getIdInternal();
    if (id != null) {
        send(manager, id);
    }
}
 
Example 16
Source File: Response.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private boolean doIsEncodeable(Request hreq, Session session,
                               String location) {
    // Is this a valid absolute URL?
    URL url = null;
    try {
        url = new URL(location);
    } catch (MalformedURLException e) {
        return (false);
    }

    // Does this URL match down to (and including) the context path?
    if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
        return (false);
    }
    if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
        return (false);
    }
    int serverPort = hreq.getServerPort();
    if (serverPort == -1) {
        if ("https".equals(hreq.getScheme())) {
            serverPort = 443;
        } else {
            serverPort = 80;
        }
    }
    int urlPort = url.getPort();
    if (urlPort == -1) {
        if ("https".equals(url.getProtocol())) {
            urlPort = 443;
        } else {
            urlPort = 80;
        }
    }
    if (serverPort != urlPort) {
        return (false);
    }

    String contextPath = getContext().getPath();
    if (contextPath != null) {
        String file = url.getFile();
        if ((file == null) || !file.startsWith(contextPath)) {
            return (false);
        }
        String tok = ";" +
                SessionConfig.getSessionUriParamName(request.getContext()) +
                "=" + session.getIdInternal();
        if( file.indexOf(tok, contextPath.length()) >= 0 ) {
            return (false);
        }
    }

    // This URL belongs to our web application, so it is encodeable
    return (true);

}
 
Example 17
Source File: Response.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private boolean doIsEncodeable(Request hreq, Session session,
                               String location) {
    // Is this a valid absolute URL?
    URL url = null;
    try {
        url = new URL(location);
    } catch (MalformedURLException e) {
        return (false);
    }

    // Does this URL match down to (and including) the context path?
    if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
        return (false);
    }
    if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
        return (false);
    }
    int serverPort = hreq.getServerPort();
    if (serverPort == -1) {
        if ("https".equals(hreq.getScheme())) {
            serverPort = 443;
        } else {
            serverPort = 80;
        }
    }
    int urlPort = url.getPort();
    if (urlPort == -1) {
        if ("https".equals(url.getProtocol())) {
            urlPort = 443;
        } else {
            urlPort = 80;
        }
    }
    if (serverPort != urlPort) {
        return (false);
    }

    String contextPath = getContext().getPath();
    if (contextPath != null) {
        String file = url.getFile();
        if (!file.startsWith(contextPath)) {
            return (false);
        }
        String tok = ";" +
                SessionConfig.getSessionUriParamName(request.getContext()) +
                "=" + session.getIdInternal();
        if( file.indexOf(tok, contextPath.length()) >= 0 ) {
            return (false);
        }
    }

    // This URL belongs to our web application, so it is encodeable
    return (true);

}