Search in sources :

Example 11 with ServiceActivatingHandler

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

the class CorrelationIdTests method testCorrelationIdPassedIfAvailable.

@Test
public void testCorrelationIdPassedIfAvailable() {
    Object correlationId = "123-ABC";
    Message<String> message = MessageBuilder.withPayload("test").setCorrelationId(correlationId).build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "upperCase");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(correlationId, new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 12 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithGenericMessageMethod.

@Test
public /*
	 * No handler fallback methods; don't force RRE
	 */
void testRequestReplyExchangerWithGenericMessageMethod() {
    RequestReplyExchanger testBean = new RequestReplyExchanger() {

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

        @SuppressWarnings("unused")
        public String foo(Message<String> request) {
            return request.getPayload().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 13 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousGenericMessageMethod.

@Test
public /*
	 * No handler fallback methods; ambiguous message handler fallbacks; force RRE
	 */
void testRequestReplyExchangerWithAmbiguousGenericMessageMethod() {
    RequestReplyExchanger testBean = new RequestReplyExchanger() {

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

        @SuppressWarnings("unused")
        public String foo(Message<String> request) {
            return request.getPayload().toUpperCase();
        }

        @SuppressWarnings("unused")
        public String bar(Message<String> request) {
            return request.getPayload().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);
    assertNotEquals("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 14 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousMethod.

@Test
public /*
	 * One message handler fallback method (RRE); ambiguous handler fallbacks; force RRE
	 */
void testRequestReplyExchangerWithAmbiguousMethod() {
    RequestReplyExchanger testBean = new RequestReplyExchanger() {

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

        @SuppressWarnings("unused")
        public String foo(String request) {
            return request.toUpperCase();
        }

        @SuppressWarnings("unused")
        public String bar(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);
    assertNotEquals("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 15 with ServiceActivatingHandler

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

the class ServiceActivatorMethodResolutionTests method testRequestReplyExchanger.

@Test
public void testRequestReplyExchanger() {
    RequestReplyExchanger testBean = new RequestReplyExchanger() {

        @Override
        public Message<?> exchange(Message<?> request) {
            return request;
        }
    };
    final Message<?> test = new GenericMessage<Object>("foo");
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean) {

        @Override
        protected Object handleRequestMessage(Message<?> message) {
            Object o = super.handleRequestMessage(message);
            assertSame(test, o);
            return null;
        }
    };
    serviceActivator.handleMessage(test);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) 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