Search in sources :

Example 1 with WebSession

use of cn.taketoday.web.session.WebSession in project today-infrastructure 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 2 with WebSession

use of cn.taketoday.web.session.WebSession in project today-infrastructure 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 3 with WebSession

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

the class SessionScope method get.

@Override
public Object get(String name, Supplier<?> objectFactory) {
    RequestContext context = RequestContextHolder.getRequired();
    WebSession session = getSession(context);
    Object sessionMutex = WebUtils.getSessionMutex(session);
    synchronized (sessionMutex) {
        return get(session, name, objectFactory);
    }
}
Also used : WebSession(cn.taketoday.web.session.WebSession) RequestContext(cn.taketoday.web.RequestContext)

Example 4 with WebSession

use of cn.taketoday.web.session.WebSession in project today-infrastructure 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)

Example 5 with WebSession

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

the class AbstractController method handleRequest.

@Override
@Nullable
public ModelAndView handleRequest(RequestContext request) throws Exception {
    if (HttpMethod.OPTIONS.matches(request.getMethodValue())) {
        request.responseHeaders().set(HttpHeaders.ALLOW, getAllowHeader());
        return null;
    }
    // Delegate to WebContentGenerator for checking and preparing.
    checkRequest(request);
    prepareResponse(request);
    // Execute handleRequestInternal in synchronized block if required.
    if (this.synchronizeOnSession) {
        WebSession session = RequestContextUtils.getSession(request, false);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                return handleRequestInternal(request);
            }
        }
    }
    return handleRequestInternal(request);
}
Also used : WebSession(cn.taketoday.web.session.WebSession) 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