Search in sources :

Example 31 with ServiceActivatingHandler

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

the class ServiceActivatorEndpointTests method returnAddressHeader.

@Test
public void returnAddressHeader() {
    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 32 with ServiceActivatingHandler

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

the class MessageProducerSupportTests method validateSuccessfulErrorFlowDoesNotThrowErrors.

@Test
public void validateSuccessfulErrorFlowDoesNotThrowErrors() {
    TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    DirectChannel outChannel = new DirectChannel();
    outChannel.subscribe(message -> {
        throw new RuntimeException("problems");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    SuccessfulErrorService errorService = new SuccessfulErrorService();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(errorService);
    handler.setBeanFactory(testApplicationContext);
    handler.afterPropertiesSet();
    errorChannel.subscribe(handler);
    MessageProducerSupport mps = new MessageProducerSupport() {
    };
    mps.setOutputChannel(outChannel);
    mps.setErrorChannel(errorChannel);
    mps.setBeanFactory(testApplicationContext);
    mps.afterPropertiesSet();
    mps.start();
    Message<?> message = new GenericMessage<String>("hello");
    mps.sendMessage(message);
    assertThat(errorService.lastMessage, instanceOf(ErrorMessage.class));
    ErrorMessage errorMessage = (ErrorMessage) errorService.lastMessage;
    assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
    MessageDeliveryException exception = (MessageDeliveryException) errorMessage.getPayload();
    assertEquals(message, exception.getFailedMessage());
    testApplicationContext.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 33 with ServiceActivatingHandler

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

the class CorrelationIdTests method testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler.

@Test
public void testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler() throws Exception {
    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(), "createMessage");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("456-XYZ", 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 34 with ServiceActivatingHandler

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

the class CorrelationIdTests method testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler.

@Test
public void testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() throws Exception {
    Message<?> message = new GenericMessage<String>("test");
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "createMessage");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("456-XYZ", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) 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 35 with ServiceActivatingHandler

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

the class CorrelationIdTests method testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable.

@Test
public void testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable() {
    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(new IntegrationMessageHeaderAccessor(message).getCorrelationId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
    assertTrue(new IntegrationMessageHeaderAccessor(message).getCorrelationId().equals(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)

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