Skip to content

Commit

Permalink
GH-3675: Restore nativeHeaders for WebSocketInChA
Browse files Browse the repository at this point in the history
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`**
  • Loading branch information
artembilan authored and garyrussell committed Nov 15, 2021
1 parent 3dabf7a commit fb14976
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.springframework.web.socket.messaging.SubProtocolHandler;

/**
* The {@link MessageProducerSupport} for inbound WebSocket messages.
*
* @author Artem Bilan
*
* @since 4.1
Expand Down Expand Up @@ -356,7 +358,6 @@ private void produceConnectAckMessage(Message<?> message, SimpMessageHeaderAcces
}

private void produceMessage(Message<?> message, SimpMessageHeaderAccessor headerAccessor) {
headerAccessor.removeHeader(SimpMessageHeaderAccessor.NATIVE_HEADERS);
Object payload = this.messageConverter.fromMessage(message, this.payloadType.get());
Assert.state(payload != null,
() -> "The message converter '" + this.messageConverter +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolHandler;
import org.springframework.web.socket.sockjs.client.SockJsClient;
import org.springframework.web.socket.sockjs.client.Transport;
import org.springframework.web.socket.sockjs.client.WebSocketTransport;

/**
Expand Down Expand Up @@ -101,7 +100,7 @@ public TomcatWebSocketTestServer server() {

@Bean
public WebSocketClient webSocketClient() {
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void testWebSocketOutboundMessageHandler() {
assertThat(received).isNotNull();
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
assertThat(stompHeaderAccessor.getMessageType()).isEqualTo(StompCommand.MESSAGE.getMessageType());
assertThat(stompHeaderAccessor.getNativeHeader(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER)).isNotNull();

Object receivedPayload = received.getPayload();
assertThat(receivedPayload).isInstanceOf(String.class);
Expand Down

0 comments on commit fb14976

Please sign in to comment.