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"))));
}
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);
}
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);
}
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);
}
}
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);
}
}
}
}
}
Aggregations