private void handlePossibleFailover(Request request, DeltaSessionManager manager, String localJvmRoute) { String sessionId = request.getRequestedSessionId(); if (sessionId != null) {
@Override public void invoke(Request request, Response response) throws IOException, ServletException { String sessionId = request.getRequestedSessionId(); Session session = request.getContext().getManager().findSession(sessionId); if (session != null) { if (!session.isValid()) { session.expire(); request.getContext().getManager().remove(session); } else { manager.add(session); session.access(); session.endAccess(); } } try { getNext().invoke(request, response); } finally { manager.store(request.getSession(false)); } }
@Override public void invoke(Request request, Response response) throws IOException, ServletException { String sessionId = request.getRequestedSessionId(); Session session = request.getContext().getManager().findSession(sessionId); if (session != null) { if (!session.isValid()) { session.expire(); request.getContext().getManager().remove(session); } else { manager.add(session); session.access(); session.endAccess(); } } try { getNext().invoke(request, response); } finally { manager.store(request.getSession(false)); } }
@Override public void invoke(Request request, Response response) throws IOException, ServletException { String sessionId = request.getRequestedSessionId(); Session session = request.getContext().getManager().findSession(sessionId); if (session != null) { if (!session.isValid()) { session.expire(); request.getContext().getManager().remove(session); } else { manager.add(session); session.access(); session.endAccess(); } } try { getNext().invoke(request, response); } finally { manager.store(request.getSession(false)); } }
@Override public void invoke(Request request, Response response) throws IOException, ServletException { String sessionId = request.getRequestedSessionId(); Session session = request.getContext().getManager().findSession(sessionId); if (session != null) { if (!session.isValid()) { session.expire(); request.getContext().getManager().remove(session); } else { manager.add(session); session.access(); session.endAccess(); } } try { getNext().invoke(request, response); } finally { manager.store(request.getSession(false)); } }
/** * If there's a session for a requested session id that is taken over (tomcat failover) or * that will be relocated (memcached failover), the new session id will be set (via {@link Request#changeSessionId(String)}). * * @param request the request * @param response the response * * @return <code>true</code> if the id of a valid session was changed. * * @see Request#changeSessionId(String) */ private boolean changeRequestedSessionId( final Request request, final Response response ) { /* * Check for session relocation only if a session id was requested */ if ( request.getRequestedSessionId() != null ) { String newSessionId = _sessionBackupService.changeSessionIdOnTomcatFailover( request.getRequestedSessionId() ); if ( newSessionId == null ) { newSessionId = _sessionBackupService.changeSessionIdOnMemcachedFailover( request.getRequestedSessionId() ); } if ( newSessionId != null ) { request.changeSessionId( newSessionId ); return true; } } return false; }
private String getSessionId(final Request request, final Response response) { // If the context is configured with cookie="false" there's no session cookie // sent so we must rely on data from MemcachedSessionService String sessionId = (String) request.getNote(MemcachedSessionService.NEW_SESSION_ID); if(sessionId == null) { sessionId = getSessionIdFromResponseSessionCookie( response ); } return sessionId != null ? sessionId : request.getRequestedSessionId(); }
@Test public final void testRequestFinishedShouldBeInvokedForIgnoredResources() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( "foo" ); when(_request.getRequestURI()).thenReturn("/pixel.gif"); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).requestFinished( eq( "foo" ), anyString() ); }
@Test public final void testChangeSessionIdForRelocatedSession() throws IOException, ServletException { final String sessionId = "bar"; final String newSessionId = "newId"; when( _request.getRequestedSessionId() ).thenReturn( sessionId ); when( _service.changeSessionIdOnMemcachedFailover( eq( sessionId ) ) ).thenReturn( newSessionId ); _sessionTrackerValve.invoke( _request, _response ); verify( _request ).changeSessionId( eq( newSessionId ) ); verify(_request).setNote(eq(RequestTrackingHostValve.SESSION_ID_CHANGED), eq(Boolean.TRUE)); }
@Test public final void testBackupSessionNotInvokedWhenNoSessionIdPresent() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( null ); when( _response.getHeader( eq( "Set-Cookie" ) ) ).thenReturn( null ); _sessionTrackerValve.invoke( _request, _response ); verify( _service, never() ).backupSession( anyString(), anyBoolean(), anyString() ); }
@Test public final void testChangeSessionIdForRelocatedSession() throws IOException, ServletException { final String sessionId = "bar"; final String newSessionId = "newId"; when(_request.getNote(eq(RequestTrackingHostValve.SESSION_ID_CHANGED))).thenReturn(Boolean.TRUE); when( _request.getRequestedSessionId() ).thenReturn( sessionId ); final Cookie cookie = new Cookie( _sessionTrackerValve.getSessionCookieName(), newSessionId ); setupGetResponseSetCookieHeadersExpectations(_response, new String[]{generateCookieString( cookie )}); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).backupSession( eq( newSessionId ), eq( true ), anyString() ); }
@Test public final void testBackupSessionInvokedWhenResponseCookiePresent() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( null ); final Cookie cookie = new Cookie( _sessionTrackerValve.getSessionCookieName(), "foo" ); setupGetResponseSetCookieHeadersExpectations(_response, new String[]{generateCookieString( cookie )}); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).backupSession( eq( "foo" ), eq( false), anyString() ); }
public String getRequestedSessionId() { if (null == request) { return null; } return request.getRequestedSessionId(); } }
public void addElement(StringBuilder buf, Date date, Request request, Response response, long time) { buf.append(wrap(request.getRequestedSessionId())); } };
} else if ( _ignorePattern != null && _ignorePattern.matcher( requestId ).matches() ) { if(_log.isDebugEnabled()) { _log.debug( ">>>>>> Ignoring: " + requestId + " (requestedSessionId "+ request.getRequestedSessionId() +") ==================" ); _log.debug( ">>>>>> Request starting: " + requestId + " (requestedSessionId "+ request.getRequestedSessionId() +") ==================" );
@Override public String getRequestedSessionId() { if (request == null) { throw new IllegalStateException( sm.getString("requestFacade.nullRequest")); } return request.getRequestedSessionId(); }
public String getRequestedSessionId() { if (request == null) { throw MESSAGES.nullRequestFacade(); } return request.getRequestedSessionId(); }
@Override public String getRequestedSessionId() { if (request == null) { throw new IllegalStateException( sm.getString("requestFacade.nullRequest")); } return request.getRequestedSessionId(); }
@Override public String getRequestedSessionId() { if (request == null) { throw new IllegalStateException( sm.getString("requestFacade.nullRequest")); } return request.getRequestedSessionId(); }
@Override public void addElement(CharArrayWriter buf, Date date, Request request, Response response, long time) { buf.append(wrap(request.getRequestedSessionId())); } };