From f8b9746ff56b43385e04e0bacdbbefb62e7492a1 Mon Sep 17 00:00:00 2001 From: cuitianhao <54015884+tianhaocui@users.noreply.github.com> Date: Sun, 19 Apr 2026 17:55:53 +0800 Subject: [PATCH] Set host header consistently in STOMP relay CONNECT frames StompBrokerRelayMessageHandler only set the host header in CONNECT frames when virtualHost was explicitly configured. Per STOMP 1.2, the host header is required on CONNECT frames. Fall back to relayHost (the TCP connection target) when virtualHost is not configured, ensuring the host header is always present in both system session and client session CONNECT frames. Closes spring-projects/spring-framework#36663 Signed-off-by: cuitianhao <54015884+tianhaocui@users.noreply.github.com> --- .../simp/stomp/StompBrokerRelayMessageHandler.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index cab92b50ac86..6c5aeb5f17e9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -456,10 +456,7 @@ protected void startInternal() { accessor.setLogin(this.systemLogin); accessor.setPasscode(this.systemPasscode); accessor.setHeartbeat(this.systemHeartbeatSendInterval, this.systemHeartbeatReceiveInterval); - String virtualHost = getVirtualHost(); - if (virtualHost != null) { - accessor.setHost(virtualHost); - } + accessor.setHost(getVirtualHost() != null ? getVirtualHost() : getRelayHost()); accessor.setSessionId(SYSTEM_SESSION_ID); if (logger.isDebugEnabled()) { logger.debug("Forwarding " + accessor.getShortLogMessage(EMPTY_PAYLOAD)); @@ -582,9 +579,7 @@ else if (accessor instanceof SimpMessageHeaderAccessor) { stompHeaderAccessor = (stompHeaderAccessor.isMutable() ? stompHeaderAccessor : StompHeaderAccessor.wrap(message)); stompHeaderAccessor.setLogin(this.clientLogin); stompHeaderAccessor.setPasscode(this.clientPasscode); - if (getVirtualHost() != null) { - stompHeaderAccessor.setHost(getVirtualHost()); - } + stompHeaderAccessor.setHost(getVirtualHost() != null ? getVirtualHost() : getRelayHost()); RelayConnectionHandler handler = new RelayConnectionHandler(sessionId, stompHeaderAccessor); this.connectionHandlers.put(sessionId, handler); this.stats.incrementConnectCount();