Skip to content

Commit 43b78e0

Browse files
artembilangaryrussell
authored andcommitted
GH-3675: Restore nativeHeaders for WebSocketInChA
Fixes #3675 The `WebSocketInboundChannelAdapter` removes a `SimpMessageHeaderAccessor.NATIVE_HEADERS` from headers used to create an outbound message. Turns out not all native headers are mapped by the `StompHeaderAccessor` to the top-level header entries. **Cherry-pick to `5.4.x` & `5.3.x`**
1 parent 83a488c commit 43b78e0

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
import org.springframework.web.socket.messaging.SubProtocolHandler;
6464

6565
/**
66+
* The {@link MessageProducerSupport} for inbound WebSocket messages.
67+
*
6668
* @author Artem Bilan
6769
*
6870
* @since 4.1
@@ -356,7 +358,6 @@ private void produceConnectAckMessage(Message<?> message, SimpMessageHeaderAcces
356358
}
357359

358360
private void produceMessage(Message<?> message, SimpMessageHeaderAccessor headerAccessor) {
359-
headerAccessor.removeHeader(SimpMessageHeaderAccessor.NATIVE_HEADERS);
360361
Object payload = this.messageConverter.fromMessage(message, this.payloadType.get());
361362
Assert.state(payload != null,
362363
() -> "The message converter '" + this.messageConverter +

spring-integration-websocket/src/test/java/org/springframework/integration/websocket/outbound/WebSocketOutboundMessageHandlerTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
4949
import org.springframework.web.socket.messaging.SubProtocolHandler;
5050
import org.springframework.web.socket.sockjs.client.SockJsClient;
51-
import org.springframework.web.socket.sockjs.client.Transport;
5251
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
5352

5453
/**
@@ -103,7 +102,7 @@ public TomcatWebSocketTestServer server() {
103102

104103
@Bean
105104
public WebSocketClient webSocketClient() {
106-
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
105+
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
107106
}
108107

109108
@Bean

spring-integration-websocket/src/test/java/org/springframework/integration/websocket/server/WebSocketServerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void testWebSocketOutboundMessageHandler() {
137137
assertThat(received).isNotNull();
138138
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
139139
assertThat(stompHeaderAccessor.getMessageType()).isEqualTo(StompCommand.MESSAGE.getMessageType());
140+
assertThat(stompHeaderAccessor.getNativeHeader(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER)).isNotNull();
140141

141142
Object receivedPayload = received.getPayload();
142143
assertThat(receivedPayload).isInstanceOf(String.class);

0 commit comments

Comments
 (0)