List of usage examples for javax.servlet.http HttpServletRequest removeAttribute
public void removeAttribute(String name);
From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java
/** * Restore the request attributes after an include. * @param request current HTTP request//from ww w. j a va 2s . c o m * @param attributesSnapshot the snapshot of the request attributes before the include */ @SuppressWarnings("unchecked") private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) { logger.debug("Restoring snapshot of request attributes after include"); // Need to copy into separate Collection here, to avoid side effects // on the Enumeration when removing attributes. Set<String> attrsToCheck = new HashSet<String>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attrsToCheck.add(attrName); } } // Add attributes that may have been removed attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet()); // Iterate over the attributes to check, restoring the original value // or removing the attribute, respectively, if appropriate. for (String attrName : attrsToCheck) { Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null) { if (logger.isDebugEnabled()) { logger.debug("Removing attribute [" + attrName + "] after include"); } request.removeAttribute(attrName); } else if (attrValue != request.getAttribute(attrName)) { if (logger.isDebugEnabled()) { logger.debug("Restoring original value of attribute [" + attrName + "] after include"); } request.setAttribute(attrName, attrValue); } } }
From source file:it.eng.spago.dispatching.httpchannel.AdapterHTTP.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Monitor monitor = null;/*from w ww . ja va2 s. com*/ IEventNotifier eventNotifier = null; RequestContextIFace requestContext = null; try { SourceBean serviceRequest = null; EMFErrorHandler emfErrorHandler = null; EMFExceptionHandler exceptionHandler = new EMFExceptionHandler(); // Retrieve LOOP responseContainer, if any ResponseContainer loopbackResponseContainer = ResponseContainer.getResponseContainer(); RequestContainer requestContainer = new RequestContainer(); RequestContainer.setRequestContainer(requestContainer); ResponseContainer responseContainer = new ResponseContainer(); ResponseContainer.setResponseContainer(responseContainer); requestContext = new DefaultRequestContext(requestContainer, responseContainer); // Retrieve HTTP session HttpSession session = request.getSession(true); eventNotifier = EventNotifierFactory.getEventNotifier(); eventNotifier.notifyEvent(new ServiceStartEvent(session), requestContext); // Trace only after calling listener, so the session id can be written on log files TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: invocato"); boolean loopback = (request.getAttribute(Constants.PUBLISHING_MODE_LOOPBACK) != null); if (loopback) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: loop-back rilevato"); // remove from the request the loopback attribute request.removeAttribute(Constants.PUBLISHING_MODE_LOOPBACK); loopbackResponseContainer = ResponseContainerAccess.getResponseContainer(request); serviceRequest = loopbackResponseContainer.getLoopbackServiceRequest(); if (serviceRequest == null) { serviceRequest = new SourceBean(Constants.SERVICE_REQUEST); } else { Object newServiceRequest = serviceRequest.getAttribute(Constants.SERVICE_REQUEST); if ((newServiceRequest != null) && (newServiceRequest instanceof SourceBean)) serviceRequest = (SourceBean) newServiceRequest; } // if (serviceRequest == null) requestContainer.setServiceRequest(serviceRequest); // The errors are kept in loop mode, so retrieve old error handler emfErrorHandler = loopbackResponseContainer.getErrorHandler(); if (emfErrorHandler == null) { emfErrorHandler = new EMFErrorHandler(); } } // if (loopbackResponseContainer != null) else { monitor = MonitorFactory.start("controller.adapter.http"); serviceRequest = new SourceBean(Constants.SERVICE_REQUEST); requestContainer.setServiceRequest(serviceRequest); // Get header parameter before parsing the request setHttpRequestData(request, requestContainer); // Check if the service was invoked with the .action or .page URL handleServiceName(serviceRequest, requestContainer); boolean isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request)); if (isMultipart) { handleMultipartForm(request, requestContext); } else { handleSimpleForm(request, requestContext); } emfErrorHandler = new EMFErrorHandler(); } // if (loopbackResponseContainer != null) else //***************** NAVIGATION CONTROL ******************************************************* serviceRequest = LightNavigationManager.controlLightNavigation(request, serviceRequest); requestContainer.setServiceRequest(serviceRequest); //******************************************************************************************** Exception serviceException = null; CoordinatorIFace coordinator = null; try { responseContainer.setErrorHandler(emfErrorHandler); String channelType = Constants.HTTP_CHANNEL; String channelTypeParameter = (String) (serviceRequest.getAttribute(Constants.CHANNEL_TYPE)); String channelTypeHeader = (String) (requestContainer.getAttribute(HTTP_ACCEPT_HEADER)); if (((channelTypeParameter != null) && channelTypeParameter.equalsIgnoreCase(Constants.WAP_CHANNEL)) || ((channelTypeHeader != null) && (channelTypeHeader.indexOf(WAP_MIME_TYPE) != -1))) channelType = Constants.WAP_CHANNEL; requestContainer.setChannelType(channelType); requestContainer.setInternalRequest(request); requestContainer.setInternalResponse(response); requestContainer.setAdapterConfig(getServletConfig()); TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: requestContainer", requestContainer); TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: sessionContainer", requestContainer.getSessionContainer()); SourceBean serviceResponse = new SourceBean(Constants.SERVICE_RESPONSE); responseContainer.setServiceResponse(serviceResponse); checkSession(session, requestContext); Navigator.checkNavigation(requestContainer); // Refresh service request because Navigator services can changed it serviceRequest = requestContainer.getServiceRequest(); // Suspend/Resume service handleSuspendResume(serviceRequest, requestContainer); coordinator = DispatcherManager.getCoordinator(requestContext); if (coordinator == null) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "AdapterHTTP::service: coordinator nullo !"); serviceException = new Exception("Coordinatore non trovato"); emfErrorHandler .addError(new EMFInternalError(EMFErrorSeverity.ERROR, "Coordinatore non trovato !")); } // if (coordinator == null) else { ((RequestContextIFace) coordinator).setRequestContext(requestContext); responseContainer.setBusinessType(coordinator.getBusinessType()); responseContainer.setBusinessName(coordinator.getBusinessName()); responseContainer.setPublisherName(coordinator.getPublisherName()); coordinator.service(serviceRequest, serviceResponse); ((RequestContextIFace) coordinator).setRequestContext(null); // requestContainer.setInternalRequest(null); } // if (coordinator == null) else } // try catch (Exception ex) { ServiceIFace service = (coordinator != null) ? coordinator.getService() : null; exceptionHandler.handleException(ex, service, requestContext); } // catch (Exception ex) // requestContainer.setInternalResponse(null); // requestContainer.setAdapterConfig(null); // nel caso in cui sia attiva la persistenza della sessione // forza la scrittura sul database synchronized (session) { session.setAttribute(Constants.REQUEST_CONTAINER, session.getAttribute(Constants.REQUEST_CONTAINER)); } // synchronized (session) TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: responseContainer", responseContainer); TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: sessionContainer", requestContainer.getSessionContainer()); if (serializeSession) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.DEBUG, "AdapterHTTP::service: sessionContainer size [" + Serializer.serialize(requestContainer.getSessionContainer()).length + "]"); } render(requestContext, serviceException); } // try catch (Exception ex) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.CRITICAL, "AdapterHTTP::service: ", ex); } // catch (Excpetion ex) try finally { RequestContainer.delRequestContainer(); ResponseContainer.delResponseContainer(); if (monitor != null) { monitor.stop(); } if (eventNotifier != null) { eventNotifier.notifyEvent(new ServiceEndEvent(null), requestContext); } } // finally }
From source file:org.apache.struts2.views.freemarker.FreemarkerResult.java
/** * Execute this result, using the specified template locationArg. * <p/>/*from ww w.j a v a2s . co m*/ * The template locationArg has already been interoplated for any variable substitutions * <p/> * this method obtains the freemarker configuration and the object wrapper from the provided hooks. * It them implements the template processing workflow by calling the hooks for * preTemplateProcess and postTemplateProcess */ public void doExecute(String locationArg, ActionInvocation invocation) throws IOException, TemplateException { this.location = locationArg; this.invocation = invocation; this.configuration = getConfiguration(); this.wrapper = getObjectWrapper(); ActionContext ctx = invocation.getInvocationContext(); HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST); if (!locationArg.startsWith("/")) { String base = ResourceUtil.getResourceBase(req); locationArg = base + "/" + locationArg; } Template template = configuration.getTemplate(locationArg, deduceLocale()); TemplateModel model = createModel(); // Give subclasses a chance to hook into preprocessing if (preTemplateProcess(template, model)) { try { // Process the template Writer writer = getWriter(); if (isWriteIfCompleted() || configuration .getTemplateExceptionHandler() == TemplateExceptionHandler.RETHROW_HANDLER) { CharArrayWriter parentCharArrayWriter = (CharArrayWriter) req .getAttribute(PARENT_TEMPLATE_WRITER); boolean isTopTemplate = false; if (isTopTemplate = (parentCharArrayWriter == null)) { //this is the top template parentCharArrayWriter = new CharArrayWriter(); //set it in the request because when the "action" tag is used a new VS and ActionContext is created req.setAttribute(PARENT_TEMPLATE_WRITER, parentCharArrayWriter); } try { template.process(model, parentCharArrayWriter); if (isTopTemplate) { parentCharArrayWriter.flush(); parentCharArrayWriter.writeTo(writer); } } catch (TemplateException e) { if (LOG.isErrorEnabled()) { LOG.error("Error processing Freemarker result!", e); } throw e; } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error("Error processing Freemarker result!", e); } throw e; } finally { if (isTopTemplate && parentCharArrayWriter != null) { req.removeAttribute(PARENT_TEMPLATE_WRITER); parentCharArrayWriter.close(); } } } else { template.process(model, writer); } } finally { // Give subclasses a chance to hook into postprocessing postTemplateProcess(template, model); } } }
From source file:gov.nih.nci.system.web.struts.action.DeleteAction.java
public String execute() throws Exception { init();/*from w w w . j a v a 2 s . com*/ HttpServletRequest request = ServletActionContext.getRequest(); String targetClass = request.getParameter("target"); if (targetClass == null || targetClass.trim().length() == 0) { request.setAttribute("Message", "Invalid target"); return null; } String idCol = null; try { idCol = classCache.getClassIdName(Class.forName(targetClass)); } catch (ClassNotFoundException e) { e.printStackTrace(); } if (idCol == null) { request.setAttribute("Message", "Invalid target"); return null; } String idColValue = request.getParameter(idCol); if (idColValue == null || idColValue.trim().length() == 0) { request.setAttribute("Message", "Invalid target identifier"); return null; } String confirm = request.getParameter("confirm"); if (confirm == null || confirm.trim().length() == 0 || !confirm.equals("true")) return SUCCESS; String url = request.getRequestURL().toString(); String restURL = url.substring(0, url.lastIndexOf("/")); WebClient client = WebClient.create(restURL); client.path("rest/" + targetClass.substring(targetClass.lastIndexOf(".") + 1, targetClass.length()) + "/" + idColValue); client.type("application/xml").accept("application/xml"); SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION.toString()); org.acegisecurity.context.SecurityContext context = (org.acegisecurity.context.SecurityContext) session .get("ACEGI_SECURITY_CONTEXT"); if (context != null) { Authentication authentication = context.getAuthentication(); // authentication.getCredentials(); String userName = ((org.acegisecurity.userdetails.User) authentication.getPrincipal()).getUsername(); String password = authentication.getCredentials().toString(); String base64encodedUsernameAndPassword = new String( Base64.encodeBase64((userName + ":" + password).getBytes())); client.header("Authorization", "Basic " + base64encodedUsernameAndPassword); } else { if (secured) { request.setAttribute("message", "Invalid authentication"); return SUCCESS; } } Response r = client.delete(); if (r.getStatus() == Status.OK.getStatusCode()) { request.removeAttribute("confirm"); request.setAttribute("successful", "1"); // request.removeAttribute("confirm"); InputStream is = (InputStream) r.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); Element root = jDoc.getRootElement(); Element messageEle = root.getChild("message"); request.setAttribute("message", org.apache.commons.lang.StringEscapeUtils.escapeHtml(messageEle.getText())); } else { InputStream is = (InputStream) r.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); Element root = jDoc.getRootElement(); Element message = root.getChild("message"); String error = root.getText(); if (message != null) error = message.getText(); String messageStr = "Failed to create: " + error; request.setAttribute("message", org.apache.commons.lang.StringEscapeUtils.escapeHtml(messageStr)); } return SUCCESS; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ChooseExamsMapContextDANew.java
public ActionForward choose(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final ActionErrors errors = new ActionErrors(); final DynaActionForm chooseExamContextoForm = (DynaActionForm) form; Boolean inEnglish = getFromRequestBoolean("inEnglish", request); if (inEnglish == null) { inEnglish = getLocale(request).getLanguage().equals(Locale.ENGLISH.getLanguage()); }/*from ww w . ja va 2s. co m*/ request.setAttribute("inEnglish", inEnglish); // index String indexValue = getFromRequest("index", request); request.setAttribute("index", indexValue); // degreeID String degreeId = (String) chooseExamContextoForm.get("degreeID"); request.setAttribute("degreeID", degreeId); final Degree degree = FenixFramework.getDomainObject(degreeId); if (degree != null) { OldCmsSemanticURLHandler.selectSite(request, degree.getSite()); } request.setAttribute("degree", degree); // curricularYearList final Boolean selectAllCurricularYears = (Boolean) chooseExamContextoForm.get("selectAllCurricularYears"); final List<Integer> curricularYears = buildCurricularYearList(selectAllCurricularYears, degree, chooseExamContextoForm); request.setAttribute("curricularYearList", curricularYears); // degreeCurricularPlanID String degreeCurricularPlanId = getFromRequest("degreeCurricularPlanID", request); final DegreeCurricularPlan degreeCurricularPlan; if (StringUtils.isEmpty(degreeCurricularPlanId)) { degreeCurricularPlan = degree.getMostRecentDegreeCurricularPlan(); } else { degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanId); } if (degreeCurricularPlan != null) { request.setAttribute("degreeCurricularPlanID", degreeCurricularPlan.getExternalId()); if (!degreeCurricularPlan.getDegree().getExternalId().equals(degreeId)) { throw new FenixActionException(); } // lista List<LabelValueBean> executionPeriodsLabelValueList = buildExecutionPeriodsLabelValueList( degreeCurricularPlan.getExternalId()); if (executionPeriodsLabelValueList.size() > 1) { request.setAttribute("lista", executionPeriodsLabelValueList); } else { request.removeAttribute("lista"); } // infoDegreeCurricularPlan InfoDegreeCurricularPlan infoDegreeCurricularPlan = InfoDegreeCurricularPlan .newInfoFromDomain(degreeCurricularPlan); request.setAttribute("infoDegreeCurricularPlan", infoDegreeCurricularPlan); } InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) request .getAttribute(PresentationConstants.EXECUTION_PERIOD); String executionPeriodID = (String) chooseExamContextoForm.get("indice"); if (executionPeriodID != null && !executionPeriodID.equals("")) { infoExecutionPeriod = ReadExecutionPeriodByOID.run(executionPeriodID); } request.setAttribute("indice", infoExecutionPeriod.getExternalId()); chooseExamContextoForm.set("indice", infoExecutionPeriod.getExternalId()); RequestUtils.setExecutionPeriodToRequest(request, infoExecutionPeriod); request.setAttribute(PresentationConstants.EXECUTION_PERIOD, infoExecutionPeriod); request.setAttribute(PresentationConstants.EXECUTION_PERIOD_OID, infoExecutionPeriod.getExternalId().toString()); final ExecutionSemester executionSemester = FenixFramework .getDomainObject(infoExecutionPeriod.getExternalId()); ExecutionDegree executionDegree = null; if (degreeCurricularPlan != null) { executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionSemester.getExecutionYear()); if (executionDegree == null) { executionDegree = degreeCurricularPlan.getMostRecentExecutionDegree(); if (executionDegree != null) { infoExecutionPeriod = InfoExecutionPeriod .newInfoFromDomain(executionDegree.getExecutionYear().getExecutionSemesterFor(1)); request.setAttribute("indice", infoExecutionPeriod.getExternalId()); chooseExamContextoForm.set("indice", infoExecutionPeriod.getExternalId()); RequestUtils.setExecutionPeriodToRequest(request, infoExecutionPeriod); request.setAttribute(PresentationConstants.EXECUTION_PERIOD, infoExecutionPeriod); request.setAttribute(PresentationConstants.EXECUTION_PERIOD_OID, infoExecutionPeriod.getExternalId().toString()); } } } if (executionDegree != null) { InfoExecutionDegree infoExecutionDegree = InfoExecutionDegree.newInfoFromDomain(executionDegree); request.setAttribute(PresentationConstants.EXECUTION_DEGREE, infoExecutionDegree); request.setAttribute("executionDegreeID", infoExecutionDegree.getExternalId().toString()); RequestUtils.setExecutionDegreeToRequest(request, infoExecutionDegree); } else { return mapping.findForward("viewExamsMap"); } return mapping.findForward("showExamsMap"); }
From source file:org.apache.click.ClickServlet.java
/** * Return a new Page instance for the given request context. This method will * invoke {@link #initPage(String, Class, HttpServletRequest)} to create * the Page instance and then set the properties on the page. * * @param context the page request context * @return a new Page instance for the given request, or null if an * PageInterceptor has aborted page creation *//*ww w. j a va2 s .c o m*/ protected Page createPage(Context context) { HttpServletRequest request = context.getRequest(); // Log request parameters if (logger.isTraceEnabled()) { logger.trace(" is Ajax request: " + context.isAjaxRequest()); logRequestParameters(request); } String path = context.getResourcePath(); if (request.getAttribute(FORWARD_PAGE) != null) { Page forwardPage = (Page) request.getAttribute(FORWARD_PAGE); if (forwardPage.getFormat() == null) { forwardPage.setFormat(configService.createFormat()); } request.removeAttribute(FORWARD_PAGE); return forwardPage; } Class<? extends Page> pageClass = configService.getPageClass(path); if (pageClass == null) { pageClass = configService.getNotFoundPageClass(); path = ConfigService.NOT_FOUND_PATH; } // Set thread local app page listeners List<PageInterceptor> interceptors = configService.getPageInterceptors(); setThreadLocalInterceptors(interceptors); for (PageInterceptor listener : interceptors) { if (!listener.preCreate(pageClass, context)) { return null; } } final Page page = initPage(path, pageClass, request); if (page.getFormat() == null) { page.setFormat(configService.createFormat()); } for (PageInterceptor listener : interceptors) { if (!listener.postCreate(page)) { return null; } } return page; }
From source file:org.ofbiz.order.shoppingcart.ShoppingCartEvents.java
/** Associates a party to order */ public static String addAdditionalParty(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); String partyId = request.getParameter("additionalPartyId"); String roleTypeId[] = request.getParameterValues("additionalRoleTypeId"); List<String> eventList = new LinkedList<String>(); Locale locale = UtilHttp.getLocale(request); int i;/*from ww w . j a v a 2 s.c o m*/ if (UtilValidate.isEmpty(partyId) || UtilValidate.isEmpty(roleTypeId) || roleTypeId.length < 1) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderPartyIdAndOrRoleTypeIdNotDefined", locale)); return "error"; } if (request.getAttribute("_EVENT_MESSAGE_LIST_") != null) { List<String> msg = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_")); eventList.addAll(msg); } for (i = 0; i < roleTypeId.length; i++) { try { cart.addAdditionalPartyRole(partyId, roleTypeId[i]); } catch (Exception e) { eventList.add(e.getLocalizedMessage()); } } request.removeAttribute("_EVENT_MESSAGE_LIST_"); request.setAttribute("_EVENT_MESSAGE_LIST_", eventList); return "success"; }
From source file:com.concursive.connect.web.controller.servlets.URLControllerServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { LOG.debug("service called"); LOG.debug("requestCharacterEncoding=" + request.getCharacterEncoding()); try {//w w w. j a va 2 s . c o m request.setCharacterEncoding("UTF-8"); } catch (Exception e) { LOG.warn("Unsupported encoding"); } // Check the preferences to see if the correct domain name is being used, else do a redirect ApplicationPrefs prefs = (ApplicationPrefs) request.getSession().getServletContext() .getAttribute("applicationPrefs"); boolean redirect = false; String contextPath = request.getContextPath(); String uri = request.getRequestURI(); String queryString = request.getQueryString(); String path = uri.substring(contextPath.length()) + (queryString == null ? "" : "?" + queryString); LOG.debug("path: " + path); request.setAttribute("requestedURL", path); // It's important the user is using the correct URL for accessing content; // The portal has it's own redirect scheme, this is a another catch all // to see if an old domain name or context is used PortalBean bean = new PortalBean(request); String expectedDomainName = prefs.get(ApplicationPrefs.WEB_DOMAIN_NAME); LOG.debug("expectedDomainName: " + expectedDomainName); LOG.debug("domainName: " + bean.getServerName()); String expectedContext = prefs.get(ApplicationPrefs.WEB_CONTEXT); LOG.debug("expectedContextPath: " + expectedContext); LOG.debug("contextPath: " + contextPath); if (StringUtils.hasText(expectedContext) && !expectedContext.equals(contextPath) || (expectedDomainName != null && path.length() > 0 && !"127.0.0.1".equals(bean.getServerName()) && !"127.0.0.1".equals(expectedDomainName) && !"localhost".equals(bean.getServerName()) && !"localhost".equals(expectedDomainName) && !bean.getServerName().startsWith("10.") && !bean.getServerName().startsWith("172.") && !bean.getServerName().startsWith("192.") && !bean.getServerName().equals(expectedDomainName))) { if (uri.length() > 0 && !uri.substring(1).equals(prefs.get("PORTAL.INDEX"))) { String newUrl = URLFactory.createURL(prefs.getPrefs()) + path; request.setAttribute("redirectTo", newUrl); LOG.debug("redirectTo: " + newUrl); request.removeAttribute(Constants.REQUEST_PAGE_LAYOUT); redirect = true; } } if (redirect) { try { RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/redirect301.jsp"); dispatcher.forward(request, response); } catch (Exception e) { } } else { mapToMVCAction(request, response); } }
From source file:org.ofbiz.order.shoppingcart.ShoppingCartEvents.java
/** Removes a previously associated party to order */ public static String removeAdditionalParty(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); String partyId = request.getParameter("additionalPartyId"); String roleTypeId[] = request.getParameterValues("additionalRoleTypeId"); List<String> eventList = new LinkedList<String>(); Locale locale = UtilHttp.getLocale(request); int i;/*from w w w. j a v a 2s.co m*/ if (UtilValidate.isEmpty(partyId) || roleTypeId.length < 1) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderPartyIdAndOrRoleTypeIdNotDefined", locale)); return "error"; } if (request.getAttribute("_EVENT_MESSAGE_LIST_") != null) { List<String> msg = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_")); eventList.addAll(msg); } for (i = 0; i < roleTypeId.length; i++) { try { cart.removeAdditionalPartyRole(partyId, roleTypeId[i]); } catch (Exception e) { Debug.logInfo(e.getLocalizedMessage(), module); eventList.add(e.getLocalizedMessage()); } } request.removeAttribute("_EVENT_MESSAGE_LIST_"); request.setAttribute("_EVENT_MESSAGE_LIST_", eventList); return "success"; }
From source file:org.betaconceptframework.astroboa.console.filter.HttpSessionRepositoryContextIntegrationFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpSession httpSession = null;// w w w . j a v a2s . c o m try { httpSession = request.getSession(false); } catch (IllegalStateException ignored) { } boolean httpSessionExistedAtStartOfRequest = httpSession != null; Map<String, AstroboaClientContext> clientContextMapBeforeChainExecution = readClientContextMapFromSession( httpSession); AstroboaClientContext activeClientContextBeforeChainExecution = readActiveClientContextFromSession( httpSession); // Make the HttpSession null, as we don't want to keep a reference to it lying // around in case chain.doFilter() invalidates it. httpSession = null; int contextHashBeforeChainExecution = 0; if (clientContextMapBeforeChainExecution != null) { contextHashBeforeChainExecution = clientContextMapBeforeChainExecution.hashCode(); } request.setAttribute(FILTER_APPLIED, Boolean.TRUE); // Create a wrapper that will eagerly update the session with the repository context // if anything in the chain does a sendError() or sendRedirect(). // See SEC-398 OnRedirectUpdateSessionResponseWrapper responseWrapper = new OnRedirectUpdateSessionResponseWrapper( response, request, httpSessionExistedAtStartOfRequest, contextHashBeforeChainExecution); // Proceed with chain try { // This is the only place in this class where RepositoryContextHolder.setContext() is called AstroboaClientContextHolder.setClientContextMap(clientContextMapBeforeChainExecution); AstroboaClientContextHolder.setActiveClientContext(activeClientContextBeforeChainExecution); filterChain.doFilter(request, responseWrapper); } finally { // This is the only place in this class where RepositoryContextHolder.getContext() is called Map<String, AstroboaClientContext> clientContextMapAfterChainExecution = AstroboaClientContextHolder .getClientContextMap(); AstroboaClientContext activeClientContextAfterChainExecution = AstroboaClientContextHolder .getActiveClientContext(); // Crucial removal of RepositoryContextHolder contents - do this before anything else. AstroboaClientContextHolder.clearContext(); request.removeAttribute(FILTER_APPLIED); // storeRepositoryContextInSession() might already be called by the response wrapper // if something in the chain called sendError() or sendRedirect(). This ensures we only call it // once per request. if (!responseWrapper.isSessionUpdateDone()) { storeClientContextInSession(clientContextMapAfterChainExecution, activeClientContextAfterChainExecution, request, httpSessionExistedAtStartOfRequest, contextHashBeforeChainExecution); } if (logger.isDebugEnabled()) { logger.debug("RepositoryContextHolder now cleared, as request processing completed"); } } }