Honor headers in AbstractMessageSendingTemplate.convertAndSend() variant

Prior to this commit, the following method in AbstractMessageSendingTemplate
simply ignored the supplied headers map.

convertAndSend(Object, Map<String, Object>, MessagePostProcessor)

Closes gh-36120
This commit is contained in:
Sam Brannen
2026-01-09 15:03:16 +01:00
parent c53a00a6c4
commit 8d4320e9ef
2 changed files with 17 additions and 1 deletions
@@ -148,7 +148,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
public void convertAndSend(Object payload, @Nullable Map<String, Object> headers,
@Nullable MessagePostProcessor postProcessor) throws MessagingException {
convertAndSend(getRequiredDefaultDestination(), payload, null, postProcessor);
convertAndSend(getRequiredDefaultDestination(), payload, headers, postProcessor);
}
@Override
@@ -17,6 +17,7 @@
package org.springframework.messaging.core;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -50,6 +51,7 @@ import static org.mockito.Mockito.verify;
*
* @author Rossen Stoyanchev
* @author Gary Russell
* @author Sam Brannen
*/
class GenericMessagingTemplateTests {
@@ -248,6 +250,20 @@ class GenericMessagingTemplateTests {
assertThat(accessor.isMutable()).isFalse();
}
@Test
void convertAndSendWithDefaultDestinationAndSimpMessageHeaders() {
Map<String, Object> headers = Map.of("foo", "bar");
Object payload = "Hello";
TestMessagePostProcessor postProcessor = new TestMessagePostProcessor();
this.template.convertAndSend(payload, headers, postProcessor);
List<Message<byte[]>> messages = this.messageChannel.getMessages();
Message<byte[]> message = messages.get(0);
assertThat(postProcessor.getMessage().getPayload()).isEqualTo(payload);
assertThat(message.getHeaders()).containsKeys("foo");
}
private class TestDestinationResolver implements DestinationResolver<MessageChannel> {