List of usage examples for javax.servlet.http HttpServletRequest removeAttribute
public void removeAttribute(String name);
From source file:org.jasig.portal.layout.StylesheetUserPreferencesServiceImpl.java
@Transactional @Override//from w w w. jav a 2 s . co m public void clearAllLayoutAttributes(HttpServletRequest request, PreferencesScope prefScope) { final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope); final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey); if (stylesheetUserPreferences != null) { stylesheetUserPreferences.clearAllLayoutAttributes(); this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences); } final HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(LAYOUT_ATTRIBUTES_KEY + stylesheetPreferencesKey.toString()); } request.removeAttribute(LAYOUT_ATTRIBUTES_KEY + stylesheetPreferencesKey.toString()); }
From source file:org.jasig.portal.layout.StylesheetUserPreferencesServiceImpl.java
@Transactional @Override//from ww w. j ava 2s. c o m public void clearStylesheetParameters(HttpServletRequest request, PreferencesScope prefScope) { final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope); final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey); if (stylesheetUserPreferences != null) { stylesheetUserPreferences.clearStylesheetParameters(); this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences); } final HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(STYLESHEET_PARAMETERS_KEY + stylesheetPreferencesKey.toString()); } request.removeAttribute(STYLESHEET_PARAMETERS_KEY + stylesheetPreferencesKey.toString()); }
From source file:org.openmrs.web.controller.FieldGenController.java
@SuppressWarnings("unchecked") public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // find the field that was identified in the openmrs:fieldGen taglib Object uri = request.getAttribute("javax.servlet.include.servlet_path.fieldGen"); if (uri == null) { uri = request.getAttribute("javax.servlet.include.servlet_path"); }// w w w . j a va 2 s .c o m String fieldGenPath = ""; Map<String, Object> model = new HashMap<String, Object>(); if (uri != null) { fieldGenPath = uri.toString(); // Allowable extensions are '' (no extension) and '.field' if (fieldGenPath.endsWith("field")) { fieldGenPath = fieldGenPath.replace(".field", ""); } else if (fieldGenPath.endsWith("jsp")) { throw new ServletException( "Illegal extension used for fieldGen: '.jsp'. Allowable extensions are '' (no extension) and '.field'"); } String type = (String) request.getAttribute("org.openmrs.fieldGen.type"); String formFieldName = (String) request.getAttribute("org.openmrs.fieldGen.formFieldName"); //String startVal = (String)request.getAttribute("org.openmrs.fieldGen.startVal"); Map<String, Object> params = (Map<String, Object>) request .getAttribute("org.openmrs.fieldGen.parameters"); Map<String, Object> moreParams = (Map<String, Object>) request .getAttribute("org.openmrs.fieldGen.parameterMap"); model.put("type", type); model.put("formFieldName", formFieldName); model.put("obj", request.getAttribute("org.openmrs.fieldGen.object")); model.put("request", request.getAttribute("org.openmrs.fieldGen.request")); model.putAll(params); if (moreParams != null) { model.putAll(moreParams); } request.removeAttribute("org.openmrs.fieldGen.type"); request.removeAttribute("org.openmrs.fieldGen.formFieldName"); request.removeAttribute("org.openmrs.fieldGen.object"); request.removeAttribute("org.openmrs.fieldGen.parameters"); request.removeAttribute("org.openmrs.fieldGen.parameterMap"); } return new ModelAndView(fieldGenPath, "model", model); }
From source file:org.apache.struts.action.RequestProcessor.java
/** * <p>If this request was not cancelled, and the request's {@link * ActionMapping} has not disabled validation, call the * <code>validate</code> method of the specified {@link ActionForm}, and * forward to the input path if there were any errors. Return * <code>true</code> if we should continue processing, or * <code>false</code> if we have already forwarded control back to the * input form.</p>/*from w w w . j a va 2s . c o m*/ * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param form The ActionForm instance we are populating * @param mapping The ActionMapping we are using * @return <code>true</code> to continue normal processing; * <code>false</code> if a response has been created. * @throws IOException if an input/output error occurs * @throws ServletException if a servlet exception occurs * @throws InvalidCancelException if a cancellation is attempted * without the proper action configuration. */ protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws IOException, ServletException, InvalidCancelException { if (form == null) { return (true); } // Has validation been turned off for this mapping? if (!mapping.getValidate()) { return (true); } // Was this request cancelled? If it has been, the mapping also // needs to state whether the cancellation is permissable; otherwise // the cancellation is considered to be a symptom of a programmer // error or a spoof. if (request.getAttribute(Globals.CANCEL_KEY) != null) { if (mapping.getCancellable()) { if (log.isDebugEnabled()) { log.debug(" Cancelled transaction, skipping validation"); } return (true); } else { request.removeAttribute(Globals.CANCEL_KEY); throw new InvalidCancelException(); } } // Call the form bean's validation method if (log.isDebugEnabled()) { log.debug(" Validating input form properties"); } ActionMessages errors = form.validate(mapping, request); if ((errors == null) || errors.isEmpty()) { if (log.isTraceEnabled()) { log.trace(" No errors detected, accepting input"); } return (true); } // Special handling for multipart request if (form.getMultipartRequestHandler() != null) { if (log.isTraceEnabled()) { log.trace(" Rolling back multipart request"); } form.getMultipartRequestHandler().rollback(); } // Was an input path (or forward) specified for this mapping? String input = mapping.getInput(); if (input == null) { if (log.isTraceEnabled()) { log.trace(" Validation failed but no input form available"); } response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getInternal().getMessage("noInput", mapping.getPath())); return (false); } // Save our error messages and return to the input form if possible if (log.isDebugEnabled()) { log.debug(" Validation failed, returning to '" + input + "'"); } request.setAttribute(Globals.ERROR_KEY, errors); if (moduleConfig.getControllerConfig().getInputForward()) { ForwardConfig forward = mapping.findForward(input); processForwardConfig(request, response, forward); } else { internalModuleRelativeForward(input, request, response); } return (false); }
From source file:com.jsmartframework.web.manager.BeanHandler.java
private void finalizeWebBean(Object bean, HttpServletRequest request) { if (bean != null) { executePreDestroy(bean);//from w w w. ja v a2 s. com finalizeInjection(bean, request); WebBean webBean = bean.getClass().getAnnotation(WebBean.class); request.removeAttribute(HELPER.getClassName(webBean, bean.getClass())); } }
From source file:uk.ac.cam.caret.sakai.rwiki.tool.RWikiServlet.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (wac == null) { wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); if (wac == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Cannot get WebApplicationContext"); return; }//from w w w. java2s. c o m } log.debug("========================Page Start=========="); request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); String targetURL = persistState(request); String action = request.getParameter("action"); if (!StringUtils.isEmpty(targetURL) && !StringUtils.equals(action, "search") && !StringUtils.equals(action, "full_search")) { response.sendRedirect(targetURL); return; } // Must be done on every request prePopulateRealm(request); addWikiStylesheet(request); request.setAttribute("footerScript", footerScript); if (headerScriptSource != null && headerScriptSource.length() > 0) { request.setAttribute("headerScriptSource", headerScriptSource); } RequestHelper helper = (RequestHelper) wac.getBean(RequestHelper.class.getName()); HttpCommand command = helper.getCommandForRequest(request); // fix for IE6's poor cache capabilities String userAgent = request.getHeader("User-Agent"); if (userAgent != null && userAgent.indexOf("MSIE 6") >= 0) { response.addHeader("Expires", "0"); response.addHeader("Pragma", "cache"); response.addHeader("Cache-Control", "private"); } command.execute(dispatcher, request, response); request.removeAttribute(Tool.NATIVE_URL); log.debug("=====================Page End============="); }
From source file:org.sakaiproject.search.tool.ControllerServlet.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (wac == null) { wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); if (wac == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Cannot get WebApplicationContext"); return; }//w ww . j a v a 2 s. c om } request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); if (searchBeanFactory == null) { searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory"); ServletContext context = getServletContext(); searchBeanFactory.setContext(context); } if (sessionManager == null) { sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName()); } addLocalHeaders(request); String targetURL = persistState(request); if (targetURL != null && targetURL.trim().length() > 0) { response.sendRedirect(targetURL); return; } if (TITLE_PANEL.equals(request.getParameter(PANEL))) { String targetPage = "/WEB-INF/pages/title.jsp"; RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } else { String path = request.getPathInfo(); if (path == null || path.length() == 0) { path = "/index"; } if (!path.startsWith("/")) { path = "/" + path; } String targetPage = "/WEB-INF/pages" + path + ".jsp"; request.setAttribute(SearchBeanFactory.SEARCH_BEAN_FACTORY_ATTR, searchBeanFactory); RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } request.removeAttribute(Tool.NATIVE_URL); }
From source file:nl.strohalm.cyclos.struts.CyclosRequestProcessor.java
private void cleanUpTransaction(final HttpServletRequest request) { if (noTransaction(request)) { return;/*from w w w .jav a2s.co m*/ } logDebug(request, "Cleaning up transaction"); // Close any open iterators DataIteratorHelper.closeOpenIterators(); // Close the session final SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); if (holder != null) { try { final Session session = holder.getSession(); if (session.isOpen()) { session.close(); } } catch (final Exception e) { LOG.error("Error closing Hibernate session", e); } TransactionSynchronizationManager.unbindResourceIfPossible(sessionFactory); } // Close the connection final Connection connection = (Connection) TransactionSynchronizationManager .getResource(connectionProvider); if (connection != null) { try { connectionProvider.closeConnection(connection); } catch (final Exception e) { LOG.error("Error closing database connection", e); } TransactionSynchronizationManager.unbindResourceIfPossible(connectionProvider); } // Cleanup the Spring transaction data TransactionSynchronizationManager.setCurrentTransactionReadOnly(false); TransactionSynchronizationManager.setActualTransactionActive(false); // Cleanup the current transaction data CurrentTransactionData.cleanup(); request.removeAttribute(EXECUTION_RESULT_KEY); }
From source file:edu.umich.its.lti.google.GoogleLtiServlet.java
private void insertRosterPermissions(HttpServletRequest request, HttpServletResponse response, TcSessionData tcSessionData) throws ServletException, IOException { M_log.info("In the insertRosterPermissions call for siteId: " + tcSessionData.getContextId() + " UserId: " + tcSessionData.getUserId()); HashMap<String, HashMap<String, String>> roster = getRoster(request, tcSessionData); M_log.debug("Roster Size: " + roster.size()); //not running permission call for single person since that person already has permission to the folder if (roster.size() != 1) { insertPermissions(request, response, tcSessionData, roster); } else {//from w w w . j a va 2 s.co m response.setStatus(HttpServletResponse.SC_OK); response.getWriter().print(resource.getString("gd.insert.permission.warn.prompt")); } // Title set in request by insertPermissions: get and clear it request.removeAttribute(FOLDER_TITLE); }
From source file:org.jahia.portlets.PortletServlet.java
/** * Dispatch the request to the appropriate portlet methods. This method * assumes that the following attributes are set in the servlet request * scope:/*from ww w .j a v a 2 s .c om*/ * <ul> * <li>METHOD_ID: indicating which method to dispatch.</li> * <li>PORTLET_REQUEST: the internal portlet request.</li> * <li>PORTLET_RESPONSE: the internal portlet response.</li> * </ul> * * @param request the servlet request. * @param response the servlet response. * @throws ServletException * @throws IOException */ private void dispatch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id = ((JahiaPortalServletRequest) request).getId(); String portletName = "/" + id.substring(0, id.indexOf("!")); Portlet portlet = portlets.get(portletName); if (portlet == null) { throw new javax.servlet.UnavailableException("Portlet " + portletName + " unavailable"); } EventPortlet eventPortlet = eventPortlets.get(portletName); ResourceServingPortlet resourceServingPortlet = resourceServingPortlets.get(portletName); // Retrieve attributes from the servlet request. Integer methodId = (Integer) request.getAttribute(PortletInvokerService.METHOD_ID); final PortletRequest portletRequest = (PortletRequest) request .getAttribute(PortletInvokerService.PORTLET_REQUEST); final PortletResponse portletResponse = (PortletResponse) request .getAttribute(PortletInvokerService.PORTLET_RESPONSE); final PortletRequestContext requestContext = (PortletRequestContext) portletRequest .getAttribute(PortletInvokerService.REQUEST_CONTEXT); final PortletResponseContext responseContext = (PortletResponseContext) portletRequest .getAttribute(PortletInvokerService.RESPONSE_CONTEXT); final FilterManager filterManager = (FilterManager) request .getAttribute(PortletInvokerService.FILTER_MANAGER); request.removeAttribute(PortletInvokerService.METHOD_ID); request.removeAttribute(PortletInvokerService.PORTLET_REQUEST); request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE); request.removeAttribute(PortletInvokerService.FILTER_MANAGER); DriverPortletConfig portletConfig = portletConfigs.get(portletName); requestContext.init(portletConfig, getServletContext(), request, response); responseContext.init(request, response); PortletWindow window = requestContext.getPortletWindow(); PortletInvocationEvent event = new PortletInvocationEvent(portletRequest, window, methodId.intValue()); notify(event, true, null); // FilterManager filtermanager = (FilterManager) request.getAttribute( // "filter-manager"); try { // The requested method is RENDER: call Portlet.render(..) if (methodId == PortletInvokerService.METHOD_RENDER) { RenderRequest renderRequest = (RenderRequest) portletRequest; RenderResponse renderResponse = (RenderResponse) portletResponse; filterManager.processFilter(renderRequest, renderResponse, portlet, portletContext); } // The requested method is RESOURCE: call // ResourceServingPortlet.serveResource(..) else if (methodId == PortletInvokerService.METHOD_RESOURCE) { ResourceRequest resourceRequest = (ResourceRequest) portletRequest; ResourceResponse resourceResponse = (ResourceResponse) portletResponse; filterManager.processFilter(resourceRequest, resourceResponse, resourceServingPortlet, portletContext); } // The requested method is ACTION: call Portlet.processAction(..) else if (methodId == PortletInvokerService.METHOD_ACTION) { ActionRequest actionRequest = (ActionRequest) portletRequest; ActionResponse actionResponse = (ActionResponse) portletResponse; filterManager.processFilter(actionRequest, actionResponse, portlet, portletContext); } // The request methode is Event: call Portlet.processEvent(..) else if (methodId == PortletInvokerService.METHOD_EVENT) { EventRequest eventRequest = (EventRequest) portletRequest; EventResponse eventResponse = (EventResponse) portletResponse; filterManager.processFilter(eventRequest, eventResponse, eventPortlet, portletContext); } // The requested method is ADMIN: call handlers. else if (methodId == PortletInvokerService.METHOD_ADMIN) { PortalAdministrationService pas = PlutoServices.getServices().getPortalAdministrationService(); for (AdministrativeRequestListener l : pas.getAdministrativeRequestListeners()) { l.administer(portletRequest, portletResponse); } } // The requested method is LOAD: do nothing. else if (methodId == PortletInvokerService.METHOD_LOAD) { // Do nothing. } notify(event, false, null); } /* catch (UnavailableException ex) { // // if (e.isPermanent()) { throw new // UnavailableException(e.getMessage()); } else { throw new // UnavailableException(e.getMessage(), e.getUnavailableSeconds()); // } // // Portlet.destroy() isn't called by Tomcat, so we have to fix it. try { portlet.destroy(); } catch (Exception th) { // Don't care for Exception this.getServletContext().log("Error during portlet destroy.", th); } // take portlet out of service portlet = null; // TODO: Handle everything as permanently for now. throw new javax.servlet.UnavailableException(ex.getMessage()); } */ catch (PortletException ex) { notify(event, false, ex); throw new ServletException(ex); } }