How do you handle exceptions in WebSocket controllers?
Use @MessageExceptionHandler and @SendToUser to return errors to the failing STOMP client, share handlers through @ControllerAdvice, and cover validation.
2,882 posts about Java: questions with answers, tutorials and articles, newest first.
Use @MessageExceptionHandler and @SendToUser to return errors to the failing STOMP client, share handlers through @ControllerAdvice, and cover validation.
@MessageExceptionHandler catches exceptions thrown by @MessageMapping methods in Spring WebSocket apps and lets you send a clean error reply to the client.
Use a ChannelInterceptor to validate, modify or reject STOMP messages in Spring WebSocket, and combine it with Spring Security for destination rules.
MessageBrokerRegistry configures the broker behind Spring STOMP WebSocket messaging: destination prefixes, the simple in-memory broker and external broker relays.
Secure Spring WebSocket and STOMP endpoints with Spring Security 6: handshake authentication, message authorization, CSRF handling and token based login.
@EnableGlobalMethodSecurity enables method-level security in Spring but is deprecated. See how to migrate to @EnableMethodSecurity.
Authenticate WebSocket clients with OAuth2 bearer tokens in Spring Security, authorize each STOMP message, and handle expiring tokens on long-lived connections.
The class does not exist in Spring Security. See what the old configurer was, why it was removed in 6.0, and how to secure STOMP messaging with an AuthorizationManager.
Secure WebSocket connections in Spring with TLS, authenticated handshakes, STOMP authorization rules, origin checks, JWT validation and abuse limits.
Spring checks the Origin header during the WebSocket handshake. Set allowed origin patterns on the handler or STOMP endpoint to accept other domains.
How a @Configuration class sets up Spring WebSocket handlers, STOMP endpoints, interceptors and allowed origins, with raw and STOMP examples.
Register a HandshakeInterceptor to authenticate or reject a WebSocket upgrade, store session attributes, and set the user with a custom handshake handler.
HandshakeInterceptor lets Spring code inspect or reject a WebSocket upgrade request. Learn how to authenticate callers and pass data into the WebSocket session.
Handle open, error and close events in Spring WebSocket with TextWebSocketHandler, handshake interceptors, STOMP session events and heartbeats.
Use SimpMessagingTemplate to publish to topics, individual users or one session. Methods, headers and pitfalls are covered with examples.
Use /user destinations with SimpMessagingTemplate.convertAndSendToUser and an authenticated Principal to deliver STOMP messages to a single user, with full Spring Boot examples.
@SubscribeMapping answers a STOMP subscription with a direct one-time reply. See config, a full example, and how it differs from @MessageMapping.
Learn the role of WebSocketSession in Spring: sending messages, handshake data, principal, attributes, thread safety and closing connections with status codes.
Configure a STOMP broker in Spring Boot 3 and broadcast to all subscribers with @SendTo or SimpMessagingTemplate. Includes a client and scaling notes.
@SendTo publishes a STOMP handler result to a topic that clients subscribe to. See the config, dynamic destinations, user-specific replies and when to use SimpMessagingTemplate.