Browse Source

Add attributes to WebFlux WebSocketSession

Issue: SPR-16212
pull/1833/head
Rossen Stoyanchev 7 years ago
parent
commit
9074828478
  1. 9
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketSession.java
  2. 11
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractWebSocketSession.java

9
spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketSession.java

@ -15,6 +15,8 @@ @@ -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 { @@ -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

11
spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractWebSocketSession.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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 { @@ -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();

Loading…
Cancel
Save