Ensure WebSocket disconnect msg reaches the client

In some application setups, the WebSocket server does not transmit
the disconnect message to the client, so that the client has no idea
that the established connection has been terminated.

This issue arises when the application uses SimpleBrokerMessageHandler
and the error handler is set to the instance of
StompSubProtocolErrorHandler or an extended class that does not
override the handleErrorMessageToClient method.

The commit fixes disconnect message population so that
`java.lang.IllegalArgumentException: No StompHeaderAccessor` exception
is not thrown in the handleErrorMessageToClient method in
StompSubProtocolErrorHandler class.

See gh-30120
This commit is contained in:
Aleksandrs Jansons 2023-03-05 08:39:12 +02:00 committed by rstoyanchev
parent 33ef9107e0
commit 1abe155663
1 changed files with 3 additions and 1 deletions

View File

@ -465,7 +465,9 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
}
if (StompCommand.ERROR.equals(command) && getErrorHandler() != null) {
Message<byte[]> errorMessage = getErrorHandler().handleErrorMessageToClient((Message<byte[]>) message);
Message<byte[]> enrichedMessage =
MessageBuilder.createMessage((byte[]) message.getPayload(), accessor.getMessageHeaders());
Message<byte[]> errorMessage = getErrorHandler().handleErrorMessageToClient(enrichedMessage);
if (errorMessage != null) {
accessor = MessageHeaderAccessor.getAccessor(errorMessage, StompHeaderAccessor.class);
Assert.state(accessor != null, "No StompHeaderAccessor");