Search in sources :

Example 1 with MethodInvokingRouter

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

the class RouterParserTests method timeoutValueConfigured.

@Test
public void timeoutValueConfigured() {
    assertTrue(this.routerWithTimeout instanceof MethodInvokingRouter);
    MessagingTemplate template = TestUtils.getPropertyValue(this.routerWithTimeout, "messagingTemplate", MessagingTemplate.class);
    Long timeout = TestUtils.getPropertyValue(template, "sendTimeout", Long.class);
    assertEquals(new Long(1234), timeout);
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MethodInvokingRouter(org.springframework.integration.router.MethodInvokingRouter) Test(org.junit.Test)

Example 2 with MethodInvokingRouter

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

the class RouterAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    AbstractMessageRouter router;
    if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
        Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
        router = this.extractTypeIfPossible(target, AbstractMessageRouter.class);
        if (router == null) {
            if (target instanceof MessageHandler) {
                Assert.isTrue(this.routerAttributesProvided(annotations), "'defaultOutputChannel', 'applySequence', " + "'ignoreSendFailures', 'resolutionRequired', 'channelMappings', 'prefix' and 'suffix' " + "can be applied to 'AbstractMessageRouter' implementations, but target handler is: " + target.getClass());
                return (MessageHandler) target;
            } else {
                router = new MethodInvokingRouter(target);
            }
        } else {
            checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
            return router;
        }
    } else {
        router = new MethodInvokingRouter(bean, method);
    }
    String defaultOutputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "defaultOutputChannel", String.class);
    if (StringUtils.hasText(defaultOutputChannelName)) {
        router.setDefaultOutputChannelName(defaultOutputChannelName);
    }
    String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
    if (StringUtils.hasText(applySequence)) {
        router.setApplySequence(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(applySequence)));
    }
    String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, "ignoreSendFailures", String.class);
    if (StringUtils.hasText(ignoreSendFailures)) {
        router.setIgnoreSendFailures(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(ignoreSendFailures)));
    }
    if (this.routerAttributesProvided(annotations)) {
        MethodInvokingRouter methodInvokingRouter = (MethodInvokingRouter) router;
        String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, "resolutionRequired", String.class);
        if (StringUtils.hasText(resolutionRequired)) {
            String resolutionRequiredValue = this.beanFactory.resolveEmbeddedValue(resolutionRequired);
            if (StringUtils.hasText(resolutionRequiredValue)) {
                methodInvokingRouter.setResolutionRequired(Boolean.parseBoolean(resolutionRequiredValue));
            }
        }
        String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, "prefix", String.class);
        if (StringUtils.hasText(prefix)) {
            methodInvokingRouter.setPrefix(this.beanFactory.resolveEmbeddedValue(prefix));
        }
        String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, "suffix", String.class);
        if (StringUtils.hasText(suffix)) {
            methodInvokingRouter.setSuffix(this.beanFactory.resolveEmbeddedValue(suffix));
        }
        String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, "channelMappings", String[].class);
        if (!ObjectUtils.isEmpty(channelMappings)) {
            StringBuilder mappings = new StringBuilder();
            for (String channelMapping : channelMappings) {
                mappings.append(channelMapping).append("\n");
            }
            Properties properties = (Properties) this.conversionService.convert(mappings.toString(), TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Properties.class));
            methodInvokingRouter.replaceChannelMappings(properties);
        }
    }
    return router;
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) AbstractMessageRouter(org.springframework.integration.router.AbstractMessageRouter) MethodInvokingRouter(org.springframework.integration.router.MethodInvokingRouter) Properties(java.util.Properties) Bean(org.springframework.context.annotation.Bean)

Example 3 with MethodInvokingRouter

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

the class GroovyRouterTests method testInt2433VerifyRiddingOfMessageProcessorsWrapping.

@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
    assertTrue(this.groovyRouterMessageHandler instanceof MethodInvokingRouter);
    @SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovyRouterMessageHandler, "messageProcessor", MessageProcessor.class);
    // before it was MethodInvokingMessageProcessor
    assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
Also used : MessageProcessor(org.springframework.integration.handler.MessageProcessor) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) MethodInvokingRouter(org.springframework.integration.router.MethodInvokingRouter) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) Test(org.junit.Test)

Aggregations

MethodInvokingRouter (org.springframework.integration.router.MethodInvokingRouter)3 Test (org.junit.Test)2 Properties (java.util.Properties)1 Bean (org.springframework.context.annotation.Bean)1 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)1 GroovyScriptExecutingMessageProcessor (org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor)1 MessageProcessor (org.springframework.integration.handler.MessageProcessor)1 AbstractMessageRouter (org.springframework.integration.router.AbstractMessageRouter)1 MessageHandler (org.springframework.messaging.MessageHandler)1