Search in sources :

Example 1 with ReplyRequiredException

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

the class GroovyServiceActivatorTests method invalidInlineScript.

// INT-2399
@Test(expected = MessageHandlingException.class)
public void invalidInlineScript() throws Exception {
    Message<?> message = new ErrorMessage(new ReplyRequiredException(new GenericMessage<String>("test"), "reply required!"));
    try {
        this.invalidInlineScript.send(message);
        fail("MessageHandlingException expected!");
    } catch (Exception e) {
        Throwable cause = e.getCause();
        assertEquals(MissingPropertyException.class, cause.getClass());
        assertThat(cause.getMessage(), Matchers.containsString("No such property: ReplyRequiredException for class: script"));
        throw e;
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ReplyRequiredException(org.springframework.integration.handler.ReplyRequiredException) MissingPropertyException(groovy.lang.MissingPropertyException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) ReplyRequiredException(org.springframework.integration.handler.ReplyRequiredException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) MissingPropertyException(groovy.lang.MissingPropertyException) BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) Test(org.junit.Test)

Example 2 with ReplyRequiredException

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

the class ContentEnricherTests method replyChannelReplyTimingOut.

/**
 * In this test a {@link Target} message is passed into a {@link ContentEnricher}.
 * The Enricher passes the message to a "request-channel" that is backed by a
 * {@link QueueChannel}. The consumer of the "request-channel" takes a long
 * time to execute, longer actually than the specified "replyTimeout" set on
 * the {@link ContentEnricher}.
 *
 * Due to the occurring replyTimeout, a Null replyMessage is returned and because
 * "requiresReply" is set to "true" on the {@link ContentEnricher}, a
 * {@link ReplyRequiredException} is raised.
 */
@Test
public void replyChannelReplyTimingOut() throws Exception {
    final long requestTimeout = 500L;
    final long replyTimeout = 100L;
    final DirectChannel replyChannel = new DirectChannel();
    final QueueChannel requestChannel = new QueueChannel(1);
    final ContentEnricher enricher = new ContentEnricher();
    enricher.setRequestChannel(requestChannel);
    enricher.setReplyChannel(replyChannel);
    enricher.setOutputChannel(new NullChannel());
    enricher.setRequestTimeout(requestTimeout);
    enricher.setReplyTimeout(replyTimeout);
    final ExpressionFactoryBean expressionFactoryBean = new ExpressionFactoryBean("payload");
    expressionFactoryBean.setSingleton(false);
    expressionFactoryBean.afterPropertiesSet();
    final Map<String, Expression> expressions = new HashMap<String, Expression>();
    expressions.put("name", new LiteralExpression("cartman"));
    expressions.put("child.name", expressionFactoryBean.getObject());
    enricher.setPropertyExpressions(expressions);
    enricher.setRequiresReply(true);
    enricher.setBeanName("Enricher");
    enricher.setBeanFactory(mock(BeanFactory.class));
    enricher.afterPropertiesSet();
    final AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                fail(e.getMessage());
            }
            return new Target("child");
        }
    };
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    final PollingConsumer consumer = new PollingConsumer(requestChannel, handler);
    final TestErrorHandler errorHandler = new TestErrorHandler();
    consumer.setTrigger(new PeriodicTrigger(0));
    consumer.setErrorHandler(errorHandler);
    consumer.setTaskScheduler(taskScheduler);
    consumer.setBeanFactory(mock(BeanFactory.class));
    consumer.afterPropertiesSet();
    consumer.start();
    final Target target = new Target("replace me");
    Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
    try {
        enricher.handleMessage(requestMessage);
    } catch (ReplyRequiredException e) {
        assertEquals("No reply produced by handler 'Enricher', and its 'requiresReply' property is set to true.", e.getMessage());
        return;
    }
    fail("ReplyRequiredException expected.");
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) ReplyRequiredException(org.springframework.integration.handler.ReplyRequiredException) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) TestErrorHandler(org.springframework.integration.config.TestErrorHandler) LiteralExpression(org.springframework.expression.common.LiteralExpression) Matchers.containsString(org.hamcrest.Matchers.containsString) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) NullChannel(org.springframework.integration.channel.NullChannel) Test(org.junit.Test)

Example 3 with ReplyRequiredException

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

the class JpaOutboundGatewayParserTests method advised.

@Test
public void advised() throws Throwable {
    setUp("JpaOutboundGatewayParserTests.xml", getClass(), "advised");
    EventDrivenConsumer jpaOutboundGatewayEndpoint = context.getBean("advised", EventDrivenConsumer.class);
    MessageHandler jpaOutboundGateway = TestUtils.getPropertyValue(jpaOutboundGatewayEndpoint, "handler", MessageHandler.class);
    FooAdvice advice = context.getBean("jpaFooAdvice", FooAdvice.class);
    assertTrue(AopUtils.isAopProxy(jpaOutboundGateway));
    try {
        jpaOutboundGateway.handleMessage(new GenericMessage<String>("foo"));
        fail("expected ReplyRequiredException");
    } catch (MessagingException e) {
        assertTrue(e instanceof ReplyRequiredException);
    }
    Mockito.verify(advice).doInvoke(Mockito.any(ExecutionCallback.class), Mockito.any(Object.class), Mockito.any(Message.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ReplyRequiredException(org.springframework.integration.handler.ReplyRequiredException) MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ReplyRequiredException (org.springframework.integration.handler.ReplyRequiredException)3 Message (org.springframework.messaging.Message)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 MissingPropertyException (groovy.lang.MissingPropertyException)1 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)1 Expression (org.springframework.expression.Expression)1 LiteralExpression (org.springframework.expression.common.LiteralExpression)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 NullChannel (org.springframework.integration.channel.NullChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 ExpressionFactoryBean (org.springframework.integration.config.ExpressionFactoryBean)1 TestErrorHandler (org.springframework.integration.config.TestErrorHandler)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)1 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)1 MessageHandler (org.springframework.messaging.MessageHandler)1