Java Code Examples for org.apache.catalina.Session#setId()
The following examples show how to use
org.apache.catalina.Session#setId() .
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: JvmRouteBinderValve.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * change session id and send to all cluster nodes * * @param request current request * @param sessionId * original session id * @param newSessionID * new session id for node migration * @param catalinaSession * current session with original session id */ protected void changeSessionID(Request request, String sessionId, String newSessionID, Session catalinaSession) { fireLifecycleEvent("Before session migration", catalinaSession); catalinaSession.setId(newSessionID, false); // FIXME: Why we remove change data from other running request? // setId also trigger resetDeltaRequest!! if (catalinaSession instanceof DeltaSession) ((DeltaSession) catalinaSession).resetDeltaRequest(); changeRequestSessionID(request, sessionId, newSessionID); // now sending the change to all other clusternodes! sendSessionIDClusterBackup(request,sessionId, newSessionID); fireLifecycleEvent("After session migration", catalinaSession); if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.changeSession", sessionId, newSessionID)); } }
Example 2
Source File: JvmRouteBinderValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * change session id and send to all cluster nodes * * @param request current request * @param sessionId * original session id * @param newSessionID * new session id for node migration * @param catalinaSession * current session with original session id */ protected void changeSessionID(Request request, String sessionId, String newSessionID, Session catalinaSession) { fireLifecycleEvent("Before session migration", catalinaSession); catalinaSession.setId(newSessionID, false); // FIXME: Why we remove change data from other running request? // setId also trigger resetDeltaRequest!! if (catalinaSession instanceof DeltaSession) ((DeltaSession) catalinaSession).resetDeltaRequest(); changeRequestSessionID(request, sessionId, newSessionID); // now sending the change to all other clusternodes! sendSessionIDClusterBackup(request,sessionId, newSessionID); fireLifecycleEvent("After session migration", catalinaSession); if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.changeSession", sessionId, newSessionID)); } }
Example 3
Source File: ManagerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public Session createSession(String sessionId) { if ((maxActiveSessions >= 0) && (getActiveSessions() >= maxActiveSessions)) { rejectedSessions++; throw new TooManyActiveSessionsException( sm.getString("managerBase.createSession.ise"), maxActiveSessions); } // Recycle or create a Session instance Session session = createEmptySession(); // Initialize the properties of the new session and return it session.setNew(true); session.setValid(true); session.setCreationTime(System.currentTimeMillis()); session.setMaxInactiveInterval(getContext().getSessionTimeout() * 60); String id = sessionId; if (id == null) { id = generateSessionId(); } session.setId(id); sessionCounter++; SessionTiming timing = new SessionTiming(session.getCreationTime(), 0); synchronized (sessionCreationTiming) { sessionCreationTiming.add(timing); sessionCreationTiming.poll(); } return session; }
Example 4
Source File: ManagerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
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 5
Source File: ManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Construct and return a new session object, based on the default * settings specified by this Manager's properties. The session * id specified will be used as the session id. * If a new session cannot be created for any reason, return * <code>null</code>. * * @param sessionId The session id which should be used to create the * new session; if <code>null</code>, a new session id will be * generated * @exception IllegalStateException if a new session cannot be * instantiated for any reason */ @Override public Session createSession(String sessionId) { if ((maxActiveSessions >= 0) && (getActiveSessions() >= maxActiveSessions)) { rejectedSessions++; throw new TooManyActiveSessionsException( sm.getString("managerBase.createSession.ise"), maxActiveSessions); } // Recycle or create a Session instance Session session = createEmptySession(); // Initialize the properties of the new session and return it session.setNew(true); session.setValid(true); session.setCreationTime(System.currentTimeMillis()); session.setMaxInactiveInterval(this.maxInactiveInterval); String id = sessionId; if (id == null) { id = generateSessionId(); } session.setId(id); sessionCounter++; SessionTiming timing = new SessionTiming(session.getCreationTime(), 0); synchronized (sessionCreationTiming) { sessionCreationTiming.add(timing); sessionCreationTiming.poll(); } return (session); }
Example 6
Source File: ManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: ManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public Session createSession(String sessionId) { if ((maxActiveSessions >= 0) && (getActiveSessions() >= maxActiveSessions)) { rejectedSessions++; throw new TooManyActiveSessionsException( sm.getString("managerBase.createSession.ise"), maxActiveSessions); } // Recycle or create a Session instance Session session = createEmptySession(); // Initialize the properties of the new session and return it session.setNew(true); session.setValid(true); session.setCreationTime(System.currentTimeMillis()); session.setMaxInactiveInterval(((Context) getContainer()).getSessionTimeout() * 60); String id = sessionId; if (id == null) { id = generateSessionId(); } session.setId(id); sessionCounter++; SessionTiming timing = new SessionTiming(session.getCreationTime(), 0); synchronized (sessionCreationTiming) { sessionCreationTiming.add(timing); sessionCreationTiming.poll(); } return (session); }
Example 8
Source File: ManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
@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: RedisStoreTest.java From session-managers with Apache License 2.0 | 5 votes |
@Test public void load() throws IOException { Session session = new StandardSession(this.manager); session.setId("test-id"); byte[] response = this.sessionSerializationUtils.serialize(session); when(this.jedisClient.get("test-id")).thenReturn(response); Session result = this.store.load("test-id"); assertEquals(session.getId(), result.getId()); }
Example 10
Source File: RedisStoreTest.java From session-managers with Apache License 2.0 | 5 votes |
@Test public void save() throws IOException { Session session = new StandardSession(this.manager); session.setId("test-id"); this.store.save(session); verify(this.jedisClient).set(getRedisSessionId(session), SESSIONS_KEY, this.sessionSerializationUtils.serialize(session), session.getMaxInactiveInterval()); }
Example 11
Source File: RedisStoreTest.java From session-managers with Apache License 2.0 | 5 votes |
@Test public void saveJedisConnectionException() throws UnsupportedEncodingException { Session session = new StandardSession(this.manager); session.setId("test-id"); doThrow(new JedisConnectionException("test-message")) .when(this.jedisClient) .set(anyString(), anyString(), any((byte[].class)), eq(session.getMaxInactiveInterval())); this.store.save(session); }
Example 12
Source File: JvmRouteSessionIDBinderListener.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Callback from the cluster, when a message is received, The cluster will * broadcast it invoking the messageReceived on the receiver. * * @param msg * ClusterMessage - the message received from the cluster */ @Override public void messageReceived(ClusterMessage msg) { if (msg instanceof SessionIDMessage) { SessionIDMessage sessionmsg = (SessionIDMessage) msg; if (log.isDebugEnabled()) log.debug(sm.getString( "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg .getOrignalSessionID(), sessionmsg .getBackupSessionID(), sessionmsg .getContextName())); Container container = getCluster().getContainer(); Container host = null ; if(container instanceof Engine) { host = container.findChild(sessionmsg.getHost()); } else { host = container ; } if (host != null) { Context context = (Context) host.findChild(sessionmsg .getContextName()); if (context != null) { try { Session session = context.getManager().findSession( sessionmsg.getOrignalSessionID()); if (session != null) { session.setId(sessionmsg.getBackupSessionID()); } else if (log.isInfoEnabled()) log.info(sm.getString("jvmRoute.lostSession", sessionmsg.getOrignalSessionID(), sessionmsg.getContextName())); } catch (IOException e) { log.error(e); } } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.contextNotFound", sessionmsg.getContextName(), ((StandardEngine) host .getParent()).getJvmRoute())); } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName())); } return; }
Example 13
Source File: JvmRouteSessionIDBinderListener.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Callback from the cluster, when a message is received, The cluster will * broadcast it invoking the messageReceived on the receiver. * * @param msg * ClusterMessage - the message received from the cluster */ @Override public void messageReceived(ClusterMessage msg) { if (msg instanceof SessionIDMessage) { SessionIDMessage sessionmsg = (SessionIDMessage) msg; if (log.isDebugEnabled()) log.debug(sm.getString( "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg .getOrignalSessionID(), sessionmsg .getBackupSessionID(), sessionmsg .getContextName())); Container container = getCluster().getContainer(); Container host = null ; if(container instanceof Engine) { host = container.findChild(sessionmsg.getHost()); } else { host = container ; } if (host != null) { Context context = (Context) host.findChild(sessionmsg .getContextName()); if (context != null) { try { Session session = context.getManager().findSession( sessionmsg.getOrignalSessionID()); if (session != null) { session.setId(sessionmsg.getBackupSessionID()); } else if (log.isInfoEnabled()) log.info(sm.getString("jvmRoute.lostSession", sessionmsg.getOrignalSessionID(), sessionmsg.getContextName())); } catch (IOException e) { log.error(e); } } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.contextNotFound", sessionmsg.getContextName(), ((StandardEngine) host .getParent()).getJvmRoute())); } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName())); } return; }