Search in sources :

Example 11 with WebSession

use of cn.taketoday.web.session.WebSession in project today-framework by TAKETODAY.

the class AbstractTemplateView method exposeSessionAttributes.

private void exposeSessionAttributes(Map<String, Object> model, RequestContext context) {
    SessionManager sessionManager = RequestContextUtils.getSessionManager(context);
    if (sessionManager != null) {
        WebSession session = sessionManager.getSession(context, false);
        if (session != null) {
            Map<String, Object> exposed = null;
            String[] attributeNames = session.getAttributeNames();
            for (String attribute : attributeNames) {
                if (model.containsKey(attribute) && !allowSessionOverride) {
                    throw new ViewRenderingException("Cannot expose session attribute '" + attribute + "' because of an existing model object of the same name");
                }
                Object attributeValue = session.getAttribute(attribute);
                if (log.isDebugEnabled()) {
                    exposed = exposed != null ? exposed : new LinkedHashMap<>();
                    exposed.put(attribute, attributeValue);
                }
                model.put(attribute, attributeValue);
            }
            if (log.isTraceEnabled() && exposed != null) {
                log.trace("Exposed session attributes to model: {}", exposed);
            }
        }
    }
}
Also used : WebSession(cn.taketoday.web.session.WebSession) SessionManager(cn.taketoday.web.session.SessionManager) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with WebSession

use of cn.taketoday.web.session.WebSession in project today-framework by TAKETODAY.

the class SessionLocaleResolver method setSessionAttribute.

private void setSessionAttribute(RequestContext request, String attributeName, @Nullable Object attribute) {
    SessionManager sessionManager = getSessionManager(request);
    if (sessionManager != null) {
        WebSession session = sessionManager.getSession(request);
        session.setAttribute(attributeName, attribute);
    }
}
Also used : WebSession(cn.taketoday.web.session.WebSession) SessionManager(cn.taketoday.web.session.SessionManager)

Example 13 with WebSession

use of cn.taketoday.web.session.WebSession in project today-framework by TAKETODAY.

the class DefaultSessionAttributeStore method getSession.

private WebSession getSession(RequestContext request) {
    WebSession session = null;
    if (sessionManager != null) {
        session = sessionManager.getSession(request);
    }
    if (session == null) {
        session = RequestContextUtils.getSession(request);
    }
    Assert.state(session != null, "No web-session");
    return session;
}
Also used : WebSession(cn.taketoday.web.session.WebSession)

Example 14 with WebSession

use of cn.taketoday.web.session.WebSession in project today-framework by TAKETODAY.

the class SessionRedirectModelManager method updateRedirectModel.

@Override
protected void updateRedirectModel(List<RedirectModel> redirectModel, RequestContext request) {
    if (CollectionUtils.isEmpty(redirectModel)) {
        WebSession session = getSession(request, false);
        if (session != null) {
            session.removeAttribute(SESSION_ATTRIBUTE);
        }
    } else {
        WebSession session = getSession(request, true);
        Assert.state(session != null, "WebSession not found in current request");
        session.setAttribute(SESSION_ATTRIBUTE, redirectModel);
    }
}
Also used : WebSession(cn.taketoday.web.session.WebSession)

Example 15 with WebSession

use of cn.taketoday.web.session.WebSession in project today-framework by TAKETODAY.

the class SessionScope method remove.

@Override
@Nullable
public Object remove(String name) {
    RequestContext context = RequestContextHolder.getRequired();
    WebSession session = getSession(context);
    if (session != null) {
        Object sessionMutex = WebUtils.getSessionMutex(session);
        synchronized (sessionMutex) {
            return remove(session, name);
        }
    }
    return null;
}
Also used : WebSession(cn.taketoday.web.session.WebSession) RequestContext(cn.taketoday.web.RequestContext) Nullable(cn.taketoday.lang.Nullable)

Aggregations

WebSession (cn.taketoday.web.session.WebSession)17 RequestContext (cn.taketoday.web.RequestContext)6 Nullable (cn.taketoday.lang.Nullable)4 SessionManager (cn.taketoday.web.session.SessionManager)4 HttpHeaders (cn.taketoday.http.HttpHeaders)2 LinkedHashMap (java.util.LinkedHashMap)2