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);
}
}
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations