Search in sources :

Example 6 with WebSession

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

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

the class RequestMappingHandlerAdapter method handleInternal.

@Override
protected Object handleInternal(RequestContext request, HandlerMethod handlerMethod) throws Throwable {
    Object returnValue;
    checkRequest(request);
    // Execute invokeHandlerMethod in synchronized block if required.
    if (synchronizeOnSession) {
        WebSession session = getSession(request);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                returnValue = invokeHandlerMethod(request, handlerMethod);
            }
        } else {
            // No Session available -> no mutex necessary
            returnValue = invokeHandlerMethod(request, handlerMethod);
        }
    } else {
        // No synchronization on session demanded at all...
        returnValue = invokeHandlerMethod(request, handlerMethod);
    }
    HttpHeaders headers = request.getHeaders();
    if (!headers.containsKey(HEADER_CACHE_CONTROL)) {
        if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
            applyCacheSeconds(request, cacheSecondsForSessionAttributeHandlers);
        } else {
            prepareResponse(request);
        }
    }
    return returnValue;
}
Also used : HttpHeaders(cn.taketoday.http.HttpHeaders) WebSession(cn.taketoday.web.session.WebSession)

Example 8 with WebSession

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

Example 9 with WebSession

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

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

the class SessionScope method getConversationId.

@Override
public String getConversationId() {
    RequestContext context = RequestContextHolder.getRequired();
    WebSession session = getSession(context, false);
    if (session != null) {
        return session.getId();
    }
    return null;
}
Also used : WebSession(cn.taketoday.web.session.WebSession) RequestContext(cn.taketoday.web.RequestContext)

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