Search in sources :

Example 6 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method dynamicReplyChannel.

@Test
public void dynamicReplyChannel() throws Exception {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    final QueueChannel replyChannel1 = new QueueChannel();
    final QueueChannel replyChannel2 = new QueueChannel();
    replyChannel2.setBeanName("replyChannel2");
    Object handler = new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return new GenericMessage<String>("foo" + message.getPayload());
        }
    };
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(handler, "handle");
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("replyChannel2", replyChannel2);
    endpoint.setChannelResolver(channelResolver);
    endpoint.setBeanFactory(testApplicationContext);
    endpoint.afterPropertiesSet();
    Message<String> testMessage1 = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel1).build();
    endpoint.handleMessage(testMessage1);
    Message<?> reply1 = replyChannel1.receive(50);
    assertNotNull(reply1);
    assertEquals("foobar", reply1.getPayload());
    Message<?> reply2 = replyChannel2.receive(0);
    assertNull(reply2);
    Message<String> testMessage2 = MessageBuilder.fromMessage(testMessage1).setReplyChannelName("replyChannel2").build();
    endpoint.handleMessage(testMessage2);
    reply1 = replyChannel1.receive(0);
    assertNull(reply1);
    reply2 = replyChannel2.receive(0);
    assertNotNull(reply2);
    assertEquals("foobar", reply2.getPayload());
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 7 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method returnAddressHeaderWithChannelName.

@Test
public void returnAddressHeaderWithChannelName() {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    QueueChannel channel = new QueueChannel(1);
    channel.setBeanName("testChannel");
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("testChannel", channel);
    ServiceActivatingHandler endpoint = this.createEndpoint();
    endpoint.setChannelResolver(channelResolver);
    endpoint.setBeanFactory(testApplicationContext);
    endpoint.afterPropertiesSet();
    Message<?> message = MessageBuilder.withPayload("foo").setReplyChannelName("testChannel").build();
    endpoint.handleMessage(message);
    Message<?> reply = channel.receive(0);
    assertNotNull(reply);
    assertEquals("FOO", reply.getPayload());
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) QueueChannel(org.springframework.integration.channel.QueueChannel) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 8 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method noOutputChannelFallsBackToReturnAddress.

@Test
public void noOutputChannelFallsBackToReturnAddress() {
    QueueChannel channel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = this.createEndpoint();
    Message<?> message = MessageBuilder.withPayload("foo").setReplyChannel(channel).build();
    endpoint.handleMessage(message);
    Message<?> reply = channel.receive(0);
    assertNotNull(reply);
    assertEquals("FOO", reply.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 9 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method noReplyMessage.

@Test
public void noReplyMessage() {
    QueueChannel channel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestNullReplyBean(), "handle");
    endpoint.setOutputChannel(channel);
    Message<?> message = MessageBuilder.withPayload("foo").build();
    endpoint.handleMessage(message);
    assertNull(channel.receive(0));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 10 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method noReplyMessageWithRequiresReply.

@Test(expected = ReplyRequiredException.class)
public void noReplyMessageWithRequiresReply() {
    QueueChannel channel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestNullReplyBean(), "handle");
    endpoint.setRequiresReply(true);
    endpoint.setOutputChannel(channel);
    Message<?> message = MessageBuilder.withPayload("foo").build();
    endpoint.handleMessage(message);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) 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