Search in sources :

Example 1 with MethodInvokingSplitter

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;
}
Also used : MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) MessageHandler(org.springframework.messaging.MessageHandler) AbstractMessageSplitter(org.springframework.integration.splitter.AbstractMessageSplitter) Bean(org.springframework.context.annotation.Bean)

Example 2 with MethodInvokingSplitter

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());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 3 with MethodInvokingSplitter

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);
}
Also used : MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter)

Example 4 with MethodInvokingSplitter

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);
}
Also used : MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) MessageProcessor(org.springframework.integration.handler.MessageProcessor) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) Test(org.junit.Test)

Example 5 with MethodInvokingSplitter

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));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Aggregations

MethodInvokingSplitter (org.springframework.integration.splitter.MethodInvokingSplitter)5 Test (org.junit.Test)3 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 Bean (org.springframework.context.annotation.Bean)1 GroovyScriptExecutingMessageProcessor (org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor)1 MessageProcessor (org.springframework.integration.handler.MessageProcessor)1 AbstractMessageSplitter (org.springframework.integration.splitter.AbstractMessageSplitter)1 MessageHandler (org.springframework.messaging.MessageHandler)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1