Add attributes to WebFlux WebSocketSession
Issue: SPR-16212
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.web.reactive.socket;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -52,6 +54,13 @@ public interface WebSocketSession {
|
||||
*/
|
||||
DataBufferFactory bufferFactory();
|
||||
|
||||
/**
|
||||
* Return the map with attributes associated with the WebSocket session.
|
||||
* @return a Map with the session attributes (never {@code null})
|
||||
* @since 5.1
|
||||
*/
|
||||
Map<String, Object> getAttributes();
|
||||
|
||||
/**
|
||||
* Provides access to the stream of inbound messages.
|
||||
* <p>This stream receives a completion or error signal when the connection
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.web.reactive.socket.adapter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -48,6 +50,8 @@ public abstract class AbstractWebSocketSession<T> implements WebSocketSession {
|
||||
|
||||
private final DataBufferFactory bufferFactory;
|
||||
|
||||
private final Map<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance and associate the given attributes with it.
|
||||
@@ -86,6 +90,11 @@ public abstract class AbstractWebSocketSession<T> implements WebSocketSession {
|
||||
return this.bufferFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Flux<WebSocketMessage> receive();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user