Search in sources :

Example 91 with MessagingException

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

the class DatatypeChannelTests method subclassOfAcceptedType.

@Test
public void subclassOfAcceptedType() {
    MessageChannel channel = createChannel(RuntimeException.class);
    assertTrue(channel.send(new ErrorMessage(new MessagingException("test"))));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) MessagingException(org.springframework.messaging.MessagingException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Test(org.junit.Test)

Example 92 with MessagingException

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

the class DispatchingChannelErrorHandlingTests method handlerThrowsExceptionExecutorChannel.

@Test
public void handlerThrowsExceptionExecutorChannel() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
    context.refresh();
    DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
    TaskExecutor executor = new SimpleAsyncTaskExecutor();
    ExecutorChannel channel = new ExecutorChannel(executor);
    channel.setBeanFactory(context);
    channel.afterPropertiesSet();
    ResultHandler resultHandler = new ResultHandler();
    defaultErrorChannel.subscribe(resultHandler);
    channel.subscribe(message -> {
        throw new MessagingException(message, new UnsupportedOperationException("intentional test failure"));
    });
    Message<?> message = MessageBuilder.withPayload("test").build();
    channel.send(message);
    this.waitForLatch(10000);
    Message<?> errorMessage = resultHandler.lastMessage;
    assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
    MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
    assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
    assertSame(message, exceptionPayload.getFailedMessage());
    assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MessagingException(org.springframework.messaging.MessagingException) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Test(org.junit.Test)

Example 93 with MessagingException

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

the class DispatchingChannelErrorHandlingTests method handlerThrowsExceptionPublishSubscribeWithExecutor.

@Test
public void handlerThrowsExceptionPublishSubscribeWithExecutor() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
    context.refresh();
    DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
    TaskExecutor executor = new SimpleAsyncTaskExecutor();
    PublishSubscribeChannel channel = new PublishSubscribeChannel(executor);
    channel.setBeanFactory(context);
    channel.afterPropertiesSet();
    ResultHandler resultHandler = new ResultHandler();
    defaultErrorChannel.subscribe(resultHandler);
    channel.subscribe(message -> {
        throw new MessagingException(message, new UnsupportedOperationException("intentional test failure"));
    });
    Message<?> message = MessageBuilder.withPayload("test").build();
    channel.send(message);
    this.waitForLatch(10000);
    Message<?> errorMessage = resultHandler.lastMessage;
    assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
    MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
    assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
    assertSame(message, exceptionPayload.getFailedMessage());
    assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MessagingException(org.springframework.messaging.MessagingException) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Test(org.junit.Test)

Example 94 with MessagingException

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

the class FeedEntryMessageSource method getFeed.

private SyndFeed getFeed() {
    try {
        synchronized (this.feedMonitor) {
            Reader reader = this.feedUrl != null ? new XmlReader(this.feedUrl) : new XmlReader(this.feedResource.getInputStream());
            SyndFeed feed = this.syndFeedInput.build(reader);
            if (logger.isDebugEnabled()) {
                logger.debug("Retrieved feed for [" + this + "]");
            }
            if (feed == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("No feeds updated for [" + this + "], returning null");
                }
            }
            return feed;
        }
    } catch (Exception e) {
        throw new MessagingException("Failed to retrieve feed for '" + this + "'", e);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MessagingException(org.springframework.messaging.MessagingException) Reader(java.io.Reader) XmlReader(com.rometools.rome.io.XmlReader) XmlReader(com.rometools.rome.io.XmlReader) MessagingException(org.springframework.messaging.MessagingException)

Example 95 with MessagingException

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

the class RemoteFileTemplate method execute.

@SuppressWarnings("rawtypes")
@Override
public <T> T execute(SessionCallback<F, T> callback) {
    Session<F> session = null;
    boolean invokeScope = false;
    if (this.activeTemplateCallbacks.get() > 0) {
        session = this.contextSessions.get();
    }
    try {
        if (session == null) {
            session = this.sessionFactory.getSession();
        } else {
            invokeScope = true;
        }
        return callback.doInSession(session);
    } catch (Exception e) {
        if (session instanceof CachingSessionFactory<?>.CachedSession) {
            ((CachingSessionFactory.CachedSession) session).dirty();
        }
        if (e instanceof MessagingException) {
            throw (MessagingException) e;
        }
        throw new MessagingException("Failed to execute on session", e);
    } finally {
        if (!invokeScope) {
            try {
                session.close();
            } catch (Exception ignored) {
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("failed to close Session", ignored);
                }
            }
        }
    }
}
Also used : CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) FileNotFoundException(java.io.FileNotFoundException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)143 Test (org.junit.Test)60 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 MessageHandlingException (org.springframework.messaging.MessageHandlingException)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8