I have been trying to retrieve the WebSession from WebSocketSessionHandler (namespace: org.springframework.web.reactive.socket) in order to use it in my send consumer (using FluxSink).
I have been digging through the whole spring source code and documentations which didn't seem up to date yet and I didn't find anything about the last versions.
Is it possible to retrieve the WebSession or are there ways to get only the id?
Here is sample code: WebSocketHandler.java
public class WebSocketHandler implements org.springframework.web.reactive.socket.WebSocketHandler {
/**
* {@inheritDoc}
*/
@Override
public Mono<Void> handle(final WebSocketSession session) {
// use session to receive message etc...
return (session.send(Flux.create((FluxSink<OutputMessageInterface> sink) -> {
// use sink
}).map(/* ... convert from string to WebSocketMessage ... */)));
}
}
And the configuration file: WebSocketConfiguration.java
@Configuration
public class WebSocketConfiguration {
@Bean
public WebSocketHandler webSocketHandler() {
return (new WebSocketHandler());
}
@Bean
public WebSocketHandlerAdapter handlerAdapter() {
return (new WebSocketHandlerAdapter());
}
@Bean
public HandlerMapping handlerMapping(@Autowired WebSocketHandler webSocketHandler) {
Map<String, WebSocketHandler> map = new HashMap<>();
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
map.put("/realtime", webSocketHandler);
mapping.setOrder(10);
mapping.setUrlMap(map);
return (mapping);
}
}
The project is based on spring-boot 2.0.0.M6, spring-boot-starter-webflux 2.0.0.M6 (spring-core 5.0.1.RELEASE)