use of org.springframework.integration.splitter.MethodInvokingSplitter in project spring-integration by spring-projects.
the class SplitterAnnotationPostProcessor method createHandler.
@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
AbstractMessageSplitter splitter;
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
splitter = this.extractTypeIfPossible(target, AbstractMessageSplitter.class);
if (splitter == null) {
if (target instanceof MessageHandler) {
Assert.hasText(applySequence, "'applySequence' can be applied to 'AbstractMessageSplitter', but " + "target handler is: " + target.getClass());
return (MessageHandler) target;
} else {
splitter = new MethodInvokingSplitter(target);
}
} else {
checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
return splitter;
}
} else {
splitter = new MethodInvokingSplitter(bean, method);
}
if (StringUtils.hasText(applySequence)) {
String applySequenceValue = this.beanFactory.resolveEmbeddedValue(applySequence);
if (StringUtils.hasText(applySequenceValue)) {
splitter.setApplySequence(Boolean.parseBoolean(applySequenceValue));
}
}
this.setOutputChannelIfPresent(annotations, splitter);
return splitter;
}
use of org.springframework.integration.splitter.MethodInvokingSplitter in project spring-integration by spring-projects.
the class CorrelationIdTests method testCorrelationIdWithSplitterWhenNotValueSetOnIncomingMessage.
@Test
public void testCorrelationIdWithSplitterWhenNotValueSetOnIncomingMessage() throws Exception {
Message<?> message = new GenericMessage<String>("test1,test2");
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());
}
use of org.springframework.integration.splitter.MethodInvokingSplitter in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method split.
/**
* Populate the {@link MethodInvokingSplitter} to evaluate the
* {@link org.springframework.integration.handler.MessageProcessor} at runtime
* from provided {@link MessageProcessorSpec}.
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
* <pre class="code">
* {@code
* .split(Scripts.script(myScriptResource).lang("groovy").refreshCheckDelay(1000),
* , e -> e.applySequence(false))
* }
* </pre>
* @param messageProcessorSpec the splitter {@link MessageProcessorSpec}.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}.
* @return the current {@link IntegrationFlowDefinition}.
* @see SplitterEndpointSpec
*/
public B split(MessageProcessorSpec<?> messageProcessorSpec, Consumer<SplitterEndpointSpec<MethodInvokingSplitter>> endpointConfigurer) {
Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null");
MessageProcessor<?> processor = messageProcessorSpec.get();
return addComponent(processor).split(new MethodInvokingSplitter(processor), endpointConfigurer);
}
use of org.springframework.integration.splitter.MethodInvokingSplitter in project spring-integration by spring-projects.
the class GroovySplitterTests method testInt2433VerifyRiddingOfMessageProcessorsWrapping.
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovySplitterMessageHandler instanceof MethodInvokingSplitter);
@SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovySplitterMessageHandler, "messageProcessor", MessageProcessor.class);
// before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
use of org.springframework.integration.splitter.MethodInvokingSplitter 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));
}
Aggregations