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