Search in sources :

Example 26 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method correlationIdSetByHandlerTakesPrecedence.

@Test
public void correlationIdSetByHandlerTakesPrecedence() {
    QueueChannel replyChannel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return MessageBuilder.fromMessage(message).setCorrelationId("ABC-123").build();
        }
    }, "handle");
    Message<String> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    endpoint.handleMessage(message);
    Message<?> reply = replyChannel.receive(500);
    Object correlationId = new IntegrationMessageHeaderAccessor(reply).getCorrelationId();
    assertFalse(message.getHeaders().getId().equals(correlationId));
    assertEquals("ABC-123", correlationId);
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 27 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method correlationIdNotSetIfMessageIsReturnedUnaltered.

@Test
public void correlationIdNotSetIfMessageIsReturnedUnaltered() {
    QueueChannel replyChannel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return message;
        }
    }, "handle");
    Message<String> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    endpoint.handleMessage(message);
    Message<?> reply = replyChannel.receive(500);
    assertNull(new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 28 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method outputChannelTakesPrecedence.

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

Example 29 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method outputChannel.

@Test
public void outputChannel() {
    QueueChannel channel = new QueueChannel(1);
    ServiceActivatingHandler endpoint = this.createEndpoint();
    endpoint.setOutputChannel(channel);
    Message<?> message = MessageBuilder.withPayload("foo").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 30 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method testBeanFactoryPopulation.

@Test
public void testBeanFactoryPopulation() {
    ServiceActivatingHandler endpoint = this.createEndpoint();
    BeanFactory mock = mock(BeanFactory.class);
    endpoint.setBeanFactory(mock);
    endpoint.afterPropertiesSet();
    Object beanFactory = TestUtils.getPropertyValue(endpoint, "processor.beanFactory");
    assertNotNull(beanFactory);
    assertSame(mock, beanFactory);
}
Also used : 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