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);
}
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());
}
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());
}
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));
}
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());
}
Aggregations