/** * @return an <code>Enumeration</code> of <code>String</code> objects * containing the names of all the objects bound to this session. */ public Set<String> attributes() { TreeSet<String> attributes = new TreeSet<>(); Enumeration<String> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { attributes.add(enumeration.nextElement()); } return attributes; }
@Override public boolean isEmpty() { if (this.session == null) { return true; } final Enumeration<String> attributeNames = this.session.getAttributeNames(); return !attributeNames.hasMoreElements(); }
public FakeHttpSession copyAttributes(HttpSession httpSession) { Enumeration<String> e = httpSession.getAttributeNames(); String k; while (e.hasMoreElements()) { k = e.nextElement(); if (k == null) continue; Object o = httpSession.getAttribute(k); if (o == null) continue; attributes.put(k, o); } return this; }
@Override public void doFilter(HttpServletRequest wrappedRequest) { assertThat(wrappedRequest.getSession().getAttribute(ATTR)) .isEqualTo(VALUE); assertThat( Collections.list(wrappedRequest.getSession().getAttributeNames())) .containsOnly(ATTR); } });
public static String dumpSessionAttributes(HttpSession session) { StringBuilder sb = new StringBuilder(); Enumeration<?> en = session.getAttributeNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); sb.append("[" + name + "]: " + session.getAttribute(name) + '\n'); } return sb.toString(); }
/** {@inheritDoc} */ public void removeAttributes() { // synchronize to prevent parallel modifications synchronized (session) { final Enumeration<String> names = session.getAttributeNames(); while (names.hasMoreElements()) { session.removeAttribute(names.nextElement()); } } }
public boolean isEmpty() throws TemplateModelException { checkSessionExistence(); return session == null || !session.getAttributeNames().hasMoreElements(); } }
@Override public void doFilter(HttpServletRequest wrappedRequest) { wrappedRequest.getSession().setAttribute(ATTR, VALUE); assertThat(wrappedRequest.getSession().getAttribute(ATTR)) .isEqualTo(VALUE); assertThat( Collections.list(wrappedRequest.getSession().getAttributeNames())) .containsOnly(ATTR); } });
/** {@inheritDoc} */ public Map<String, Object> getAttributes() { final Map<String, Object> result = new HashMap<String, Object>(); // Synchronize to prevent parallel modifications synchronized (session) { final Enumeration<String> names = session.getAttributeNames(); while (names.hasMoreElements()) { final String name = names.nextElement(); result.put(name, session.getAttribute(name)); } } return Collections.unmodifiableMap(result); }
@Override public int size() { if (this.session == null) { return 0; } int size = 0; final Enumeration<String> attributeNames = this.session.getAttributeNames(); while (attributeNames.hasMoreElements()) { attributeNames.nextElement(); size++; } return size; }
@Test public void handleAndCompleteSession() throws Exception { HandlerMethod handlerMethod = handlerMethod("handleAndCompleteSession", SessionStatus.class); handlerAdapter.handle(request, response, handlerMethod); assertFalse(request.getSession().getAttributeNames().hasMoreElements()); }
session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000L); final List<String> attributeNames = Collections.list(session.getAttributeNames()); attributeCount = attributeNames.size(); serializable = computeSerializable(session, attributeNames); final Object countryCode = session.getAttribute(SessionListener.SESSION_COUNTRY_KEY); if (countryCode == null) { country = null; final Object addr = session.getAttribute(SessionListener.SESSION_REMOTE_ADDR); if (addr == null) { remoteAddr = null; Object user = session.getAttribute(SessionListener.SESSION_REMOTE_USER); if (user == null) {
@Override public Collection<Object> values() { if (this.session == null) { return Collections.emptySet(); } final List<Object> values = new ArrayList<Object>(5); final Enumeration<String> attributeNames = this.session.getAttributeNames(); while (attributeNames.hasMoreElements()) { values.add(this.session.getAttribute(attributeNames.nextElement())); } return values; }
/** {@inheritDoc} */ public Set<String> getAttributeNames() { final Set<String> result = new HashSet<String>(); // Synchronize to prevent parallel modifications synchronized (session) { final Enumeration<String> names = session.getAttributeNames(); while (names.hasMoreElements()) { result.add(names.nextElement()); } } return Collections.unmodifiableSet(result); }
for (String name : Collections.list(httpSession.getAttributeNames())) { Object obj = httpSession.getAttribute(name); sessionSerializable = sessionSerializable && obj instanceof Serializable; (String) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_BY_IP); if (lastAccessedIp != null) { sbean.setLastAccessedIp(lastAccessedIp); sbean.setLastAccessedIpLocale( (Locale) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_LOCALE));
/** * 将Session中的值放入模板上下文 * @param context 模板上下文 * @param session Session * @return VelocityContext */ public static VelocityContext parseSession(VelocityContext context, javax.servlet.http.HttpSession session) { if (null != session) { final Enumeration<String> sessionAttrs = session.getAttributeNames(); if (sessionAttrs != null) { String attrName = null; while (sessionAttrs.hasMoreElements()) { attrName = sessionAttrs.nextElement(); context.put(attrName, session.getAttribute(attrName)); } } } return context; }
@Override public Set<String> keySet() { if (this.session == null) { return Collections.emptySet(); } final Set<String> keySet = new LinkedHashSet<String>(5); final Enumeration<String> attributeNames = this.session.getAttributeNames(); while (attributeNames.hasMoreElements()) { keySet.add(attributeNames.nextElement()); } return keySet; }
@Override public boolean renewSession(JaxRsContext context) { final HttpSession session = getHttpSession(context); final Map<String, Object> attributes = new HashMap<>(); Collections.list(session.getAttributeNames()).forEach(k -> attributes.put(k, session.getAttribute(k))); session.invalidate(); // let's recreate the session from zero, the previous becomes // generally unusable depending on the servlet implementation final HttpSession newSession = getHttpSession(context); attributes.forEach(newSession::setAttribute); return true; }
/** * 将Session中的值放入模板上下文 * @param context 模板上下文 * @param session Session * @return VelocityContext */ public static VelocityContext parseSession(VelocityContext context, javax.servlet.http.HttpSession session) { if (null != session) { final Enumeration<String> sessionAttrs = session.getAttributeNames(); if (sessionAttrs != null) { String attrName = null; while (sessionAttrs.hasMoreElements()) { attrName = sessionAttrs.nextElement(); context.put(attrName, session.getAttribute(attrName)); } } } return context; }
public Collection<Object> getAttributeKeys() throws InvalidSessionException { try { Enumeration namesEnum = httpSession.getAttributeNames(); Collection<Object> keys = null; if (namesEnum != null) { keys = new ArrayList<Object>(); while (namesEnum.hasMoreElements()) { keys.add(namesEnum.nextElement()); } } return keys; } catch (Exception e) { throw new InvalidSessionException(e); } }