Search in sources :

Example 1 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class UnicastingDispatcherTests method withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel.

@SuppressWarnings("unchecked")
@Test
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
    SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
    MessageHandler errorHandler = message -> {
        MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
        assertTrue(message.getPayload() instanceof MessageDeliveryException);
        replyChannel.send(new GenericMessage<String>("reply"));
    };
    errorChannel.subscribe(errorHandler);
    RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
    Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
    assertEquals("reply", reply.getPayload());
    context.close();
}
Also used : MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) MessageHandler(org.springframework.messaging.MessageHandler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Assert.assertTrue(org.junit.Assert.assertTrue) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) Assert.assertEquals(org.junit.Assert.assertEquals) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHandler(org.springframework.messaging.MessageHandler) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 2 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger 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 3 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger 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 4 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger 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 5 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger 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

RequestReplyExchanger (org.springframework.integration.gateway.RequestReplyExchanger)27 Test (org.junit.Test)24 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)21 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)18 GenericMessage (org.springframework.messaging.support.GenericMessage)17 Destination (javax.jms.Destination)11 TextMessage (javax.jms.TextMessage)11 Message (javax.jms.Message)10 JmsTemplate (org.springframework.jms.core.JmsTemplate)10 MessageCreator (org.springframework.jms.core.MessageCreator)10 CachingConnectionFactory (org.springframework.jms.connection.CachingConnectionFactory)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ConnectionFactory (javax.jms.ConnectionFactory)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)5 Message (org.springframework.messaging.Message)5 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)5 Date (java.util.Date)4 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4