/** * Invalidate this session if it is marked to be invalidated from previous request. * * @see com.opensymphony.xwork.interceptor.AroundInterceptor#before(com.opensymphony.xwork.ActionInvocation) */ protected void before(ActionInvocation invocation) throws Exception { SessionMap sessionMap = (SessionMap) invocation.getInvocationContext().get(ActionContext.SESSION); if (sessionMap.containsKey(key) && sessionMap.get(key).equals("true")) { if (LOG.isDebugEnabled()) LOG.debug("found marker in session indicating this is the 'next request', session should be invalidated"); sessionMap.invalidate(); LOG.info("session invalidated"); } } }
/** * Decides if this interceptor should invalidate the session or mark the session * to be invalidated upon the next request that contains this interceptor in the stack. * * @see com.opensymphony.xwork.interceptor.AroundInterceptor#after(com.opensymphony.xwork.ActionInvocation, java.lang.String) */ protected void after(ActionInvocation invocation, String result) throws Exception { SessionMap sessionMap = (SessionMap) invocation.getInvocationContext().get(ActionContext.SESSION); if (NOW.equalsIgnoreCase(type)) { if (LOG.isDebugEnabled()) LOG.debug("type=now, invalidating session now"); sessionMap.invalidate(); LOG.info("session invalidated"); } else if (NEXT_REQUEST.equalsIgnoreCase(type)) { if (LOG.isDebugEnabled()) LOG.debug("type=NextRequest, mark key in session, such that next request that have this interceptor will invalidate the session"); sessionMap.put(key, "true"); } else if (NO_OPERATION.equalsIgnoreCase(type)) { if (LOG.isDebugEnabled()) LOG.debug("no operation"); } else { LOG.warn("unrecognized type, type should be either "+NOW+", "+NEXT_REQUEST+" or "+NO_OPERATION); } }
( (SessionMap) session ).invalidate();
public Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context) { // request map wrapping the http request objects Map requestMap = new RequestMap(request); // parameters map wrapping the http paraneters. Map params = null; if (mapping != null) { params = mapping.getParams(); } Map requestParams = new HashMap(request.getParameterMap()); if (params != null) { params.putAll(requestParams); } else { params = requestParams; } // session map wrapping the http session Map session = new SessionMap(request); // application map wrapping the ServletContext Map application = new ApplicationMap(context); return createContextMap(requestMap, params, session, application, request, response, context); }
/** * Removes the specified session attribute. * * @param key the name of the attribute to remove. * @return the value that was removed or <tt>null</tt> if the value was not found (and hence, not removed). */ public Object remove(Object key) { if (session == null) { return null; } synchronized (session) { entries = null; Object value = get(key); session.removeAttribute(key.toString()); return value; } } }
public static OgnlValueStack getStack(PageContext pageContext) { HttpServletRequest req = (HttpServletRequest) pageContext.getRequest(); OgnlValueStack stack = (OgnlValueStack) req.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY); if (stack == null) { stack = new OgnlValueStack(); HttpServletResponse res = (HttpServletResponse) pageContext.getResponse(); DispatcherUtils.initialize(pageContext.getServletContext()); DispatcherUtils du = DispatcherUtils.getInstance(); Map extraContext = du.createContextMap(new RequestMap(req), req.getParameterMap(), new SessionMap(req), new ApplicationMap(pageContext.getServletContext()), req, res, pageContext.getServletContext()); extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext); stack.getContext().putAll(extraContext); req.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, stack); // also tie this stack/context to the ThreadLocal ActionContext.setContext(new ActionContext(stack.getContext())); } else { // let's make sure that the current page context is in the action context Map context = stack.getContext(); context.put(ServletActionContext.PAGE_CONTEXT, pageContext); AttributeMap attrMap = new AttributeMap(context); context.put("attr", attrMap); } return stack; }
/** * Saves an attribute in the session. * * @param key the name of the session attribute. * @param value the value to set. * @return the object that was just set. */ public Object put(Object key, Object value) { synchronized (this) { if (session == null) { session = request.getSession(true); } } synchronized (session) { entries = null; session.setAttribute(key.toString(), value); return get(key); } }
Map ses = ActionContext.getContext().getSession(); if (ses == null && autoCreateSession) { ses = new SessionMap(ServletActionContext.getRequest()); ActionContext.getContext().setSession(ses);
Map session = new SessionMap(req); Map application = new ApplicationMap(servletContext); DispatcherUtils du = DispatcherUtils.getInstance();