Skip to content

Commit e7534fc

Browse files
committed
spring-projectsGH-3675: Restore nativeHeaders for WebSocketInChA
Fixes spring-projects#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 3dabf7a commit e7534fc

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

+2-1
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
4747
import org.springframework.web.socket.messaging.SubProtocolHandler;
4848
import org.springframework.web.socket.sockjs.client.SockJsClient;
49-
import org.springframework.web.socket.sockjs.client.Transport;
5049
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
5150

5251
/**
@@ -101,7 +100,7 @@ public TomcatWebSocketTestServer server() {
101100

102101
@Bean
103102
public WebSocketClient webSocketClient() {
104-
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
103+
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
105104
}
106105

107106
@Bean

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

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public void testWebSocketOutboundMessageHandler() {
134134
assertThat(received).isNotNull();
135135
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
136136
assertThat(stompHeaderAccessor.getMessageType()).isEqualTo(StompCommand.MESSAGE.getMessageType());
137+
assertThat(stompHeaderAccessor.getNativeHeader(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER)).isNotNull();
137138

138139
Object receivedPayload = received.getPayload();
139140
assertThat(receivedPayload).isInstanceOf(String.class);

0 commit comments

Comments
 (0)