List of usage examples for javax.servlet.http HttpSession removeAttribute
public void removeAttribute(String name);
From source file:com.globalsight.everest.webapp.pagehandler.administration.localepairs.LocalePairImportHandler.java
public void invokePageHandler(WebPageDescriptor p_pageDescriptor, HttpServletRequest p_request, HttpServletResponse p_response, ServletContext p_context) throws ServletException, IOException, EnvoyServletException { HttpSession session = p_request.getSession(false); String sessionId = session.getId(); SessionManager sessionMgr = (SessionManager) session.getAttribute(WebAppConstants.SESSION_MANAGER); String companyId = CompanyThreadLocal.getInstance().getValue(); boolean isSuperAdmin = ((Boolean) session.getAttribute(WebAppConstants.IS_SUPER_ADMIN)).booleanValue(); String action = p_request.getParameter("action"); try {/* w w w .j a va 2 s . c o m*/ if (LocalePairConstants.IMPORT.equals(action)) { if (isSuperAdmin) { importLocalePair(p_request); p_request.setAttribute("currentId", companyId); } } else if ("startUpload".equals(action)) { File uploadedFile = this.uploadFile(p_request); if (isSuperAdmin) { String importToCompId = p_request.getParameter("companyId"); session.setAttribute("importToCompId", importToCompId); } session.setAttribute("uploading_filter", uploadedFile); } else if ("doImport".equals(action)) { int count = 0; if (sessionMgr.getAttribute("count") != null) { count = (Integer) sessionMgr.getAttribute("count"); if (count == 1) { count++; sessionMgr.setAttribute("count", count); } } else { count++; sessionMgr.setAttribute("count", count); } if (session.getAttribute("uploading_filter") != null) { filter_percentage_map.clear();// .remove(sessionId); filter_error_map.clear();// .remove(sessionId); File uploadedFile = (File) session.getAttribute("uploading_filter"); String importToCompId = (String) session.getAttribute("importToCompId"); session.removeAttribute("importToCompId"); session.removeAttribute("uploading_filter"); DoImport imp = new DoImport(sessionId, uploadedFile, companyId, importToCompId); imp.start(); } else { logger.error("No uploaded user info file."); } } else if ("refreshProgress".equals(action)) { this.refreshProgress(p_request, p_response, sessionId); return; } } catch (RemoteException re) { throw new EnvoyServletException(EnvoyServletException.EX_GENERAL, re); } catch (GeneralException ge) { throw new EnvoyServletException(EnvoyServletException.EX_GENERAL, ge); } super.invokePageHandler(p_pageDescriptor, p_request, p_response, p_context); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.permission.PermissionGroupsHandler.java
/** * Updates a PermissionGroup.//from www . ja v a 2s. c o m */ private void savePermissionGroup(HttpSession p_session, HttpServletRequest p_request) throws RemoteException, NamingException, GeneralException { SessionManager sessionMgr = (SessionManager) p_session.getAttribute(WebAppConstants.SESSION_MANAGER); PermissionGroupImpl permGroup = (PermissionGroupImpl) sessionMgr.getAttribute("permGroup"); // Update data in permission group object PermissionHelper.saveBasicInfo(permGroup, p_request); // Update in db Permission.getPermissionManager().updatePermissionGroup(permGroup); // Update users in permission group PermissionHelper.updateUsers(permGroup, p_request); String activityDashboardViewPermissionCheckedOrNot = (String) p_session .getAttribute(Permission.ACTIVITY_DASHBOARD_VIEW); if (activityDashboardViewPermissionCheckedOrNot != null) { final Collection<String> usersInPermGroup = Permission.getPermissionManager() .getAllUsersForPermissionGroup(permGroup.getId()); // In order to refresh the activity dashboard with possible // incorrect numbers if ("unchecked".equals(activityDashboardViewPermissionCheckedOrNot)) { // clean up the user owned records in TASK_INTERIM table for all // users in this permission group when the permission is // unchecked for (String userId : usersInPermGroup) { TaskInterimPersistenceAccessor.deleteInterimUser(userId); } } else if ("checked".equals(activityDashboardViewPermissionCheckedOrNot)) { // re-create the data in TASK_INTERIM table when the permission // is checked again Runnable runnable = new Runnable() { public void run() { for (String userId : usersInPermGroup) { if (!TaskInterimPersistenceAccessor.isTriggered(userId)) { TaskInterimPersistenceAccessor.initializeUserTasks(userId); } } } }; Thread t = new MultiCompanySupportedThread(runnable); t.start(); } p_session.removeAttribute(Permission.ACTIVITY_DASHBOARD_VIEW); } }
From source file:com.uniquesoft.uidl.servlet.UploadServlet.java
/** * This method parses the submit action, puts in session a listener where the * progress status is updated, and eventually stores the received data in * the user session.//w ww. ja v a2 s.c o m * * returns null in the case of success or a string with the error * */ @SuppressWarnings("unchecked") protected String parsePostRequest(HttpServletRequest request, HttpServletResponse response) { try { String delay = request.getParameter(PARAM_DELAY); uploadDelay = Integer.parseInt(delay); } catch (Exception e) { } HttpSession session = request.getSession(); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received."); AbstractUploadListener listener = getCurrentListener(request); if (listener != null) { if (listener.isFrozen() || listener.isCanceled() || listener.getPercent() >= 100) { removeCurrentListener(request); } else { String error = getMessage("busy"); logger.error("UPLOAD-SERVLET (" + session.getId() + ") " + error); return error; } } // Create a file upload progress listener, and put it in the user session, // so the browser can use ajax to query status of the upload process listener = createNewListener(request); List<FileItem> uploadedItems; try { // Call to a method which the user can override checkRequest(request); // Create the factory used for uploading files, FileItemFactory factory = getFileItemFactory(getContentLength(request)); ServletFileUpload uploader = new ServletFileUpload(factory); uploader.setSizeMax(maxSize); uploader.setProgressListener(listener); // Receive the files logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsing HTTP POST request "); uploadedItems = uploader.parseRequest(request); session.removeAttribute(getSessionLastFilesKey(request)); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsed request, " + uploadedItems.size() + " items received."); // Received files are put in session List<FileItem> sessionFiles = getMySessionFileItems(request); if (sessionFiles == null) { sessionFiles = new ArrayList<FileItem>(); } String error = ""; if (uploadedItems.size() > 0) { // We append to the field name the sequence of the uploaded file int cnt = 0; for (FileItem i : uploadedItems) { if (!i.isFormField()) { i.setFieldName(i.getFieldName().replace(UConsts.MULTI_SUFFIX, "") + "-" + cnt++); } } sessionFiles.addAll(uploadedItems); String msg = ""; for (FileItem i : sessionFiles) { msg += i.getFieldName() + " => " + i.getName() + "(" + i.getSize() + " bytes),"; } logger.debug("UPLOAD-SERVLET (" + session.getId() + ") puting items in session: " + msg); session.setAttribute(getSessionFilesKey(request), sessionFiles); session.setAttribute(getSessionLastFilesKey(request), uploadedItems); } else { logger.error("UPLOAD-SERVLET (" + session.getId() + ") error NO DATA received "); error += getMessage("no_data"); } return error.length() > 0 ? error : null; // So much silly questions in the list about this issue. } catch (LinkageError e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Exception: " + e.getMessage() + "\n" + stackTraceToString(e)); RuntimeException ex = new UploadActionException(getMessage("restricted", e.getMessage()), e); listener.setException(ex); throw ex; } catch (SizeLimitExceededException e) { RuntimeException ex = new UploadSizeLimitException(e.getPermittedSize(), e.getActualSize()); listener.setException(ex); throw ex; } catch (UploadSizeLimitException e) { listener.setException(e); throw e; } catch (UploadCanceledException e) { listener.setException(e); throw e; } catch (UploadTimeoutException e) { listener.setException(e); throw e; } catch (Throwable e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Unexpected Exception -> " + e.getMessage() + "\n" + stackTraceToString(e)); e.printStackTrace(); RuntimeException ex = new UploadException(e); listener.setException(ex); throw ex; } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.users.UserImportHandler.java
public void invokePageHandler(WebPageDescriptor pageDescriptor, HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException, EnvoyServletException { // permission check HttpSession session = request.getSession(false); PermissionSet userPerms = (PermissionSet) session.getAttribute(WebAppConstants.PERMISSIONS); if (!userPerms.getPermissionFor(Permission.USERS_IMPORT)) { logger.error("User doesn't have the permission to visit this page."); response.sendRedirect("/globalsight/ControlServlet?"); return;//from www.j ava2 s .c o m } String sessionId = session.getId(); SessionManager sessionMgr = (SessionManager) session.getAttribute(SESSION_MANAGER); User user = (User) sessionMgr.getAttribute(WebAppConstants.USER); String action = request.getParameter("action"); if (StringUtils.isNotEmpty(action)) { if (action.equals("startUpload")) { File uploadedFile = this.uploadFile(request); session.setAttribute("uploading_user", uploadedFile); int ignoreOrOverwriteFlag = 0;// ignore as default if ("1".equals(request.getParameter("ifUserExistedFlag"))) { ignoreOrOverwriteFlag = 1;//overwrite } session.setAttribute("ignoreOrOverwriteFlag", ignoreOrOverwriteFlag); } else if (action.equals("doImport")) { if (session.getAttribute("uploading_user") != null) { user_percentage_map.remove(sessionId); user_error_map.remove(sessionId); File uploadedFile = (File) session.getAttribute("uploading_user"); session.removeAttribute("uploading_user"); int flag = (Integer) session.getAttribute("ignoreOrOverwriteFlag"); DoImport imp = new DoImport(sessionId, uploadedFile, user, CompanyThreadLocal.getInstance().getValue(), flag); imp.start(); } else { logger.error("No uploaded user info file."); } } else if (action.equals("refreshProgress")) { this.refreshProgress(request, response, sessionId); return; } } ResourceBundle bundle = PageHandler.getBundle(session); setLable(request, bundle); super.invokePageHandler(pageDescriptor, request, response, context); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.mtprofile.MTProfileImportHandler.java
public void invokePageHandler(WebPageDescriptor p_pageDescriptor, HttpServletRequest p_request, HttpServletResponse p_response, ServletContext p_context) throws ServletException, IOException, EnvoyServletException { HttpSession session = p_request.getSession(false); String sessionId = session.getId(); SessionManager sessionMgr = (SessionManager) session.getAttribute(WebAppConstants.SESSION_MANAGER); String currentCompanyId = CompanyThreadLocal.getInstance().getValue(); boolean isSuperAdmin = ((Boolean) session.getAttribute(WebAppConstants.IS_SUPER_ADMIN)).booleanValue(); String action = p_request.getParameter(MTProfileConstants.ACTION); try {/* w ww.j a v a 2s. c o m*/ if (MTProfileConstants.IMPORT_ACTION.equals(action)) { if (isSuperAdmin) { importMTProfile(p_request); p_request.setAttribute("currentId", currentCompanyId); } } else if ("startUpload".equals(action)) { File uploadedFile = this.uploadFile(p_request); if (isSuperAdmin) { String importToCompId = p_request.getParameter("companyId"); session.setAttribute("importToCompId", importToCompId); } session.setAttribute("uploading_filter", uploadedFile); } else if ("doImport".equals(action)) { int count = 0; if (sessionMgr.getAttribute("count") != null) { count = (Integer) sessionMgr.getAttribute("count"); if (count == 1) { count++; sessionMgr.setAttribute("count", count); } } else { count++; sessionMgr.setAttribute("count", count); } if (session.getAttribute("uploading_filter") != null) { filter_percentage_map.clear();// .remove(sessionId); filter_error_map.clear();// .remove(sessionId); File uploadedFile = (File) session.getAttribute("uploading_filter"); String importToCompId = (String) session.getAttribute("importToCompId"); session.removeAttribute("importToCompId"); session.removeAttribute("uploading_filter"); DoImport imp = new DoImport(sessionId, uploadedFile, currentCompanyId, importToCompId); imp.start(); } else { logger.error("No uploaded user info file."); } } else if ("refreshProgress".equals(action)) { this.refreshProgress(p_request, p_response, sessionId); return; } } catch (RemoteException re) { throw new EnvoyServletException(EnvoyServletException.EX_GENERAL, re); } catch (GeneralException ge) { throw new EnvoyServletException(EnvoyServletException.EX_GENERAL, ge); } super.invokePageHandler(p_pageDescriptor, p_request, p_response, p_context); }
From source file:com.enonic.vertical.adminweb.AdminLogInServlet.java
private void handlerLoginForm(HttpServletRequest request, HttpServletResponse response, HttpSession session, HashMap<String, Object> parameters, org.jdom.Document doc) throws VerticalAdminException { final UserStoreXmlCreator xmlCreator = new UserStoreXmlCreator( userStoreService.getUserStoreConnectorConfigs()); List<UserStoreEntity> userStores = securityService.getUserStores(); org.jdom.Document tempDoc = xmlCreator.createPagedDocument(userStores, 0, 100); org.jdom.Element dataElem = doc.getRootElement(); dataElem.addContent(tempDoc.getRootElement().detach()); // set correct language and get languages xml AdminConsoleTranslationService languageMap = AdminConsoleTranslationService.getInstance(); String languageCode = request.getParameter("lang"); Boolean cookieSet = false;/*from w ww. j a v a 2s .co m*/ if (languageCode == null) { Cookie cookie = CookieUtil.getCookie(request, "languageCode"); if (cookie == null) { languageCode = languageMap.getDefaultLanguageCode(); } else { languageCode = cookie.getValue(); cookieSet = true; } } languageMap.toDoc(doc, languageCode); session.setAttribute("languageCode", languageCode); parameters.put("languagecode", languageCode); if (!cookieSet) { String deploymentPath = DeploymentPathResolver.getAdminDeploymentPath(request); CookieUtil.setCookie(response, "languageCode", languageCode, COOKIE_TIMEOUT, deploymentPath); } String userStoreKeyStr = request.getParameter("userStorekey"); if (userStoreKeyStr != null) { parameters.put("userStorekey", userStoreKeyStr); } String username = request.getParameter("username"); if (username != null) { parameters.put("username", username); } String password = request.getParameter("password"); if (password != null) { parameters.put("password", password); } String errorCode = (String) session.getAttribute("passworderrorcode"); if (errorCode != null) { session.removeAttribute("passworderrorcode"); session.removeAttribute("passworderror"); } errorCode = (String) session.getAttribute("loginerrorcode"); if (errorCode != null) { parameters.put("errorcode", errorCode); parameters.put("errormessage", session.getAttribute("loginerror")); } // version and copyright info parameters.put("version", Version.getVersion()); parameters.put("copyright", Version.getCopyright()); String selectedUserStore = (String) session.getAttribute("selectedloginuserstore"); if (StringUtils.isNotEmpty(selectedUserStore)) { parameters.put("selectedloginuserstore", selectedUserStore); } transformXML(request, response, doc, "login_form.xsl", parameters); }
From source file:gwtupload.server.UploadServlet.java
/** * This method parses the submit action, puts in session a listener where the * progress status is updated, and eventually stores the received data in * the user session./* ww w . j a va2 s .com*/ * * returns null in the case of success or a string with the error * */ protected String parsePostRequest(HttpServletRequest request, HttpServletResponse response) { try { String delay = request.getParameter(PARAM_DELAY); String maxFilesize = request.getParameter(PARAM_MAX_FILE_SIZE); maxSize = maxFilesize != null && maxFilesize.matches("[0-9]*") ? Long.parseLong(maxFilesize) : maxSize; uploadDelay = Integer.parseInt(delay); } catch (Exception e) { } HttpSession session = request.getSession(); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received."); AbstractUploadListener listener = getCurrentListener(request); if (listener != null) { if (listener.isFrozen() || listener.isCanceled() || listener.getPercent() >= 100) { removeCurrentListener(request); } else { String error = getMessage("busy"); logger.error("UPLOAD-SERVLET (" + session.getId() + ") " + error); return error; } } // Create a file upload progress listener, and put it in the user session, // so the browser can use ajax to query status of the upload process listener = createNewListener(request); List<FileItem> uploadedItems; try { // Call to a method which the user can override checkRequest(request); // Create the factory used for uploading files, FileItemFactory factory = getFileItemFactory(getContentLength(request)); ServletFileUpload uploader = new ServletFileUpload(factory); uploader.setSizeMax(maxSize); uploader.setFileSizeMax(maxFileSize); uploader.setProgressListener(listener); // Receive the files logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsing HTTP POST request "); uploadedItems = uploader.parseRequest(request); session.removeAttribute(getSessionLastFilesKey(request)); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsed request, " + uploadedItems.size() + " items received."); // Received files are put in session List<FileItem> sessionFiles = getMySessionFileItems(request); if (sessionFiles == null) { sessionFiles = new ArrayList<FileItem>(); } String error = ""; if (uploadedItems.size() > 0) { sessionFiles.addAll(uploadedItems); String msg = ""; for (FileItem i : sessionFiles) { msg += i.getFieldName() + " => " + i.getName() + "(" + i.getSize() + " bytes),"; } logger.debug("UPLOAD-SERVLET (" + session.getId() + ") puting items in session: " + msg); session.setAttribute(getSessionFilesKey(request), sessionFiles); session.setAttribute(getSessionLastFilesKey(request), uploadedItems); } else if (!isAppEngine()) { logger.error("UPLOAD-SERVLET (" + session.getId() + ") error NO DATA received "); error += getMessage("no_data"); } return error.length() > 0 ? error : null; // So much silly questions in the list about this issue. } catch (LinkageError e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Exception: " + e.getMessage() + "\n" + stackTraceToString(e)); RuntimeException ex = new UploadActionException(getMessage("restricted", e.getMessage()), e); listener.setException(ex); throw ex; } catch (SizeLimitExceededException e) { RuntimeException ex = new UploadSizeLimitException(e.getPermittedSize(), e.getActualSize()); listener.setException(ex); throw ex; } catch (UploadSizeLimitException e) { listener.setException(e); throw e; } catch (UploadCanceledException e) { listener.setException(e); throw e; } catch (UploadTimeoutException e) { listener.setException(e); throw e; } catch (Throwable e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Unexpected Exception -> " + e.getMessage(), e); e.printStackTrace(); RuntimeException ex = new UploadException(e); listener.setException(ex); throw ex; } }
From source file:com.iskyshop.manage.buyer.action.OrderBuyerAction.java
@SecurityMapping(title = "", value = "/buyer/refund_image_del.htm*", rtype = "buyer", rname = "", rcode = "user_center", rgroup = "") @RequestMapping("/buyer/refund_image_del.htm") public void refund_image_del(HttpServletRequest request, HttpServletResponse response, String image_id) { response.setContentType("text/plain"); response.setHeader("Cache-Control", "no-cache"); response.setCharacterEncoding("UTF-8"); PrintWriter writer;/*from w w w . j a v a 2 s . c o m*/ try { HttpSession session = request.getSession(); AtomicInteger img_num = (AtomicInteger) session.getAttribute("img_num"); if (img_num != null) { String refund_img = (String) session.getAttribute("refund_img_" + image_id); CommUtil.deleteFile(CommUtil.getURL(request) + "/" + refund_img); session.removeAttribute(refund_img); session.removeAttribute(image_id); int id = Integer.valueOf(image_id); int j = 0; for (int i = 1; i < img_num.intValue(); i++) { j++; if (i == id) { i--; id--; continue; } session.setAttribute("refund_img_" + i, session.getAttribute("refund_img_" + j)); } session.setAttribute("img_num", new AtomicInteger(img_num.intValue() - 1)); AtomicInteger count = (AtomicInteger) session.getAttribute("img_num"); String img_html = ""; for (int i = 1; i < count.intValue() + 1; i++) { img_html += "<li><a target='_blank' id='refund_href" + i + "' href='" + CommUtil.getURL(request) + "/" + session.getAttribute("refund_img_" + i) + "'> <img id='refund_img_" + i + "' width='55' height='55' src='" + CommUtil.getURL(request) + "/" + session.getAttribute("refund_img_" + i) + "' /></a> <b onclick='delete_return_img(" + i + ")'>X</b></li>"; } Map map = new HashMap(); map.put("num", count); map.put("result", true); map.put("img_html", img_html); writer = response.getWriter(); writer.print(Json.toJson(map)); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.skilrock.lms.web.scratchService.gameMgmt.common.GameUploadAction.java
/** * This method is used to Upload games basic details and rank file. throws * LMSException// w ww . j a v a 2s .co m * * @return SUCCESS */ public String uploadBasicDetails() throws Exception { HttpSession session = getRequest().getSession(); String govt_comm_type = null; System.out.println("rule is " + getGovtCommRule()); if (govtCommRule.equals("fixedper")) { System.out.println("inside this"); govt_comm_type = "FIXED_PER"; } else if (govtCommRule.equals("minprofit")) { govt_comm_type = "MIN_PROFIT"; } else if (govtCommRule.equals("notapplicable")) { govt_comm_type = "NOT_APP"; } String defaultInvoiceMethod = (String) ServletActionContext.getServletContext() .getAttribute("SCRATCH_INVOICING_METHOD_DEFAULT"); logger.info("DEFAULT INVOICING METHOD : " + defaultInvoiceMethod); GameuploadHelper gameHelper = new GameuploadHelper(); String returnType = gameHelper.uploadBasicDetails(govt_comm_type, priceperTicket, gameNumber, gameName, ticketpetBook, booksperPack, agentSaleCommRate, agentPWTCommRate, retailerSaleCommRate, retailerPWTCommRate, govtCommRate, minAssProfit, getDigitsofPack(), getDigitsofBook(), getDigitsofTicket(), getRankupload(), getPrizePayOutRatio(), getVatPercentage(), getTicketsInScheme(), getGameVirnDigits(), defaultInvoiceMethod); if (returnType.equals("ERROR")) { addActionError(getText("msg.this.game.uploaded.previously")); return ERROR; } else { // remove session attributes session.removeAttribute("x"); return SUCCESS; } }