Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native STOMP headers removed by WebSocketInboundChannelAdapter #3675

Closed
freynder opened this issue Nov 15, 2021 · 4 comments · Fixed by #3676
Closed

native STOMP headers removed by WebSocketInboundChannelAdapter #3675

freynder opened this issue Nov 15, 2021 · 4 comments · Fixed by #3676

Comments

@freynder
Copy link

Hi,

I use the WebSocket Inbound Channel Adapter with the StompSubProtocolHandler for inbound STOMP over websocket. Our client application sets a few STOMP headers that we need to read in the backend. However, these headers are explicitely removed in WebSocketInboundChannelAdapter, please see below:

Is there any reason to do so? When comparing to HTTP for example, those headers are mapped and still accessible in the resulting Message.

Thank you,

@artembilan
Copy link
Member

I cannot recall at the moment why did we remove that header, but would you mind to share more context how those custom headers can appear in the nativeHeaders entry?
What do you send on the client side?
I see this in my tests:

headers = {MessageHeaderAccessor$MutableMessageHeaders@8484}  size = 9
 "simpMessageType" -> {SimpMessageType@8498} "MESSAGE"
 "stompCommand" -> {StompCommand@8500} "MESSAGE"
 "nativeHeaders" -> {LinkedMultiValueMap@8502}  size = 5
  key = "nativeHeaders"
  value = {LinkedMultiValueMap@8502}  size = 5
   "destination" -> {ArrayList@8525}  size = 1
   "content-type" -> {ArrayList@8527}  size = 1
   "subscription" -> {ArrayList@8529}  size = 1
   "message-id" -> {ArrayList@8531}  size = 1
   "content-length" -> {ArrayList@8533}  size = 1
 "simpSessionAttributes" -> {ConcurrentHashMap@8504}  size = 0
 "simpHeartbeat" -> {long[2]@8506} [0, 0]
 "simpSubscriptionId" -> "subs1"
 "contentType" -> {MimeType@8510} "application/json"
 "simpSessionId" -> "e2b9fd630bcd4a5cbad5d991ba46ac1d"
 "simpDestination" -> "/topic/foo"

So, most of those nativeHeaders are remapped to the top-level header entries with that simp prefix.

I probly won't mind to restore such a header, if you really confirm that plain @MessageMapping with regular Spring Websocket support gives you an access to this one.

Thank you!

@artembilan artembilan added status: waiting-for-reporter Needs a feedback from the reporter in: websocket labels Nov 15, 2021
@freynder
Copy link
Author

Hi,

Thank you for the quick response.

The STOMP header provided by the client is specific to the application.

I can confirm it can be retrieved through @MessageMapping as I'm migrating this code to spring integration. Extract:

    @MessageMapping("/inbound.send")
    public ServerMessage receive(@Payload ClientMessage message, Message<ClientMessage> m,
            SimpMessageHeaderAccessor headers) throws Exception {
        String sessionId = headers.getNativeHeader(APP_SPECIFIC_SESSION_ID).get(0);

Thank you

@artembilan artembilan added this to the 5.5.6 milestone Nov 15, 2021
@artembilan artembilan added backport 5.3.x type: enhancement and removed status: waiting-for-reporter Needs a feedback from the reporter labels Nov 15, 2021
@artembilan
Copy link
Member

OK. Got it. Restoring then SimpMessageHeaderAccessor.NATIVE_HEADERS header entry in the message the WebSocketInboundChannelAdapter is producing...

artembilan added a commit to artembilan/spring-integration that referenced this issue Nov 15, 2021
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`**
@freynder
Copy link
Author

Really impressed with the quick resolution, thank you very much.

garyrussell pushed a commit that referenced this issue Nov 15, 2021
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`**
garyrussell pushed a commit that referenced this issue Nov 15, 2021
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`**
garyrussell pushed a commit that referenced this issue Nov 15, 2021
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`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants