List of usage examples for javax.servlet.http HttpSession getAttribute
public Object getAttribute(String name);
null
if no object is bound under the name. From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission.java
public static void clearEditSubmissionInSession(HttpSession sess, EditSubmission editSub) { if (sess == null) return;// w w w . j a v a2s .c om if (editSub == null) return; Map<String, EditSubmission> submissions = (Map<String, EditSubmission>) sess .getAttribute("EditSubmissions"); if (submissions == null) { throw new Error("EditSubmission: could not get a Map of EditSubmissions from the session."); } submissions.remove(editSub.editKey); }
From source file:com.huateng.ebank.business.common.GlobalInfo.java
public static GlobalInfo getFromRequest(HttpServletRequest request) throws CommonException { HttpSession httpSession = request.getSession(); GlobalInfo globalInfo = (GlobalInfo) httpSession.getAttribute(GlobalInfo.KEY_GLOBAL_INFO); if (log.isDebugEnabled()) { log.debug("session id = " + httpSession.getId()); }//from w ww .j a v a 2 s . c o m if (null != globalInfo) { setCurrentInstance(globalInfo); String oldSessionId = globalInfo.getSessionId(); String sessionId = httpSession.getId(); if (!sessionId.equals(oldSessionId)) { ExceptionUtil.throwCommonException("???, ?.", ErrorCode.ERROR_CODE_TLRNO_SESSION_BINDED); } globalInfo.setSessionId(sessionId); } return globalInfo; }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Returns a String which holds the selected categories for the result page of the new documents query.<p> * // w ww .ja v a 2 s.c o m * @param cms the CmsObject * @param request the HttpServletRequest * @param messageAll the localized message String used when all categories were selected * @return String with comma separated selected categories or localized "all" message */ public static String getCategories(CmsObject cms, HttpServletRequest request, String messageAll) { StringBuffer retValue = new StringBuffer(128); // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); if ("true".equals(paramAll)) { return messageAll; } else { List categories = getCategoryList((String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); Iterator i = categories.iterator(); while (i.hasNext()) { String path = (String) i.next(); try { retValue.append(cms.readPropertyObject(path, CmsCategory.CATEGORY_TITLE, false).getValue()); } catch (CmsException e) { // noop } if (i.hasNext()) { retValue.append(", "); } } // clear objects to release memory categories = null; i = null; } return retValue.toString(); }
From source file:com.alkacon.opencms.v8.documentcenter.NewDocumentsTree.java
/** * Returns a String which holds the selected categories for the result page of the new documents query.<p> * /*from ww w . jav a 2 s . c o m*/ * @param cms the CmsObject * @param request the HttpServletRequest * @param messageAll the localized message String used when all categories were selected * @return String with comma separated selected categories or localized "all" message */ public static String getCategories(CmsObject cms, HttpServletRequest request, String messageAll) { StringBuffer retValue = new StringBuffer(128); // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); if ("true".equals(paramAll)) { return messageAll; } else { List<String> categories = getCategoryList( (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); Iterator<String> i = categories.iterator(); while (i.hasNext()) { String path = i.next(); try { retValue.append(cms.readPropertyObject(path, CmsCategory.CATEGORY_TITLE, false).getValue()); } catch (CmsException e) { // noop } if (i.hasNext()) { retValue.append(", "); } } // clear objects to release memory categories = null; i = null; } return retValue.toString(); }
From source file:org.openmrs.module.diagnosiscapturerwanda.util.DiagnosisUtil.java
public static Location getLocationLoggedIn(HttpSession session) { return (Location) session.getAttribute(MetadataDictionary.SESSION_ATTRIBUTE_DIAGNOSIS_WORKSTATION_LOCATION); }
From source file:fr.paris.lutece.portal.service.util.AppPathService.java
/** * Return the url of the webapp, built from the request * * @param request The HttpServletRequest * @return strBase the webapp url//from w ww.ja v a 2s. co m */ public static String getBaseUrl(HttpServletRequest request) { if (request == null) { return getBaseUrl(); } String strBase; // Search for a Virtual Host Base Url defined in the request strBase = getVirtualHostBaseUrl(request); // If not found, get the base url from session if ((strBase == null) || strBase.equals(StringUtils.EMPTY)) { HttpSession session = request.getSession(false); if (session != null) { Object oBase = session.getAttribute(SESSION_BASE_URL); if (oBase != null) { strBase = (String) oBase; } } } // If not found, get the base url from the config.properties if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) { strBase = AppPropertiesService.getProperty(PROPERTY_BASE_URL); } if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) { // Dynamic base URL if not defined in the properties strBase = request.getScheme() + DOUBLE_POINTS + SLASH + SLASH + request.getServerName(); int nPort = request.getServerPort(); if (nPort != PORT_NUMBER_HTTP) { strBase += (DOUBLE_POINTS + nPort); } strBase += request.getContextPath(); } if (!strBase.endsWith(SLASH)) { strBase += SLASH; } return strBase; }
From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java
public static int sessionSize(HttpSession session) { int total = 0; try {// ww w . ja v a 2s . c o m java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(baos); Enumeration enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { String name = (String) enumeration.nextElement(); Object obj = session.getAttribute(name); oos.writeObject(obj); int size = baos.size(); total += size; logger.debug("The session name: " + name + " and the size is: " + size); } logger.debug("Total session size is: " + total); } catch (Exception e) { logger.error("Could not get the session size - " + ExceptionUtils.formatStackTrace(e)); } return total; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale.java
/** * Do we need to override the Locale in the current request? return the * first of these to be found://from w w w .j av a2s . c o m * <ul> * <li>The forced Locale in the servlet context</li> * <li>The selected Locale in the session</li> * <li>The first of the selectable Locales</li> * <li>null</li> * </ul> */ public static Locale getOverridingLocale(HttpServletRequest req) { HttpSession session = req.getSession(); ServletContext ctx = session.getServletContext(); Object ctxInfo = ctx.getAttribute(ATTRIBUTE_NAME); if (ctxInfo instanceof ContextSelectedLocale) { Locale forcedLocale = ((ContextSelectedLocale) ctxInfo).getForcedLocale(); if (forcedLocale != null) { log.debug("Found forced locale in the context: " + forcedLocale); return forcedLocale; } } Object sessionInfo = session.getAttribute(ATTRIBUTE_NAME); if (sessionInfo instanceof SessionSelectedLocale) { Locale selectedLocale = ((SessionSelectedLocale) sessionInfo).getSelectedLocale(); if (selectedLocale != null) { log.debug("Found selected locale in the session: " + selectedLocale); return selectedLocale; } } if (ctxInfo instanceof ContextSelectedLocale) { List<Locale> selectableLocales = ((ContextSelectedLocale) ctxInfo).getSelectableLocales(); if (selectableLocales != null && !selectableLocales.isEmpty()) { Locale defaultLocale = selectableLocales.get(0); log.debug("Using first selectable locale as default: " + defaultLocale); return defaultLocale; } } return null; }
From source file:org.carewebframework.security.spring.DesktopSecurityContextRepository.java
/** * Given a session and desktop id, returns Spring security context object. * //from w ww. j ava 2s . com * @param session Session where security context is stored. * @param dtid Id of desktop whose security context is sought. * @return SecurityContext The Spring security context. First looks for the desktop-based * security context. If not found, then looks for a session-based security context. This * call will convert a session-based security context to desktop-based if a desktop * identifier is found in the request object, a desktop-based security context does not * exist, and a session-based security context does exist. * @throws IllegalStateException if session is invalidated */ private static SecurityContext getSecurityContext(HttpSession session, String dtid) { final String key = getDesktopContextKey(dtid); if (key == null) { return getSecurityContext(session, false); } // Check for desktop-associated security context SecurityContext securityContext = (SecurityContext) session.getAttribute(key); // If no desktop security context, check session. if (securityContext == null) { securityContext = getSecurityContext(session, true); // If session security context found and this is a managed desktop, move into desktop. if (securityContext != null) { session.setAttribute(key, securityContext); } } return securityContext; }
From source file:eionet.cr.web.security.CRUser.java
/** * Returns the value of {@link #hasPermission(String, String, String)}, using the given ACL path, the given permission, and the * name of the user found in the given session. If no user found in session, the method will be called with user name set to * null.// www . j a v a 2s . co m * * @param session current session * @param aclPath full acl path * @param permission permission to be checked * @return true if user hsa the checked permission */ public static boolean hasPermission(HttpSession session, String aclPath, String permission) { // if no session given, simply return false if (session == null) { return false; } // get user object from session CRUser crUser = (CRUser) session.getAttribute(WebConstants.USER_SESSION_ATTR); // Return false if user is not logged in // if (crUser == null) { // return false; // } // get user name from user object, or set to null if user object null String userName = crUser == null ? null : crUser.getUserName(); // check if user with this name has this permission in this ACL return CRUser.hasPermission(userName, aclPath, permission); }