Search in sources :

Example 66 with Message

use of org.springframework.messaging.Message 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 67 with Message

use of org.springframework.messaging.Message 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 68 with Message

use of org.springframework.messaging.Message 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)

Example 69 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class AsyncMessagingTemplateTests method asyncSendAndReceiveWithDefaultChannel.

@Test
public void asyncSendAndReceiveWithDefaultChannel() throws Exception {
    DirectChannel channel = new DirectChannel();
    channel.subscribe(new EchoHandler(200));
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    long start = System.currentTimeMillis();
    Future<Message<?>> result = template.asyncSendAndReceive(MessageBuilder.withPayload("test").build());
    assertNotNull(result.get());
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 70 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncCompletableNoAsyncMessage.

@Test
public void testAsyncCompletableNoAsyncMessage() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("completableNoAsync", TestService.class);
    CompletableFuture<Message<?>> result = service.completableReturnsMessage("flowCompletableM");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("flowCompletableM", reply.getPayload());
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

Message (org.springframework.messaging.Message)597 Test (org.junit.Test)423 GenericMessage (org.springframework.messaging.support.GenericMessage)272 QueueChannel (org.springframework.integration.channel.QueueChannel)189 MessageChannel (org.springframework.messaging.MessageChannel)128 ArrayList (java.util.ArrayList)113 BeanFactory (org.springframework.beans.factory.BeanFactory)85 CountDownLatch (java.util.concurrent.CountDownLatch)80 DirectChannel (org.springframework.integration.channel.DirectChannel)69 AtomicReference (java.util.concurrent.atomic.AtomicReference)68 Test (org.junit.jupiter.api.Test)65 MessageHandler (org.springframework.messaging.MessageHandler)58 List (java.util.List)56 PollableChannel (org.springframework.messaging.PollableChannel)56 ErrorMessage (org.springframework.messaging.support.ErrorMessage)52 Matchers.containsString (org.hamcrest.Matchers.containsString)50 MessagingException (org.springframework.messaging.MessagingException)50 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)43 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)41 Assert.assertEquals (org.junit.Assert.assertEquals)40