List of usage examples for javax.servlet.http HttpSession getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
of String
objects containing the names of all the objects bound to this session. From source file:org.parancoe.web.util.MarkPositionHelper.java
public static void unmarkAllPositions(HttpSession session) { Enumeration attributeNames = session.getAttributeNames(); while (attributeNames.hasMoreElements()) { String name = (String) attributeNames.nextElement(); if (name.startsWith(MarkPositionTag.PREFIX)) { session.removeAttribute(name); }// ww w . j a v a 2s . c om } }
From source file:org.apache.hupa.server.utils.SessionUtils.java
/** * Remove session attributes, it has to be done in the login and logout actions * @param session//from w ww .j av a 2s . c o m */ public static void cleanSessionAttributes(HttpSession session) { if (session != null) { @SuppressWarnings("rawtypes") Enumeration en = session.getAttributeNames(); ArrayList<String> toRemove = new ArrayList<String>(); while (en.hasMoreElements()) { String s = en.nextElement().toString(); if (s.startsWith("hupa")) { toRemove.add(s); } } for (String attr : toRemove) { session.removeAttribute(attr); } } }
From source file:gov.nih.nci.cabig.ctms.web.WebTools.java
@SuppressWarnings({ "unchecked" }) public static SortedMap<String, Object> sessionAttributesToMap(final HttpSession session) { if (session != null) { return namedAttributesToMap(session.getAttributeNames(), new AttributeAccessor() { public Object getAttribute(String name) { return session.getAttribute(name); }/*from w w w.j ava 2s . c om*/ }); } else { return emptySortedMap(); } }
From source file:net.big_oh.common.web.WebUtil.java
/** * A convenience method that counts number of attributes stored in a user's * {@link HttpSession}.// w w w .j a v a2s .c om * * @param session * An HttpSession object from any web application. * @return A count of the number of attributes stored in an HttpSession. */ public static int countAttributesInSession(HttpSession session) { int count = 0; Enumeration<?> attributeEnum = session.getAttributeNames(); while (attributeEnum.hasMoreElements()) { attributeEnum.nextElement(); count++; } return count; }
From source file:com.bsb.cms.commons.web.MossActionUtils.java
/** * ?? ???<s:debug></s:debug> * /* www. j av a 2s . c om*/ * @param req */ @SuppressWarnings("all") @Deprecated public static void print(HttpServletRequest req) { // Application Map<String, Object> parameters = new WeakHashMap<String, Object>(); // attributes in scope RequestParameter for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); String[] v = req.getParameterValues(name); if (v.length == 1) { if (v[0].equals("")) continue; parameters.put(name, v[0]); } else parameters.put(name, v); } // attributes in scope Request for (Enumeration e = req.getAttributeNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object v = req.getAttribute(name); parameters.put(name, v); } // attributes in scope Session HttpSession session = req.getSession(); for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object v = session.getAttribute(name); parameters.put(name, v); } Set keys = parameters.keySet(); Iterator it = keys.iterator(); String key; Object value; while (it.hasNext()) { key = (String) it.next(); value = parameters.get(key); System.out.println("key:" + key + ", value:" + value); } }
From source file:net.big_oh.common.web.WebUtil.java
/** * A convenience method that performs a reverse lookup to find all names * under which an attribute is stored in a user's {@link HttpSession}. * //ww w . ja v a 2 s . com * @param session * An HttpSession object from any web application. * @param sessionAttribute * Attribute name of interest. * @return A seet of all attribute names under which the sessionAttribute * parameter is stored in the session. */ public static Set<String> getNamesForSessionAttribute(HttpSession session, Object sessionAttribute) { Set<String> attributeNames = new HashSet<String>(); Enumeration<?> attributeEnum = session.getAttributeNames(); while (attributeEnum.hasMoreElements()) { String attributeName = (String) attributeEnum.nextElement(); if (sessionAttribute == session.getAttribute(attributeName)) { attributeNames.add(attributeName); } } return attributeNames; }
From source file:org.craftercms.core.util.HttpServletUtils.java
public static Map<String, Object> createSessionMap(HttpServletRequest request) { Map<String, Object> sessionMap = new HashMap<String, Object>(); HttpSession session = request.getSession(false); if (session != null) { for (Enumeration attributeNameEnum = session.getAttributeNames(); attributeNameEnum .hasMoreElements();) {//from w w w . jav a 2 s . c om String attributeName = (String) attributeNameEnum.nextElement(); sessionMap.put(attributeName, session.getAttribute(attributeName)); } } return sessionMap; }
From source file:org.soulwing.cas.support.ValidationUtils.java
/** * Removes all CAS-related session state for a given request * @param request the subject <code>HttpServletRequest</code> */// ww w . j a v a 2s .co m public static void removeSessionState(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session == null) { return; } ServiceValidationResponse validation = ValidationUtils.getServiceValidationResponse(request); Enumeration names = session.getAttributeNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(AuthenticatorConstants.ATTRIBUTE_PREFIX)) { log.debug("Removing attribute " + name + " from session"); session.removeAttribute(name); } } if (validation != null) { log.info("User " + validation.getUserName() + " has logged out"); } }
From source file:org.apache.axis.transport.http.AxisHTTPSessionListener.java
/** * Static method to destroy all ServiceLifecycle objects within an * Axis session.// www . j a v a 2s . co m */ static void destroySession(HttpSession session) { // Check for our marker so as not to do unneeded work if (session.getAttribute(AxisHttpSession.AXIS_SESSION_MARKER) == null) return; if (log.isDebugEnabled()) { log.debug("Got destroySession event : " + session); } Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { Object next = e.nextElement(); if (next instanceof ServiceLifecycle) { ((ServiceLifecycle) next).destroy(); } } }
From source file:edu.stanford.muse.webapp.Sessions.java
private static void removeAllAttributes(HttpSession session) { java.util.Enumeration keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if ("cacheDir".equals(key) || "userKey".equals(key) || "museEmailFetcher".equals(key)) // do not remove "cacheDir"/"userKey" which may be user-provided. // do not remove "museEmailFetcher" which is required for fetching. // TODO: this is getting ugly. maybe we should do the opposite = removing only certain attributes. continue; session.removeAttribute(key);/*ww w . j a va2 s.c o m*/ } }