@ -16,6 +16,7 @@
package org.springframework.web.server;
import java.util.Map;
import java.util.Optional;
import reactor.core.publisher.Mono;
@ -46,6 +47,14 @@ public interface ServerWebExchange {
*/
Map<String, Object> getAttributes();
/**
* Return the request attribute value if present.
* @param name the attribute name
* @param <T> the attribute type
* @return the attribute value
<T> Optional<T> getAttribute(String name);
* Return the web session for the current request. Always guaranteed to
* return an instance either matching to the session id requested by the
@ -18,6 +18,7 @@ package org.springframework.web.server;
import java.time.Duration;
import java.time.Instant;
@ -44,6 +45,14 @@ public interface WebSession {
* Return the attribute value if present.
* Force the creation of a session causing the session id to be sent when
* {@link #save()} is called.
package org.springframework.web.server.adapter;
import java.util.concurrent.ConcurrentHashMap;
import reactor.core.publisher.EmitterProcessor;
@ -78,6 +79,11 @@ public class DefaultServerWebExchange implements ServerWebExchange {
return this.attributes;
}
@Override @SuppressWarnings("unchecked")
public <T> Optional<T> getAttribute(String name) {
return Optional.ofNullable((T) this.attributes.get(name));
@Override
public Mono<WebSession> getSession() {
if (this.sessionMono == null) {
@ -20,6 +20,7 @@ import java.time.Clock;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
@ -101,6 +102,11 @@ public class DefaultWebSession implements ConfigurableWebSession, Serializable {
public Instant getCreationTime() {
return this.creationTime;