mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
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:
+1
-1
@@ -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
|
||||
|
||||
+16
@@ -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> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user