@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = this.data.remove(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(sessionAttribute.getValue())); session.put(sessionAttribute.getKey(), in.readObject()); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
private PersistentSession readSession(final File sessionFile) { try { try (final FileInputStream fileInputStream = new FileInputStream(sessionFile)) { try (final ObjectInputStream in = new ObjectInputStream(fileInputStream)) { final Date expDate = new Date(in.readLong()); final HashMap<String, Object> sessionData = new HashMap<>(); try { for (; ; ) readSessionAttribute(in, sessionData); } catch (EOFException e) { ;// Ok we reached the end of the file } return new PersistentSession(expDate, sessionData); } } } catch (IOException e) { LOGGER.log(Level.WARNING, e, () -> "Cannot load sessions from " + sessionFile); return null; } }
objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData));
objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData));
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
public void stop() { ClassLoader old = getTccl(); try { setTccl(servletContext.getClassLoader()); this.started = false; final Map<String, SessionPersistenceManager.PersistentSession> objectData = new HashMap<>(); for (String sessionId : sessionManager.getTransientSessions()) { Session session = sessionManager.getSession(sessionId); if (session != null) { final HttpSessionEvent event = new HttpSessionEvent(SecurityActions.forSession(session, servletContext, false)); final Map<String, Object> sessionData = new HashMap<>(); for (String attr : session.getAttributeNames()) { final Object attribute = session.getAttribute(attr); sessionData.put(attr, attribute); if (attribute instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener) attribute).sessionWillPassivate(event); } } objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData)); } } sessionPersistenceManager.persistSessions(deploymentName, objectData); this.data.clear(); } finally { setTccl(old); } }
public PersistentSession getPersistentSession() { return new PersistentSession(this.expiration, this.sessionData); }