List of usage examples for javax.servlet.http HttpSession removeAttribute
public void removeAttribute(String name);
From source file:edu.hm.muse.controller.Logincontroller.java
@RequestMapping(value = "/adminlogin.secu", method = RequestMethod.POST) public ModelAndView doAdminLogin(@RequestParam(value = "mpwd", required = false) String mpwd, @RequestParam(value = "csrftoken", required = false) String csrfParam, HttpServletResponse response, HttpSession session) { if (null == mpwd || mpwd.isEmpty()) { throw new SuperFatalAndReallyAnnoyingException( "I can not process, because the requestparam mpwd is empty or null or something like this"); }//w w w . j a va2 s. c o m String sql = "select count (*) from M_ADMIN where mpwd = ?"; try { String digest = calculateSHA256(new ByteArrayInputStream(mpwd.getBytes("UTF8"))); int res = 0; res = jdbcTemplate.queryForInt(sql, new Object[] { digest }, new int[] { Types.VARCHAR }); Integer csrfTokenSess = (Integer) session.getAttribute("csrftoken"); if (res != 0 && csrfParam != null && !csrfParam.isEmpty() && csrfTokenSess != null) { Integer csrfParamToken = Integer.parseInt(csrfParam); if (csrfParamToken.intValue() == csrfTokenSess.intValue()) { SecureRandom random = new SecureRandom(); int token = random.nextInt(); session.setAttribute("user", "admin"); session.setAttribute("login", true); session.setAttribute("admintoken", token); response.addCookie(new Cookie("admintoken", String.valueOf(token))); session.removeAttribute("csrftoken"); return new ModelAndView("redirect:adminintern.secu"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (ClassCastException ccastEx) { ccastEx.printStackTrace(); } catch (NumberFormatException nfoEx) { nfoEx.printStackTrace(); } catch (DataAccessException e) { throw new SuperFatalAndReallyAnnoyingException( String.format("Sorry but %sis a bad grammar or has following problem %s", sql, e.getMessage())); } ModelAndView mv = returnToAdminLogin(session); return mv; }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Hanldes the processing for all of the artifact comment page targets. * //from www . jav a 2 s. c o m * @param model the UI model for the current request * @param session the HTTP session * @param redirectAttrs request attributes that must be available in case of a page redirect * @param newSession flag indicating that the user has requested to re-register in their session * @param commentForm the form used to supply the field values for the submitted comment * @param pubType the type of the publication to view (1.0/2.0) * @param isMembersOnlyPage flag indicating whether the page being viewed is a members-only page * @param targetPage the MVC name of the target page * @param submitCommentsUrl the URL location of the comment submission page * @return String */ private String doCommentArtifactPage(Model model, HttpSession session, RedirectAttributes redirectAttrs, boolean newSession, ArtifactCommentForm commentForm, PublicationType pubType, boolean isMembersOnlyPage, String targetPage, String submitCommentsUrl) { boolean commentSuccess = false; try { if (newSession) session.removeAttribute("registrantId"); Registrant registrant = getCurrentRegistrant(session); boolean processRegistrant = commentForm.isProcessForm() && (registrant == null); RegistrantForm registrantForm = commentForm.getRegistrantForm(); registrantForm.setProcessForm(processRegistrant); handleRegistrantInfo(registrantForm, model, session); registrant = (Registrant) model.asMap().get("registrant"); // If the registrant was created successfully, commit it and start a new // transaction for the comment if (processRegistrant && (registrant != null)) { DAOFactoryManager.getFactory().commitTransaction(); DAOFactoryManager.getFactory().beginTransaction(); registrant = getCurrentRegistrant(session); } if (commentForm.isProcessForm()) { commentSuccess = addArtifactComment(commentForm, registrant, model, session); } if (commentSuccess) { if (isMembersOnlyPage) { targetPage = "redirect:/specifications/members/CommentThankYou.html"; } else { targetPage = "redirect:/specifications/CommentThankYou.html"; } redirectAttrs.addAttribute("submitCommentsUrl", submitCommentsUrl); model.asMap().clear(); } else { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); Publication publication = pDao.getLatestPublication(pubType, getAllowedStates(isMembersOnlyPage)); List<PublicationItem> publicationItems = new ArrayList<>(); if (publication != null) { publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.ARTIFACT)); } model.addAttribute("publication", publication); model.addAttribute("publicationItems", publicationItems); model.addAttribute("commentTypes", Arrays.asList(CommentType.values())); setupPublicationCheck(model, isMembersOnlyPage, pubType); } model.addAttribute("submitCommentsUrl", submitCommentsUrl); commentForm.setProcessForm(true); } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Hanldes the processing for all of the schema comment page targets. * //from w w w. ja v a 2 s.c om * @param model the UI model for the current request * @param session the HTTP session * @param redirectAttrs request attributes that must be available in case of a page redirect * @param newSession flag indicating that the user has requested to re-register in their session * @param commentForm the form used to supply the field values for the submitted comment * @param pubType the type of the publication to view (1.0/2.0) * @param isMembersOnlyPage flag indicating whether the page being viewed is a members-only page * @param targetPage the MVC name of the target page * @param submitCommentsUrl the URL location of the comment submission page * @return String */ private String doCommentSpecPage(Model model, HttpSession session, RedirectAttributes redirectAttrs, boolean newSession, SchemaCommentForm commentForm, PublicationType pubType, boolean isMembersOnlyPage, String targetPage, String submitCommentsUrl) { boolean commentSuccess = false; try { if (newSession) session.removeAttribute("registrantId"); Registrant registrant = getCurrentRegistrant(session); boolean processRegistrant = commentForm.isProcessForm() && (registrant == null); RegistrantForm registrantForm = commentForm.getRegistrantForm(); registrantForm.setProcessForm(processRegistrant); handleRegistrantInfo(registrantForm, model, session); registrant = (Registrant) model.asMap().get("registrant"); // If the registrant was created successfully, commit it and start a new // transaction for the comment if (processRegistrant && (registrant != null)) { DAOFactoryManager.getFactory().commitTransaction(); DAOFactoryManager.getFactory().beginTransaction(); registrant = getCurrentRegistrant(session); } if (commentForm.isProcessForm()) { commentSuccess = addSchemaComment(commentForm, registrant, model, session); } if (commentSuccess) { if (isMembersOnlyPage) { targetPage = "redirect:/specifications/members/CommentThankYou.html"; } else { targetPage = "redirect:/specifications/CommentThankYou.html"; } redirectAttrs.addAttribute("submitCommentsUrl", submitCommentsUrl); model.asMap().clear(); } else { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); Publication publication = pDao.getLatestPublication(pubType, getAllowedStates(isMembersOnlyPage)); List<PublicationItem> publicationItems = new ArrayList<>(); if (publication != null) { publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.WSDL)); publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.XML_SCHEMA)); publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.JSON_SCHEMA)); } model.addAttribute("publication", publication); model.addAttribute("publicationItems", publicationItems); model.addAttribute("commentTypes", Arrays.asList(CommentType.values())); setupPublicationCheck(model, isMembersOnlyPage, pubType); } model.addAttribute("submitCommentsUrl", submitCommentsUrl); commentForm.setProcessForm(true); } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.mitre.openid.connect.filter.AuthorizationRequestFilter.java
/** * //from ww w. j av a 2s . c o m */ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(); // skip everything that's not an authorize URL if (!requestMatcher.matches(request)) { chain.doFilter(req, res); return; } try { // we have to create our own auth request in order to get at all the parmeters appropriately AuthorizationRequest authRequest = null; ClientDetailsEntity client = null; authRequest = authRequestFactory .createAuthorizationRequest(createRequestMap(request.getParameterMap())); if (!Strings.isNullOrEmpty(authRequest.getClientId())) { client = clientService.loadClientByClientId(authRequest.getClientId()); } // save the login hint to the session // but first check to see if the login hint makes any sense String loginHint = loginHintExtracter.extractHint((String) authRequest.getExtensions().get(LOGIN_HINT)); if (!Strings.isNullOrEmpty(loginHint)) { session.setAttribute(LOGIN_HINT, loginHint); } else { session.removeAttribute(LOGIN_HINT); } if (authRequest.getExtensions().get(PROMPT) != null) { // we have a "prompt" parameter String prompt = (String) authRequest.getExtensions().get(PROMPT); List<String> prompts = Splitter.on(PROMPT_SEPARATOR).splitToList(Strings.nullToEmpty(prompt)); if (prompts.contains(PROMPT_NONE)) { // see if the user's logged in Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { // user's been logged in already (by session management) // we're OK, continue without prompting chain.doFilter(req, res); } else { logger.info("Client requested no prompt"); // user hasn't been logged in, we need to "return an error" if (client != null && authRequest.getRedirectUri() != null) { // if we've got a redirect URI then we'll send it String url = redirectResolver.resolveRedirect(authRequest.getRedirectUri(), client); try { URIBuilder uriBuilder = new URIBuilder(url); uriBuilder.addParameter(ERROR, LOGIN_REQUIRED); if (!Strings.isNullOrEmpty(authRequest.getState())) { uriBuilder.addParameter(STATE, authRequest.getState()); // copy the state parameter if one was given } response.sendRedirect(uriBuilder.toString()); return; } catch (URISyntaxException e) { logger.error("Can't build redirect URI for prompt=none, sending error instead", e); response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied"); return; } } response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied"); return; } } else if (prompts.contains(PROMPT_LOGIN)) { // first see if the user's already been prompted in this session if (session.getAttribute(PROMPTED) == null) { // user hasn't been PROMPTED yet, we need to check session.setAttribute(PROMPT_REQUESTED, Boolean.TRUE); // see if the user's logged in Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { // user's been logged in already (by session management) // log them out and continue SecurityContextHolder.getContext().setAuthentication(null); chain.doFilter(req, res); } else { // user hasn't been logged in yet, we can keep going since we'll get there chain.doFilter(req, res); } } else { // user has been PROMPTED, we're fine // but first, undo the prompt tag session.removeAttribute(PROMPTED); chain.doFilter(req, res); } } else { // prompt parameter is a value we don't care about, not our business chain.doFilter(req, res); } } else if (authRequest.getExtensions().get(MAX_AGE) != null || (client != null && client.getDefaultMaxAge() != null)) { // default to the client's stored value, check the string parameter Integer max = (client != null ? client.getDefaultMaxAge() : null); String maxAge = (String) authRequest.getExtensions().get(MAX_AGE); if (maxAge != null) { max = Integer.parseInt(maxAge); } if (max != null) { Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP); Date now = new Date(); if (authTime != null) { long seconds = (now.getTime() - authTime.getTime()) / 1000; if (seconds > max) { // session is too old, log the user out and continue SecurityContextHolder.getContext().setAuthentication(null); } } } chain.doFilter(req, res); } else { // no prompt parameter, not our business chain.doFilter(req, res); } } catch (InvalidClientException e) { // we couldn't find the client, move on and let the rest of the system catch the error chain.doFilter(req, res); } }
From source file:edu.ucsd.library.xdre.web.ExcelImportController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String ds = request.getParameter("ts"); String collectionId = request.getParameter("category"); String unit = request.getParameter("unit"); String message = request.getParameter("message"); String fileStore = request.getParameter("fs"); String licenseBeginDate = request.getParameter("licenseBeginDate"); String licenseEndDate = request.getParameter("licenseEndDate"); HttpSession session = request.getSession(); DAMSClient damsClient = null;//from ww w .ja v a2 s .c o m Map dataMap = new HashMap(); try { // initiate column name and control values for validation String columns = request.getServletContext().getRealPath("files/valid_columns.xlsx"); String cvs = request.getServletContext().getRealPath("files/valid_cv_values.xlsx"); try { ExcelSource.initControlValues(new File(columns), new File(cvs)); } catch (Exception e) { e.printStackTrace(); } if (ds == null) ds = Constants.DEFAULT_TRIPLESTORE; damsClient = new DAMSClient(Constants.DAMS_STORAGE_URL); damsClient.setTripleStore(ds); Map<String, String> collectionMap = damsClient.listCollections(); Map<String, String> unitsMap = damsClient.listUnits(); List<String> tsSrcs = damsClient.listTripleStores(); List<String> fsSrcs = damsClient.listFileStores(); String fsDefault = damsClient.defaultFilestore(); if (fileStore == null || fileStore.length() == 0) fileStore = fsDefault; message = (!StringUtils.isBlank(message) || StringUtils.isBlank(collectionId)) ? message : (String) session.getAttribute("message"); session.removeAttribute("message"); JSONArray accessValues = new JSONArray(); accessValues.addAll(Arrays.asList(RecordUtil.ACCESS_VALUES)); Map<String, String> countryCodes = MarcModsImportController.getCountryCodes(request); dataMap.put("categories", collectionMap); dataMap.put("category", collectionId); dataMap.put("units", unitsMap); dataMap.put("unit", unit); dataMap.put("message", message); dataMap.put("triplestore", ds); dataMap.put("triplestores", tsSrcs); dataMap.put("filestores", fsSrcs); dataMap.put("filestore", fileStore); dataMap.put("filestoreDefault", fsDefault); dataMap.put("copyrightStatus", RecordUtil.COPYRIGHT_VALUES); dataMap.put("program", RecordUtil.PROGRAM_VALUES); dataMap.put("accessOverride", accessValues); dataMap.put("licenseBeginDate", licenseBeginDate); dataMap.put("licenseEndDate", licenseEndDate); dataMap.put("countryCodes", countryCodes); } catch (Exception e) { e.printStackTrace(); message += e.getMessage(); } finally { if (damsClient != null) damsClient.close(); } return new ModelAndView("excelImport", "model", dataMap); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.json.GetEntitiesByVClassContinuation.java
@Override protected JSONArray process() throws ServletException { log.debug("in getEntitiesByVClassContinuation()"); String resKey = vreq.getParameter("resultKey"); if (resKey == null) throw new ServletException("Could not get resultKey"); HttpSession session = vreq.getSession(); if (session == null) throw new ServletException("there is no session to get the pervious results from"); @SuppressWarnings("unchecked") List<Individual> entsInVClass = (List<Individual>) session.getAttribute(resKey); if (entsInVClass == null) throw new ServletException("Could not find List<Individual> for resultKey " + resKey); List<Individual> entsToReturn = new ArrayList<Individual>(REPLY_SIZE); boolean more = false; int count = 0; /* we have a large number of items to send back so we need to stash the list in the session scope */ if (entsInVClass.size() > REPLY_SIZE) { more = true;/*from ww w .j a va2 s . c o m*/ ListIterator<Individual> entsFromVclass = entsInVClass.listIterator(); while (entsFromVclass.hasNext() && count <= REPLY_SIZE) { entsToReturn.add(entsFromVclass.next()); entsFromVclass.remove(); count++; } if (log.isDebugEnabled()) log.debug("getEntitiesByVClassContinuation(): Creating reply with continue token," + " sending in this reply: " + count + ", remaing to send: " + entsInVClass.size()); } else { //send out reply with no continuation entsToReturn = entsInVClass; count = entsToReturn.size(); session.removeAttribute(resKey); if (log.isDebugEnabled()) log.debug("getEntitiesByVClassContinuation(): sending " + count + " Ind without continue token"); } //put all the entities on the JSON array JSONArray ja = individualsToJson(entsToReturn); //put the responseGroup number on the end of the JSON array if (more) { try { JSONObject obj = new JSONObject(); obj.put("resultGroup", "true"); obj.put("size", count); StringBuffer nextUrlStr = vreq.getRequestURL(); nextUrlStr.append("?").append("getEntitiesByVClass").append("=1&").append("resultKey=") .append(resKey); obj.put("nextUrl", nextUrlStr.toString()); ja.put(obj); } catch (JSONException je) { throw new ServletException(je.getMessage()); } } log.debug("done with getEntitiesByVClassContinuation()"); return ja; }
From source file:net.testdriven.psiprobe.controllers.sessions.ListSessionsController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false) && SecurityUtils.hasAttributeValueRole(getServletContext(), request); SessionSearchInfo searchInfo = new SessionSearchInfo(); searchInfo.setSearchAction(StringUtils.trimToNull( ServletRequestUtils.getStringParameter(request, "searchAction", SessionSearchInfo.ACTION_NONE))); HttpSession sess = request.getSession(); if (searchInfo.isApply()) { searchInfo.setSessionId(/*from w w w . j av a2s . co m*/ StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchSessionId"))); searchInfo.setLastIP( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchLastIP"))); searchInfo.setAgeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeFrom"))); searchInfo.setAgeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeTo"))); searchInfo.setIdleTimeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeFrom"))); searchInfo.setIdleTimeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeTo"))); searchInfo.setAttrName( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAttrName"))); if (sess != null) { sess.setAttribute(SessionSearchInfo.SESS_ATTR_NAME, searchInfo); } } else if (sess != null) { if (searchInfo.isClear()) { sess.removeAttribute(SessionSearchInfo.SESS_ATTR_NAME); } else { SessionSearchInfo ss = (SessionSearchInfo) sess.getAttribute(SessionSearchInfo.SESS_ATTR_NAME); if (ss != null) { searchInfo = ss; } } } // context is not specified we'll retrieve all sessions of the container List<Context> ctxs; if (context == null) { ctxs = getContainerWrapper().getTomcatContainer().findContexts(); } else { ctxs = new ArrayList<>(); ctxs.add(context); } List<ApplicationSession> sessionList = new ArrayList<>(); for (Context ctx : ctxs) { if (ctx != null && ctx.getManager() != null && (!searchInfo.isApply() || searchInfo.isUseSearch())) { Session[] sessions = ctx.getManager().findSessions(); for (Session session : sessions) { ApplicationSession appSession = ApplicationUtils.getApplicationSession(session, calcSize, searchInfo.isUseAttr()); if (appSession != null && matchSession(appSession, searchInfo)) { if (ctx.getName() != null) { appSession.setApplicationName(ctx.getName().length() > 0 ? ctx.getName() : "/"); } sessionList.add(appSession); } } } } if (sessionList.isEmpty() && searchInfo.isApply()) { synchronized (sess) { populateSearchMessages(searchInfo); } } ModelAndView modelAndView = new ModelAndView(getViewName(), "sessions", sessionList); modelAndView.addObject("searchInfo", searchInfo); return modelAndView; }
From source file:com.googlecode.psiprobe.controllers.sessions.ListSessionsController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false) && SecurityUtils.hasAttributeValueRole(getServletContext(), request); SessionSearchInfo searchInfo = new SessionSearchInfo(); searchInfo.setSearchAction(StringUtils.trimToNull( ServletRequestUtils.getStringParameter(request, "searchAction", SessionSearchInfo.ACTION_NONE))); HttpSession sess = request.getSession(); if (searchInfo.isApply()) { searchInfo.setSessionId(/*from w ww. j a v a 2 s. c o m*/ StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchSessionId"))); searchInfo.setLastIP( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchLastIP"))); searchInfo.setAgeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeFrom"))); searchInfo.setAgeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeTo"))); searchInfo.setIdleTimeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeFrom"))); searchInfo.setIdleTimeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeTo"))); searchInfo.setAttrName( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAttrName"))); if (sess != null) { sess.setAttribute(SessionSearchInfo.SESS_ATTR_NAME, searchInfo); } } else if (sess != null) { if (searchInfo.isClear()) { sess.removeAttribute(SessionSearchInfo.SESS_ATTR_NAME); } else { SessionSearchInfo ss = (SessionSearchInfo) sess.getAttribute(SessionSearchInfo.SESS_ATTR_NAME); if (ss != null) { searchInfo = ss; } } } // context is not specified we'll retrieve all sessions of the container List ctxs; if (context == null) { ctxs = getContainerWrapper().getTomcatContainer().findContexts(); } else { ctxs = new ArrayList(); ctxs.add(context); } List sessionList = new ArrayList(); for (Iterator it = ctxs.iterator(); it.hasNext();) { Context ctx = (Context) it.next(); if (ctx != null && ctx.getManager() != null && (!searchInfo.isApply() || searchInfo.isUseSearch())) { Session[] sessions = ctx.getManager().findSessions(); for (int i = 0; i < sessions.length; i++) { Session session = sessions[i]; ApplicationSession appSession = ApplicationUtils.getApplicationSession(session, calcSize, searchInfo.isUseAttr()); if (appSession != null && matchSession(appSession, searchInfo)) { if (ctx.getName() != null) { appSession.setApplicationName(ctx.getName().length() > 0 ? ctx.getName() : "/"); } sessionList.add(appSession); } } } } if (sessionList.isEmpty() && searchInfo.isApply()) { synchronized (sess) { populateSearchMessages(searchInfo); } } ModelAndView modelAndView = new ModelAndView(getViewName(), "sessions", sessionList); modelAndView.addObject("searchInfo", searchInfo); return modelAndView; }
From source file:com.exilant.exility.core.HtmlRequestHandler.java
/*** * Save grids that are to be paginated into session. replace these grids in * outData with just the first page.//ww w.j av a2s . co m * * @param req * @param inData * @param outData */ private void savePaginationData(HttpServletRequest req, ServiceData inData, ServiceData outData) { ArrayList<String> gridNames = new ArrayList<String>(); for (String name : outData.grids.keySet()) { gridNames.add(name); } HttpSession session = req.getSession(); for (String name : gridNames) { String pageSize = inData.getValue(name + HtmlRequestHandler.PAGE_SIZE); if (pageSize == null) { continue; } int ps = Integer.parseInt(pageSize); String[][] grid = outData.grids.get(name); int n = grid.length - 1; // Spit.out(name + " has " + n + " rows while page size is " + ps); if (n <= ps) { session.removeAttribute(name); continue; } session.setAttribute(name, grid); String[][] newGrid = new String[ps + 1][]; newGrid[0] = grid[0]; for (int i = 1; i < newGrid.length; i++) { newGrid[i] = grid[i]; } outData.addGrid(name, newGrid); outData.addValue(name + "TotalRows", Integer.toString(n)); // Spit.out("TotalRows for table " + name + " set to " + // outData.getValue(name + "TotalRows") ); } }
From source file:psiprobe.controllers.sessions.ListSessionsController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false) && SecurityUtils.hasAttributeValueRole(getServletContext(), request); SessionSearchInfo searchInfo = new SessionSearchInfo(); searchInfo.setSearchAction(StringUtils.trimToNull( ServletRequestUtils.getStringParameter(request, "searchAction", SessionSearchInfo.ACTION_NONE))); HttpSession sess = request.getSession(false); if (searchInfo.isApply()) { searchInfo.setSessionId(//from w w w . j a v a 2 s . com StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchSessionId"))); searchInfo.setLastIp( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchLastIP"))); searchInfo.setAgeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeFrom"))); searchInfo.setAgeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAgeTo"))); searchInfo.setIdleTimeFrom( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeFrom"))); searchInfo.setIdleTimeTo( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchIdleTimeTo"))); searchInfo.setAttrName( StringUtils.trimToNull(ServletRequestUtils.getStringParameter(request, "searchAttrName"))); if (sess != null) { sess.setAttribute(SessionSearchInfo.SESS_ATTR_NAME, searchInfo); } } else if (sess != null) { if (searchInfo.isClear()) { sess.removeAttribute(SessionSearchInfo.SESS_ATTR_NAME); } else { SessionSearchInfo ss = (SessionSearchInfo) sess.getAttribute(SessionSearchInfo.SESS_ATTR_NAME); if (ss != null) { searchInfo = ss; } } } // context is not specified we'll retrieve all sessions of the container List<Context> ctxs; if (context == null) { ctxs = getContainerWrapper().getTomcatContainer().findContexts(); } else { ctxs = new ArrayList<>(); ctxs.add(context); } List<ApplicationSession> sessionList = new ArrayList<>(); for (Context ctx : ctxs) { if (ctx != null && ctx.getManager() != null && (!searchInfo.isApply() || searchInfo.isUseSearch())) { Session[] sessions = ctx.getManager().findSessions(); for (Session session : sessions) { ApplicationSession appSession = ApplicationUtils.getApplicationSession(session, calcSize, searchInfo.isUseAttr()); if (appSession != null && matchSession(appSession, searchInfo)) { if (ctx.getName() != null) { appSession.setApplicationName(ctx.getName().length() > 0 ? ctx.getName() : "/"); } sessionList.add(appSession); } } } } if (sessionList.isEmpty() && searchInfo.isApply()) { synchronized (sess) { populateSearchMessages(searchInfo); } } ModelAndView modelAndView = new ModelAndView(getViewName(), "sessions", sessionList); modelAndView.addObject("searchInfo", searchInfo); return modelAndView; }