Skip to content

Commit

Permalink
Ensure WebSocket disconnect msg reaches the client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexjansons authored and Aleksandrs Jansons committed Mar 16, 2023
1 parent 1de36ab commit cb785e1
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ else if (StompCommand.CONNECTED.equals(command)) {
}

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");
Expand Down

0 comments on commit cb785e1

Please sign in to comment.