2020-11-02 11:21:46.962 [clientOutboundChannel-3] ERROR  --- o.s.w.s.m.StompSubProtocolHandler.publishEvent(StompSubProtocolHandler.java:385) --- Error publishing SessionConnectedEvent[GenericMessage [payload=byte[0], headers={simpMessageType=CONNECT_ACK, spanTraceId=ae48556ad02db145, spanId=05a96dc7755e5b87, spanParentSpanId=525b2016120994a8, nativeHeaders={spanTraceId=[ae48556ad02db145], spanId=[05a96dc7755e5b87], spanParentSpanId=[525b2016120994a8], spanSampled=[1]}, simpConnectMessage=GenericMessage [payload=byte[0], headers={simpMessageType=CONNECT, simpSessionAttributes={sessionId=4A8F1D6A86E7679007D70E332BEFAE84}, simpHeartbeat=[J@25b0d6a7, spanTraceId=ae48556ad02db145, spanId=ae48556ad02db145, stompCommand=CONNECT, nativeHeaders={accept-version=[1.1,1.0], heart-beat=[10000,10000], spanTraceId=[ae48556ad02db145], spanId=[ae48556ad02db145], spanSampled=[1]}, spanSampled=1, simpSessionId=42vqpveq}], id=cc73a69b-fdc9-979e-c6f5-c325d63842a7, spanSampled=1, simpSessionId=42vqpveq}]] java.lang.IllegalStateException: No SimpMessageHeaderAccessor
    at org.springframework.util.Assert.state(Assert.java:73) ~[spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.web.socket.messaging.DefaultSimpUserRegistry.onApplicationEvent(DefaultSimpUserRegistry.java:90) ~[spring-websocket-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]

Spring DefaultSimpUserRegistry prevents event from being published if original SimpMessageHeaderAccessor cannot be found

Comment From: rstoyanchev

The call to headerAccessor.toMessageHeaders() from the example interceptor makes a completely new copy of the headers without any connection to the MessageHeaderAccessor. It should probably be using getMessageHeaders() instead.

That said we could make DefaultSimpUserRegistry more lenient in this case and access directly by name rather than expecting to find the original SimpMessageHeaderAccessor.