Search in sources :

Example 16 with AbstractReplyProducingMessageHandler

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

the class DirectChannelSubscriptionTests method exceptionThrownFromRegisteredEndpoint.

@Test(expected = MessagingException.class)
public void exceptionThrownFromRegisteredEndpoint() {
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            throw new RuntimeException("intentional test failure");
        }
    };
    handler.setOutputChannel(targetChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, handler);
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    try {
        this.sourceChannel.send(new GenericMessage<String>("foo"));
    } finally {
        context.stop();
    }
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Example 17 with AbstractReplyProducingMessageHandler

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

the class ContentEnricherTests method clonePayloadIgnored.

@Test
public void clonePayloadIgnored() {
    QueueChannel replyChannel = new QueueChannel();
    DirectChannel requestChannel = new DirectChannel();
    requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new Source("John", "Doe");
        }
    });
    ContentEnricher enricher = new ContentEnricher();
    enricher.setRequestChannel(requestChannel);
    enricher.setShouldClonePayload(true);
    SpelExpressionParser parser = new SpelExpressionParser();
    Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
    propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
    enricher.setPropertyExpressions(propertyExpressions);
    enricher.setBeanFactory(mock(BeanFactory.class));
    enricher.afterPropertiesSet();
    TargetUser target = new TargetUser();
    target.setName("replace me");
    Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
    enricher.handleMessage(requestMessage);
    Message<?> reply = replyChannel.receive(0);
    TargetUser result = (TargetUser) reply.getPayload();
    assertEquals("Doe, John", result.getName());
    assertSame(target, result);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Example 18 with AbstractReplyProducingMessageHandler

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

the class ContentEnricherTests method testLifeCycleMethodsWithRequestChannel.

@Test
public void testLifeCycleMethodsWithRequestChannel() {
    DirectChannel requestChannel = new DirectChannel();
    requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new Source("John", "Doe");
        }
    });
    ContentEnricher enricher = new ContentEnricher();
    enricher.setRequestChannel(requestChannel);
    enricher.setBeanFactory(mock(BeanFactory.class));
    enricher.afterPropertiesSet();
    enricher.start();
    assertTrue(enricher.isRunning());
    enricher.stop();
    assertFalse(enricher.isRunning());
    enricher.start();
    assertTrue(enricher.isRunning());
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Example 19 with AbstractReplyProducingMessageHandler

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

the class ContentEnricherTests method nestedProperty.

@Test
public void nestedProperty() {
    QueueChannel replyChannel = new QueueChannel();
    DirectChannel requestChannel = new DirectChannel();
    requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new Source("John", "Doe");
        }
    });
    ContentEnricher enricher = new ContentEnricher();
    enricher.setRequestChannel(requestChannel);
    SpelExpressionParser parser = new SpelExpressionParser();
    Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
    propertyExpressions.put("child.name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
    enricher.setPropertyExpressions(propertyExpressions);
    enricher.setBeanFactory(mock(BeanFactory.class));
    enricher.afterPropertiesSet();
    Target target = new Target("test");
    Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
    enricher.handleMessage(requestMessage);
    Message<?> reply = replyChannel.receive(0);
    Target result = (Target) reply.getPayload();
    assertEquals("test", result.getName());
    assertEquals("Doe, John", result.getChild().getName());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Example 20 with AbstractReplyProducingMessageHandler

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

the class ContentEnricherTests method clonePayloadWithFailure.

@Test
public void clonePayloadWithFailure() {
    QueueChannel replyChannel = new QueueChannel();
    DirectChannel requestChannel = new DirectChannel();
    requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new Source("John", "Doe");
        }
    });
    ContentEnricher enricher = new ContentEnricher();
    enricher.setRequestChannel(requestChannel);
    enricher.setShouldClonePayload(true);
    SpelExpressionParser parser = new SpelExpressionParser();
    Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
    propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
    enricher.setPropertyExpressions(propertyExpressions);
    enricher.setBeanFactory(mock(BeanFactory.class));
    enricher.afterPropertiesSet();
    UncloneableTargetUser target = new UncloneableTargetUser();
    target.setName("replace me");
    Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
    try {
        enricher.handleMessage(requestMessage);
    } catch (MessageHandlingException e) {
        assertThat(e.getMessage(), containsString("Failed to clone payload object"));
        return;
    }
    fail("Expected a MessageHandlingException to be thrown.");
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) MessageHandlingException(org.springframework.messaging.MessageHandlingException) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Aggregations

AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)52 Test (org.junit.Test)46 BeanFactory (org.springframework.beans.factory.BeanFactory)37 QueueChannel (org.springframework.integration.channel.QueueChannel)29 Message (org.springframework.messaging.Message)28 DirectChannel (org.springframework.integration.channel.DirectChannel)23 GenericMessage (org.springframework.messaging.support.GenericMessage)20 Matchers.containsString (org.hamcrest.Matchers.containsString)19 ErrorMessage (org.springframework.messaging.support.ErrorMessage)18 ArrayList (java.util.ArrayList)14 AdviceMessage (org.springframework.integration.message.AdviceMessage)14 Advice (org.aopalliance.aop.Advice)13 HashMap (java.util.HashMap)12 MessageHandlingException (org.springframework.messaging.MessageHandlingException)12 Expression (org.springframework.expression.Expression)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 MessageHandlingExpressionEvaluatingAdviceException (org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice.MessageHandlingExpressionEvaluatingAdviceException)9 MessagingException (org.springframework.messaging.MessagingException)9