Search in sources :

Example 36 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerSeveralMethods.

@Test
public /*
	 * A handler and message handler fallback (RRE); don't force RRE
	 */
void testRequestReplyExchangerSeveralMethods() {
    RequestReplyExchanger testBean = new RequestReplyExchanger() {

        @Override
        public Message<?> exchange(Message<?> request) {
            return request;
        }

        @SuppressWarnings("unused")
        public String foo(String request) {
            return request.toUpperCase();
        }
    };
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
    PollableChannel outputChannel = new QueueChannel();
    serviceActivator.setOutputChannel(outputChannel);
    Message<?> test = new GenericMessage<Object>(new Date());
    serviceActivator.handleMessage(test);
    assertEquals(test, outputChannel.receive(10));
    test = new GenericMessage<Object>("foo");
    serviceActivator.handleMessage(test);
    assertEquals("FOO", outputChannel.receive(10).getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) PollableChannel(org.springframework.messaging.PollableChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Date(java.util.Date) Test(org.junit.Test)

Example 37 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method singlePublicMethodMatches.

@Test
public void singlePublicMethodMatches() {
    SinglePublicMethodTestBean testBean = new SinglePublicMethodTestBean();
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
    QueueChannel outputChannel = new QueueChannel();
    serviceActivator.setOutputChannel(outputChannel);
    serviceActivator.handleMessage(new GenericMessage<String>("foo"));
    Message<?> result = outputChannel.receive(0);
    assertEquals("FOO", result.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 38 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method singleAnnotationMatches.

@Test
public void singleAnnotationMatches() {
    SingleAnnotationTestBean testBean = new SingleAnnotationTestBean();
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
    QueueChannel outputChannel = new QueueChannel();
    serviceActivator.setOutputChannel(outputChannel);
    serviceActivator.handleMessage(new GenericMessage<String>("foo"));
    Message<?> result = outputChannel.receive(0);
    assertEquals("FOO", result.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 39 with ServiceActivatingHandler

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

the class IntegrationFlowDefinition method handle.

/**
 * Populate a {@link ServiceActivatingHandler} for the
 * {@link org.springframework.integration.handler.MessageProcessor} from the provided
 *  {@link MessageProcessorSpec}.
 * In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
 * <pre class="code">
 * {@code
 *  .handle(Scripts.script("classpath:myScript.ruby"), e -> e.autoStartup(false))
 * }
 * </pre>
 * @param messageProcessorSpec the {@link MessageProcessorSpec} to use.
 * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
 * @return the current {@link IntegrationFlowDefinition}.
 */
public B handle(MessageProcessorSpec<?> messageProcessorSpec, Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) {
    Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null");
    MessageProcessor<?> processor = messageProcessorSpec.get();
    return addComponent(processor).handle(new ServiceActivatingHandler(processor), endpointConfigurer);
}
Also used : ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler)

Example 40 with ServiceActivatingHandler

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

the class MessagingGatewayTests method validateErroMessageCanNotBeReplyMessage.

// should fail but it doesn't now
@Test(expected = MessagingException.class)
public void validateErroMessageCanNotBeReplyMessage() {
    DirectChannel reqChannel = new DirectChannel();
    reqChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyErrorService());
    handler.setBeanFactory(mock(BeanFactory.class));
    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.sendAndReceiveMessage("hello");
}
Also used : 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)

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