Search in sources :

Example 1 with MethodInvokingCorrelationStrategy

use of org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy in project spring-integration by spring-projects.

the class ResequencerParserTests method testCorrelationStrategyRefAndMethod.

@Test
public void testCorrelationStrategyRefAndMethod() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithCorrelationStrategyRefAndMethod");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    Object correlationStrategy = getPropertyValue(resequencer, "correlationStrategy");
    assertEquals("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter", MethodInvokingCorrelationStrategy.class, correlationStrategy.getClass());
    MethodInvokingCorrelationStrategy adapter = (MethodInvokingCorrelationStrategy) correlationStrategy;
    assertEquals("foo", adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build()));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) MethodInvokingCorrelationStrategy(org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy) Test(org.junit.Test)

Example 2 with MethodInvokingCorrelationStrategy

use of org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy in project spring-integration by spring-projects.

the class AggregatorAnnotationTests method testAnnotationWithCustomCorrelationStrategy.

@Test
public void testAnnotationWithCustomCorrelationStrategy() throws Exception {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:/org/springframework/integration/config/annotation/testAnnotatedAggregator.xml" });
    final String endpointName = "endpointWithCorrelationStrategy";
    MessageHandler aggregator = this.getAggregator(context, endpointName);
    Object correlationStrategy = getPropertyValue(aggregator, "correlationStrategy");
    Assert.assertTrue(correlationStrategy instanceof MethodInvokingCorrelationStrategy);
    MethodInvokingCorrelationStrategy releaseStrategyAdapter = (MethodInvokingCorrelationStrategy) correlationStrategy;
    DirectFieldAccessor processorAccessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(releaseStrategyAdapter).getPropertyValue("processor")).getPropertyValue("delegate"));
    Object targetObject = processorAccessor.getPropertyValue("targetObject");
    assertSame(context.getBean(endpointName), targetObject);
    assertNull(processorAccessor.getPropertyValue("handlerMethods"));
    Object handlerMethod = processorAccessor.getPropertyValue("handlerMethod");
    assertNotNull(handlerMethod);
    DirectFieldAccessor handlerMethodAccessor = new DirectFieldAccessor(handlerMethod);
    Method completionCheckerMethod = (Method) handlerMethodAccessor.getPropertyValue("invocableHandlerMethod.method");
    assertEquals("correlate", completionCheckerMethod.getName());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Method(java.lang.reflect.Method) MethodInvokingCorrelationStrategy(org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy) Test(org.junit.Test)

Example 3 with MethodInvokingCorrelationStrategy

use of org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy in project spring-integration by spring-projects.

the class AggregatorAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    MethodInvokingMessageGroupProcessor processor = new MethodInvokingMessageGroupProcessor(bean, method);
    processor.setBeanFactory(this.beanFactory);
    MethodInvokingReleaseStrategy releaseStrategy = null;
    Method releaseStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, ReleaseStrategy.class);
    if (releaseStrategyMethod != null) {
        releaseStrategy = new MethodInvokingReleaseStrategy(bean, releaseStrategyMethod);
    }
    MethodInvokingCorrelationStrategy correlationStrategy = null;
    Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class);
    if (correlationStrategyMethod != null) {
        correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod);
    }
    AggregatingMessageHandler handler = new AggregatingMessageHandler(processor, new SimpleMessageStore(), correlationStrategy, releaseStrategy);
    String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class);
    if (StringUtils.hasText(discardChannelName)) {
        handler.setDiscardChannelName(discardChannelName);
    }
    String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class);
    if (StringUtils.hasText(outputChannelName)) {
        handler.setOutputChannelName(outputChannelName);
    }
    String sendPartialResultsOnExpiry = MessagingAnnotationUtils.resolveAttribute(annotations, "sendPartialResultsOnExpiry", String.class);
    if (sendPartialResultsOnExpiry != null) {
        handler.setSendPartialResultOnExpiry(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(sendPartialResultsOnExpiry)));
    }
    handler.setBeanFactory(this.beanFactory);
    return handler;
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor) Method(java.lang.reflect.Method) MethodInvokingCorrelationStrategy(org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)

Aggregations

MethodInvokingCorrelationStrategy (org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy)3 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 AggregatingMessageHandler (org.springframework.integration.aggregator.AggregatingMessageHandler)1 MethodInvokingMessageGroupProcessor (org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor)1 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)1 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1 SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)1 MessageHandler (org.springframework.messaging.MessageHandler)1