Search in sources :

Example 51 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class ServiceActivatorEndpointTests method correlationIdSetByHandlerTakesPrecedence.

@Test
public void correlationIdSetByHandlerTakesPrecedence() {
    QueueChannel replyChannel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return MessageBuilder.fromMessage(message).setCorrelationId("ABC-123").build();
        }
    }, "handle");
    Message<String> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    endpoint.handleMessage(message);
    Message<?> reply = replyChannel.receive(500);
    Object correlationId = new IntegrationMessageHeaderAccessor(reply).getCorrelationId();
    assertFalse(message.getHeaders().getId().equals(correlationId));
    assertEquals("ABC-123", correlationId);
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 52 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class ServiceActivatorEndpointTests method correlationIdNotSetIfMessageIsReturnedUnaltered.

@Test
public void correlationIdNotSetIfMessageIsReturnedUnaltered() {
    QueueChannel replyChannel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return message;
        }
    }, "handle");
    Message<String> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    endpoint.handleMessage(message);
    Message<?> reply = replyChannel.receive(500);
    assertNull(new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 53 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class BroadcastingDispatcherTests method applySequenceDisabledByDefault.

@Test
public void applySequenceDisabledByDefault() {
    BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
    final List<Message<?>> messages = Collections.synchronizedList(new ArrayList<Message<?>>());
    MessageHandler target1 = new MessageStoringTestEndpoint(messages);
    MessageHandler target2 = new MessageStoringTestEndpoint(messages);
    dispatcher.addHandler(target1);
    dispatcher.addHandler(target2);
    dispatcher.dispatch(new GenericMessage<String>("test"));
    assertEquals(2, messages.size());
    assertEquals(0, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceNumber());
    assertEquals(0, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceSize());
    assertEquals(0, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceNumber());
    assertEquals(0, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceSize());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHandler(org.springframework.messaging.MessageHandler) Test(org.junit.Test)

Example 54 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class CorrelationIdTests method testCorrelationIdWithSplitterWhenValueSetOnIncomingMessage.

@Test
public void testCorrelationIdWithSplitterWhenValueSetOnIncomingMessage() throws Exception {
    final String correlationIdForTest = "#FOR_TEST#";
    Message<?> message = MessageBuilder.withPayload("test1,test2").setCorrelationId(correlationIdForTest).build();
    QueueChannel testChannel = new QueueChannel();
    MethodInvokingSplitter splitter = new MethodInvokingSplitter(new TestBean(), TestBean.class.getMethod("split", String.class));
    splitter.setOutputChannel(testChannel);
    splitter.handleMessage(message);
    Message<?> reply1 = testChannel.receive(100);
    Message<?> reply2 = testChannel.receive(100);
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply1).getCorrelationId());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply2).getCorrelationId());
    assertTrue("Sequence details missing", reply1.getHeaders().containsKey(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS));
    assertTrue("Sequence details missing", reply2.getHeaders().containsKey(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 55 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class CorrelationIdTests method testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler.

@Test
public void testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler() throws Exception {
    Object correlationId = "123-ABC";
    Message<String> message = MessageBuilder.withPayload("test").setCorrelationId(correlationId).build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "createMessage");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("456-XYZ", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Aggregations

IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)68 Test (org.junit.Test)56 QueueChannel (org.springframework.integration.channel.QueueChannel)32 Message (org.springframework.messaging.Message)21 GenericMessage (org.springframework.messaging.support.GenericMessage)19 MessageChannel (org.springframework.messaging.MessageChannel)15 ArrayList (java.util.ArrayList)10 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)9 DirectChannel (org.springframework.integration.channel.DirectChannel)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 List (java.util.List)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)3