From 1d470fc3755c8534b18d5319c599b1257e576d6c Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Fri, 6 Feb 2026 17:08:04 +0000 Subject: [PATCH] Exposes headerFilter on SimpAnnotationMethodMessageHandler Closes gh-36179 --- .../SimpAnnotationMethodMessageHandler.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index 6a6970a5f01..160a48ba236 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.jspecify.annotations.Nullable; @@ -118,6 +119,8 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan private @Nullable MessageHeaderInitializer headerInitializer; + private @Nullable Predicate headerFilter; + private @Nullable Integer phase; private volatile boolean running; @@ -268,6 +271,22 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan return this.headerInitializer; } + /** + * Add a filter to determine which headers from the input message should be + * propagated to the output message. Applies to return value handling of + * {@code @SendTo}, {@code @SendToUser}, and {@code @SubscribeMapping} + * controller methods. Multiple filters are combined with + * {@link Predicate#or(Predicate)}. + *

By default, no headers are propagated if this is not set. + * @since 7.0.4 + * @see SendToMethodReturnValueHandler#addHeaderFilter(Predicate) + * @see SubscriptionMethodReturnValueHandler#addHeaderFilter(Predicate) + */ + public void addHeaderFilter(Predicate filter) { + Assert.notNull(filter, "'headerFilter' predicate must not be null"); + this.headerFilter = (this.headerFilter != null ? this.headerFilter.or(filter) : filter); + } + /** * Set the phase that this handler should run in. *

By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with