Search in sources :

Example 1 with ServiceActivatingHandler

use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.

the class MessagingGatewayTests method validateErrorChannelWithSuccessfulReply.

// should not fail but it does now
@Test
public void validateErrorChannelWithSuccessfulReply() {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    DirectChannel reqChannel = new DirectChannel();
    reqChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService());
    handler.setBeanFactory(testApplicationContext);
    handler.afterPropertiesSet();
    errorChannel.subscribe(handler);
    this.messagingGateway = new MessagingGatewaySupport() {
    };
    this.messagingGateway.setRequestChannel(reqChannel);
    this.messagingGateway.setErrorChannel(errorChannel);
    this.messagingGateway.setReplyChannel(null);
    this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
    this.messagingGateway.afterPropertiesSet();
    this.messagingGateway.start();
    this.messagingGateway.send("hello");
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 2 with ServiceActivatingHandler

use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.

the class PayloadAndHeaderMappingTests method getHandler.

private ServiceActivatingHandler getHandler(String methodName, Class<?>... types) throws Exception {
    ServiceActivatingHandler serviceActivatingHandler = new ServiceActivatingHandler(bean, TestBean.class.getMethod(methodName, types));
    serviceActivatingHandler.setBeanFactory(applicationContext);
    serviceActivatingHandler.afterPropertiesSet();
    return serviceActivatingHandler;
}
Also used : ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler)

Example 3 with ServiceActivatingHandler

use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.

the class ServiceActivatorFactoryBean method createExpressionEvaluatingHandler.

@Override
protected MessageHandler createExpressionEvaluatingHandler(Expression expression) {
    ExpressionEvaluatingMessageProcessor<Object> processor = new ExpressionEvaluatingMessageProcessor<Object>(expression);
    processor.setBeanFactory(this.getBeanFactory());
    ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
    handler.setPrimaryExpression(expression);
    return this.configureHandler(handler);
}
Also used : ExpressionEvaluatingMessageProcessor(org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler)

Example 4 with ServiceActivatingHandler

use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.

the class ServiceActivatorFactoryBean method createMethodInvokingHandler.

@Override
protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
    MessageHandler handler = null;
    handler = createDirectHandlerIfPossible(targetObject, targetMethodName);
    if (handler == null) {
        handler = configureHandler(StringUtils.hasText(targetMethodName) ? new ServiceActivatingHandler(targetObject, targetMethodName) : new ServiceActivatingHandler(targetObject));
    }
    return handler;
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler)

Example 5 with ServiceActivatingHandler

use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.

the class ServiceActivatorAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    AbstractReplyProducingMessageHandler serviceActivator;
    if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
        final Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
        serviceActivator = this.extractTypeIfPossible(target, AbstractReplyProducingMessageHandler.class);
        if (serviceActivator == null) {
            if (target instanceof MessageHandler) {
                /*
					 * Return a reply-producing message handler so that we still get 'produced no reply' messages
					 * and the super class will inject the advice chain to advise the handler method if needed.
					 */
                return new ReplyProducingMessageHandlerWrapper((MessageHandler) target);
            } else {
                serviceActivator = new ServiceActivatingHandler(target);
            }
        } else {
            checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
            return (MessageHandler) target;
        }
    } else {
        serviceActivator = new ServiceActivatingHandler(bean, method);
    }
    String requiresReply = MessagingAnnotationUtils.resolveAttribute(annotations, "requiresReply", String.class);
    if (StringUtils.hasText(requiresReply)) {
        serviceActivator.setRequiresReply(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(requiresReply)));
    }
    String isAsync = MessagingAnnotationUtils.resolveAttribute(annotations, "async", String.class);
    if (StringUtils.hasText(isAsync)) {
        serviceActivator.setAsync(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(isAsync)));
    }
    this.setOutputChannelIfPresent(annotations, serviceActivator);
    return serviceActivator;
}
Also used : AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Bean(org.springframework.context.annotation.Bean) ReplyProducingMessageHandlerWrapper(org.springframework.integration.handler.ReplyProducingMessageHandlerWrapper)

Aggregations

ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)45 Test (org.junit.Test)38 QueueChannel (org.springframework.integration.channel.QueueChannel)29 BeanFactory (org.springframework.beans.factory.BeanFactory)10 DirectChannel (org.springframework.integration.channel.DirectChannel)10 GenericMessage (org.springframework.messaging.support.GenericMessage)10 Message (org.springframework.messaging.Message)8 ServerSocket (java.net.ServerSocket)7 Socket (java.net.Socket)7 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)6 AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)6 RequestReplyExchanger (org.springframework.integration.gateway.RequestReplyExchanger)5 Date (java.util.Date)4 TcpNetServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory)4 PollableChannel (org.springframework.messaging.PollableChannel)4 IOException (java.io.IOException)3 PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)3 TestUtils (org.springframework.integration.test.util.TestUtils)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 HashMap (java.util.HashMap)2