use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class TestAnnotatedEndpointWithCustomizedAggregator method aggregatingMethod.
@Aggregator(inputChannel = "inputChannel", outputChannel = "outputChannel", discardChannel = "discardChannel", sendPartialResultsOnExpiry = "true", sendTimeout = "98765432")
public Message<?> aggregatingMethod(List<Message<?>> messages) {
List<Message<?>> sortableList = new ArrayList<>(messages);
Collections.sort(sortableList, new MessageSequenceComparator());
StringBuffer buffer = new StringBuffer();
Object correlationId = null;
for (Message<?> message : sortableList) {
buffer.append(message.getPayload().toString());
if (null == correlationId) {
correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
}
}
Message<?> returnedMessage = new GenericMessage<>(buffer.toString());
aggregatedMessages.put(correlationId, returnedMessage);
return returnedMessage;
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class TestAggregatorBean method createSingleMessageFromGroup.
@Aggregator
public Message<?> createSingleMessageFromGroup(List<Message<?>> messages) {
List<Message<?>> sortableList = new ArrayList<>(messages);
Collections.sort(sortableList, new MessageSequenceComparator());
StringBuffer buffer = new StringBuffer();
Object correlationId = null;
for (Message<?> message : sortableList) {
buffer.append(message.getPayload().toString());
if (null == correlationId) {
correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
}
}
Message<?> returnedMessage = new GenericMessage<>(buffer.toString());
if (correlationId != null) {
this.aggregatedMessages.put(correlationId, returnedMessage);
}
return returnedMessage;
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class SplitterParserTests method splitterParserTestApplySequenceFalse.
@Test
public void splitterParserTestApplySequenceFalse() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("splitterParserTests.xml", this.getClass());
context.start();
DirectChannel inputChannel = context.getBean("noSequenceInput", DirectChannel.class);
PollableChannel output = (PollableChannel) context.getBean("output");
inputChannel.send(MessageBuilder.withPayload(Collections.emptyList()).build());
Message<?> message = output.receive(1000);
assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceNumber(), is(0));
assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceSize(), is(0));
context.close();
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class DefaultSplitterTests method splitFlux.
@Test
public void splitFlux() {
Message<?> message = new GenericMessage<>(Flux.generate(() -> 0, (state, sink) -> {
if (state == 10) {
sink.complete();
} else {
sink.next(state);
}
return ++state;
}));
QueueChannel outputChannel = new QueueChannel();
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(outputChannel);
splitter.handleMessage(message);
for (int i = 0; i < 10; i++) {
Message<?> reply = outputChannel.receive(0);
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
assertNull(outputChannel.receive(10));
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class HeaderFilterTests method testFilterWithinHandler.
@Test
public void testFilterWithinHandler() {
UUID correlationId = UUID.randomUUID();
QueueChannel replyChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("test").setHeader("x", 1).setHeader("y", 2).setHeader("z", 3).setCorrelationId(correlationId).setReplyChannel(replyChannel).setErrorChannelName("testErrorChannel").build();
HeaderFilter filter = new HeaderFilter("x", "z");
MessageTransformingHandler handler = new MessageTransformingHandler(filter);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(message);
Message<?> result = replyChannel.receive(0);
assertNotNull(result);
assertNotNull(result.getHeaders().get("y"));
assertNull(result.getHeaders().get("x"));
assertNull(result.getHeaders().get("z"));
assertEquals("testErrorChannel", result.getHeaders().getErrorChannel());
assertEquals(replyChannel, result.getHeaders().getReplyChannel());
assertEquals(correlationId, new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Aggregations