Skip to content

Conversation

@catturtle123
Copy link

@catturtle123 catturtle123 commented Jan 20, 2026

This PR addresses issue #36168

Summary

  • Added an opt-in mechanism to selectively propagate headers from an input Message to the outbound Message created by:

    • SendToMethodReturnValueHandler
    • SubscriptionMethodReturnValueHandler
  • Header propagation is controlled via a configurable Predicate<String>.

  • Default behavior remains unchanged: no headers are propagated unless explicitly configured.

Resolved Issue

  • Allows applications to forward selected headers (e.g. correlation or receipt-related headers) while avoiding accidental propagation of internal or protocol-specific headers.
  • Provides a simple and explicit customization point instead of always copying or discarding headers.

Scope

  • This change applies only at the Spring Messaging layer.
  • It affects how outbound MessageHeaders are populated by handler return value processing.
  • It does not change STOMP native header serialization or WebSocket frame encoding.

Discussion Points

  • Whether the public getter (getHeaderPropagationPredicate) should be retained, or removed to keep the API strictly write-only.
  • The current scope of this PR is limited to propagating headers at the Spring Messaging level.
    A discussion point is whether this is sufficient for the intended use cases, or if extending the mechanism to STOMP native headers should be considered separately rather than as part of this change.

Integration Test

  • Behavior was validated in an end-to-end WebSocket/STOMP scenario to ensure:

    • propagated headers flow through the Spring Messaging pipeline correctly,
    • no regressions occur in routing or delivery.
  • Only unit tests are committed in this PR.

If preferred, I can also include the integration test in this PR.

스크린샷 2026-01-20 오후 12 46 02

* Predicate to determine which header names from the input message should be propagated.
* If null, no headers are propagated (default behavior).
*/
private @Nullable Predicate<String> headerPropagationPredicate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify the name to headerFilter, and no need for Javadoc on the field as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I’ve renamed it to headerFilter and removed the field-level Javadoc to keep it consistent with existing style.

* <p><b>Warning:</b> The predicate should avoid propagating or overwriting well-known protocol headers
* (e.g. headers starting with "simp", "content-type", etc.) to prevent breaking internal messaging semantics.
* </p>
* <p>If not set, no input headers are propagated (default behavior).</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of such a warning, which requires further investigation on its own, how about applying header propagation first, and then setting standard headers (like session id) second, so there is no possibility for overwriting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I’ve removed the warning and updated the order so propagated headers are applied first, followed by standard headers, to avoid any possibility of overwriting.

* <p>If not set, no input headers are propagated (default behavior).</p>
*/
public void setHeaderPropagationPredicate(@Nullable Predicate<String> predicate) {
this.headerPropagationPredicate = predicate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could allow multiple predicates to be provided, and combine those with Predicate#or, also changing the method name to add~ instead of set~.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I’ve changed the API to addHeaderFilter and combined multiple predicates using Predicate#or.

@rstoyanchev rstoyanchev self-assigned this Jan 20, 2026
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2026
@rstoyanchev rstoyanchev added this to the 7.0.4 milestone Jan 20, 2026
@rstoyanchev rstoyanchev changed the title Add header propagation predicate support to message return value hand… Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers Jan 20, 2026
@catturtle123
Copy link
Author

catturtle123 commented Jan 20, 2026

I've applied the requested changes (renaming to headerFilter, switching to add~ method with Predicate#or logic, and adjusting the execution order). I've squashed the changes into the main commit to keep the history clean as per the contribution guide. Sorry for making the delta review slightly harder.

…lers

Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers

3 participants