Package vaultWeb.config.websocket
Class WebSocketConfig
java.lang.Object
vaultWeb.config.websocket.WebSocketConfig
- All Implemented Interfaces:
org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig
extends Object
implements org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
WebSocket configuration enabling STOMP messaging for real-time chat functionality. Sets up the
message broker with an in-memory topic destination and registers the WebSocket endpoint with
SockJS fallback support.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigureClientInboundChannel(org.springframework.messaging.simp.config.ChannelRegistration registration) Configure the inbound channel for STOMP messages from clients.voidconfigureMessageBroker(org.springframework.messaging.simp.config.MessageBrokerRegistry config) Configure message broker with a simple in-memory broker for topics and application destination prefix for incoming messages.voidregisterStompEndpoints(org.springframework.web.socket.config.annotation.StompEndpointRegistry registry) Register STOMP WebSocket endpoint at "/ws-chat" with SockJS fallback and allow all origins (adjust for production).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
addArgumentResolvers, addReturnValueHandlers, configureClientOutboundChannel, configureMessageConverters, configureWebSocketTransport, getPhase
-
Constructor Details
-
WebSocketConfig
public WebSocketConfig()
-
-
Method Details
-
configureMessageBroker
public void configureMessageBroker(org.springframework.messaging.simp.config.MessageBrokerRegistry config) Configure message broker with a simple in-memory broker for topics and application destination prefix for incoming messages.- Specified by:
configureMessageBrokerin interfaceorg.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer- Parameters:
config- the message broker registry
-
registerStompEndpoints
public void registerStompEndpoints(org.springframework.web.socket.config.annotation.StompEndpointRegistry registry) Register STOMP WebSocket endpoint at "/ws-chat" with SockJS fallback and allow all origins (adjust for production).- Specified by:
registerStompEndpointsin interfaceorg.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer- Parameters:
registry- the STOMP endpoint registry
-
configureClientInboundChannel
public void configureClientInboundChannel(org.springframework.messaging.simp.config.ChannelRegistration registration) Configure the inbound channel for STOMP messages from clients. This method adds a ChannelInterceptor that intercepts incoming messages before they reach message-handling methods. During the CONNECT command, it extracts the JWT token from the "Authorization" header, validates it, and sets the corresponding Spring Security Authentication object as the user for the session. This enables per-user messaging and security checks for WebSocket messages.- Specified by:
configureClientInboundChannelin interfaceorg.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer- Parameters:
registration- the client inbound channel registration
-