DatastoreValve extends ValveBase { @Override public void invoke(Request request, Response response) throws IOException, ServletException { log.debug("Processing request with session:" + request.getRequestedSessionId()); getNext().invoke(request, response); Context context = request.getContext(); Manager manager = context.getManager(); Session session = request.getSessionInternal(false); if (session != null && !isUriExcluded(request.getRequestURI())) { log.debug("Persisting session with id: " + session.getId()); session.access(); session.endAccess(); if (manager instanceof StoreManager) { StoreManager storeManager = (StoreManager) manager; storeManager.getStore().save(session); storeManager.removeSuper(session); } else { log.error("In order to persist the session the manager must implement StoreManager"); } } else { log.debug("Session not persisted (Non existent or the URI is ignored)"); } }  @Override void invoke(Request request, Response response); void setUriExcludePattern(String uriExcludePattern);  }
@Test public void testSessionPersistence() throws Exception { valve.setNext(nextValve); valve.invoke(request, response); verify(store).save(session); verify(manager).removeSuper(session); }