Search in sources :

Example 1 with DefaultAmqpHeaderMapper

use of org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper in project spring-integration by spring-projects.

the class OutboundEndpointTests method testHeaderMapperWinsGateway.

@Test
public void testHeaderMapperWinsGateway() {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    TestRabbitTemplate amqpTemplate = spy(new TestRabbitTemplate(connectionFactory));
    AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate);
    endpoint.setHeadersMappedLast(true);
    endpoint.setExpectReply(true);
    DefaultAmqpHeaderMapper mapper = DefaultAmqpHeaderMapper.inboundMapper();
    mapper.setRequestHeaderNames("*");
    endpoint.setHeaderMapper(mapper);
    final AtomicReference<Message> amqpMessage = new AtomicReference<Message>();
    willAnswer(invocation -> {
        amqpMessage.set(invocation.getArgument(2));
        return null;
    }).given(amqpTemplate).doSendAndReceiveWithTemporary(isNull(), isNull(), any(Message.class), isNull());
    org.springframework.messaging.Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "bar").setReplyChannel(new QueueChannel()).build();
    endpoint.handleMessage(message);
    assertNotNull(amqpMessage.get());
    assertEquals("bar", amqpMessage.get().getMessageProperties().getContentType());
    assertNull(amqpMessage.get().getMessageProperties().getHeaders().get(MessageHeaders.REPLY_CHANNEL));
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) Message(org.springframework.amqp.core.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) DefaultAmqpHeaderMapper(org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 Message (org.springframework.amqp.core.Message)1 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)1 DefaultAmqpHeaderMapper (org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1