diff --git a/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java b/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java index 1236f3d777..cde58e392e 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.util.Assert; -import org.springframework.web.context.request.async.WebAsyncManager; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebSession; @@ -41,6 +40,7 @@ public class DefaultWebSessionManager implements WebSessionManager { private static final Log logger = LogFactory.getLog(DefaultWebSessionManager.class); + private WebSessionIdResolver sessionIdResolver = new CookieWebSessionIdResolver(); private WebSessionStore sessionStore = new InMemoryWebSessionStore(); @@ -84,15 +84,18 @@ public class DefaultWebSessionManager implements WebSessionManager { @Override public Mono getSession(ServerWebExchange exchange) { return Mono.defer(() -> retrieveSession(exchange) - .switchIfEmpty(Mono.defer(() -> { - if (logger.isDebugEnabled()) { - logger.debug("Did not find an existing WebSession, creating a new one."); - } - return this.sessionStore.createWebSession(); - })) + .switchIfEmpty(createWebSession()) .doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session)))); } + private Mono createWebSession() { + Mono session = this.sessionStore.createWebSession(); + if (logger.isDebugEnabled()) { + session = session.doOnNext(s -> logger.debug("Created new WebSession.")); + } + return session; + } + private Mono retrieveSession(ServerWebExchange exchange) { return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange)) .concatMap(this.sessionStore::retrieveSession) @@ -106,7 +109,7 @@ public class DefaultWebSessionManager implements WebSessionManager { if (!ids.isEmpty()) { // Expired on retrieve or while processing request, or invalidated.. if (logger.isDebugEnabled()) { - logger.debug("Expiring existing sessionIds while saving session."); + logger.debug("WebSession expired or has been invalidated"); } this.sessionIdResolver.expireSession(exchange); }