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:ilearn.orb.controller.AnnotationController.java
private static UserProfile retrieveProfile(HttpSession session, int userId) throws NumberFormatException, Exception { UserProfile p = null;//from w w w. java2 s .c o m if (userId < 0) { // p = HardcodedUsers.defaultProfile(selectedStudent.getId()); String json = UserServices.getDefaultProfile(HardcodedUsers.defaultProfileLanguage(userId)); if (json != null) p = new Gson().fromJson(json, UserProfile.class); } else { String json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()), session.getAttribute("auth").toString()); json = UserServices.getJsonProfile(userId, session.getAttribute("auth").toString()); if (json != null) p = new Gson().fromJson(json, UserProfile.class); } return p; }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;/*from w w w . j av a 2 s . c o m*/ String name; StringBuffer html = new StringBuffer(); //session HttpSession session = request.getSession(); html.append("<div><b>session:</b></div><ul>"); html.append(createLI("Id", session.getId())); html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString())); html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString())); //session:attributes e = session.getAttributeNames(); html.append("<li>attributes:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, String.valueOf(session.getAttribute(name)))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //request html.append("<div><b>request:</b></div><ul>"); html.append(createLI("URL", request.getRequestURL().toString())); html.append(createLI("QueryString", request.getQueryString())); html.append(createLI("Method", request.getMethod())); html.append(createLI("CharacterEncoding", request.getCharacterEncoding())); html.append(createLI("ContentType", request.getContentType())); html.append(createLI("Protocol", request.getProtocol())); html.append(createLI("RemoteAddr", request.getRemoteAddr())); html.append(createLI("RemoteHost", request.getRemoteHost())); html.append(createLI("RemotePort", request.getRemotePort() + "")); html.append(createLI("RemoteUser", request.getRemoteUser())); html.append(createLI("ServerName", request.getServerName())); html.append(createLI("ServletPath", request.getServletPath())); html.append(createLI("ServerPort", request.getServerPort() + "")); html.append(createLI("Scheme", request.getScheme())); html.append(createLI("LocalAddr", request.getLocalAddr())); html.append(createLI("LocalName", request.getLocalName())); html.append(createLI("LocalPort", request.getLocalPort() + "")); html.append(createLI("Locale", request.getLocale().toString())); //request:headers e = request.getHeaderNames(); html.append("<li>Headers:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getHeader(name))); } html.append("</ul></li>\r\n"); //request:parameters e = request.getParameterNames(); html.append("<li>Parameters:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getParameter(name))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //response html.append("<div><b>response:</b></div><ul>"); html.append(createLI("CharacterEncoding", response.getCharacterEncoding())); html.append(createLI("ContentType", response.getContentType())); html.append(createLI("BufferSize", response.getBufferSize() + "")); html.append(createLI("Locale", response.getLocale().toString())); html.append("<ul>\r\n"); return html; }
From source file:com.liferay.portlet.InvokerPortletImpl.java
public static Map<String, InvokerPortletResponse> getResponses(HttpSession session) { Map<String, InvokerPortletResponse> responses = (Map<String, InvokerPortletResponse>) session .getAttribute(WebKeys.CACHE_PORTLET_RESPONSES); if (responses == null) { responses = new ConcurrentHashMap<String, InvokerPortletResponse>(); session.setAttribute(WebKeys.CACHE_PORTLET_RESPONSES, responses); }//from w ww .j a v a 2s. c o m return responses; }
From source file:org.jruby.rack.mock.WebUtils.java
/** * Check the given request for a session attribute of the given name. * Returns null if there is no session or if the session has no such attribute. * Does not create a new session if none has existed before! * @param request current HTTP request// www.j a v a 2s . c o m * @param name the name of the session attribute * @return the value of the session attribute, or {@code null} if not found */ public static Object getSessionAttribute(HttpServletRequest request, String name) { Assert.notNull(request, "Request must not be null"); HttpSession session = request.getSession(false); return (session != null ? session.getAttribute(name) : null); }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Returns a list of new resources in the specified folder or category folder depending on the request parameters.<p> * /*w w w . ja v a2 s . co m*/ * @param cms the CmsObject to perform some operations * @param request the HttpServletRequest to get the needed request parameters * @return the list of new resources */ public static List getNewResources(CmsObject cms, HttpServletRequest request) { // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); String startFolder = cms.getRequestContext().getFolderUri(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); String paramStartDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_STARTDATE); String paramEndDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ENDDATE); // parse the date Strings to long long startDate = Long.parseLong(paramStartDate); long endDate = Long.parseLong(paramEndDate); // create list of categories if selected List selectedCategoryList = new ArrayList(); paramAll = (paramAll == null) ? "false" : paramAll; if (!"true".equals(paramAll)) { // search individual categories selectedCategoryList = getCategoryList( (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); if (selectedCategoryList.size() == 0) { return new ArrayList(0); } } String openedCategories = CategoryTree.getTreeInfo(cms, CategoryTree.C_USER_INFO_OPENED_CATEGORIES, request); List openedCategoryList = CategoryTree.commaStringToList(openedCategories, CategoryTree.C_LIST_SEPARATOR); return getNewResourceList(cms, startFolder, startDate, endDate, selectedCategoryList, openedCategoryList); }
From source file:com.alkacon.opencms.v8.documentcenter.NewDocumentsTree.java
/** * Returns a list of new resources in the specified folder or category folder depending on the request parameters.<p> * //from w w w .j a v a 2 s.co m * @param cms the CmsObject to perform some operations * @param request the HttpServletRequest to get the needed request parameters * @return the list of new resources */ public static List<CmsResource> getNewResources(CmsObject cms, HttpServletRequest request) { // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); String startFolder = cms.getRequestContext().getFolderUri(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); String paramStartDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_STARTDATE); String paramEndDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ENDDATE); // parse the date Strings to long long startDate = Long.parseLong(paramStartDate); long endDate = Long.parseLong(paramEndDate); // create list of categories if selected List<String> selectedCategoryList = new ArrayList<String>(); paramAll = (paramAll == null) ? "false" : paramAll; if (!"true".equals(paramAll)) { // search individual categories selectedCategoryList = getCategoryList( (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); if (selectedCategoryList.size() == 0) { return new ArrayList<CmsResource>(0); } } String openedCategories = CategoryTree.getTreeInfo(cms, CategoryTree.C_USER_INFO_OPENED_CATEGORIES, request); List<String> openedCategoryList = CategoryTree.commaStringToList(openedCategories, CategoryTree.C_LIST_SEPARATOR); return getNewResourceList(cms, startFolder, startDate, endDate, selectedCategoryList, openedCategoryList); }
From source file:com.xpn.xwiki.stats.impl.StatsUtil.java
/** * @param session the session.//from w w w. j av a 2s. co m * @return the visit object stored in the session. * @since 1.4M1 */ public static VisitStats getVisitFromSession(HttpSession session) { return (VisitStats) session.getAttribute(SESSPROP_VISITOBJECT); }
From source file:grails.plugin.springsecurity.SpringSecurityUtils.java
/** * Get the last auth exception.//from w w w . ja v a 2 s . c om * @param session the session * @return the exception */ public static Throwable getLastException(final HttpSession session) { return (Throwable) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); }
From source file:grails.plugin.springsecurity.SpringSecurityUtils.java
/** * Get the saved request from the session. * @param session the session//from w ww. j a va 2 s. c o m * @return the saved request */ public static SavedRequest getSavedRequest(final HttpSession session) { return (SavedRequest) session.getAttribute(SAVED_REQUEST); }
From source file:org.jruby.rack.mock.WebUtils.java
/** * Return the best available mutex for the given session: * that is, an object to synchronize on for the given session. * <p>Returns the session mutex attribute if available; usually, * this means that the HttpSessionMutexListener needs to be defined * in {@code web.xml}. Falls back to the HttpSession itself * if no mutex attribute found./* w ww . j a va 2 s.com*/ * <p>The session mutex is guaranteed to be the same object during * the entire lifetime of the session, available under the key defined * by the {@code SESSION_MUTEX_ATTRIBUTE} constant. It serves as a * safe reference to synchronize on for locking on the current session. * <p>In many cases, the HttpSession reference itself is a safe mutex * as well, since it will always be the same object reference for the * same active logical session. However, this is not guaranteed across * different servlet containers; the only 100% safe way is a session mutex. * @param session the HttpSession to find a mutex for * @return the mutex object (never {@code null}) * @see #SESSION_MUTEX_ATTRIBUTE * @see HttpSessionMutexListener */ public static Object getSessionMutex(HttpSession session) { Assert.notNull(session, "Session must not be null"); Object mutex = session.getAttribute(SESSION_MUTEX_ATTRIBUTE); if (mutex == null) { mutex = session; } return mutex; }