use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.
the class PollerSpec method errorChannel.
/**
* Specify a {@link MessageChannel} to use for sending error message in case
* of polling failures.
* @param errorChannel the {@link MessageChannel} to use.
* @return the spec.
* @see MessagePublishingErrorHandler
*/
public PollerSpec errorChannel(MessageChannel errorChannel) {
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setDefaultErrorChannel(errorChannel);
this.componentsToRegister.put(errorHandler, null);
return errorHandler(errorHandler);
}
use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.
the class RedisQueueInboundGateway method onInit.
@Override
protected void onInit() throws Exception {
super.onInit();
if (!this.extractPayload) {
Assert.notNull(this.serializer, "'serializer' has to be provided where 'extractPayload == false'.");
}
if (this.taskExecutor == null) {
String beanName = this.getComponentName();
this.taskExecutor = new SimpleAsyncTaskExecutor((beanName == null ? "" : beanName + "-") + this.getComponentType());
}
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
errorHandler.setDefaultErrorChannel(getErrorChannel());
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
}
}
use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.
the class AbstractPollingEndpoint method onInit.
@Override
protected void onInit() {
synchronized (this.initializationMonitor) {
if (this.initialized) {
return;
}
Assert.notNull(this.trigger, "Trigger is required");
if (this.taskExecutor != null) {
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
if (this.errorHandler == null) {
Assert.notNull(this.getBeanFactory(), "BeanFactory is required");
this.errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
this.errorHandlerIsDefault = true;
}
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, this.errorHandler);
}
}
if (this.transactionSynchronizationFactory == null && this.adviceChain != null) {
if (this.adviceChain.stream().anyMatch(TransactionInterceptor.class::isInstance)) {
this.transactionSynchronizationFactory = new PassThroughTransactionSynchronizationFactory();
}
}
this.initialized = true;
}
try {
super.onInit();
} catch (Exception e) {
throw new BeanInitializationException("Cannot initialize: " + this, e);
}
}
use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.
the class PollerSpec method errorChannel.
/**
* Specify a bean name for the {@link MessageChannel} to use for sending error message in case
* of polling failures.
* @param errorChannelName the bean name for {@link MessageChannel} to use.
* @return the spec.
* @see MessagePublishingErrorHandler
*/
public PollerSpec errorChannel(String errorChannelName) {
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setDefaultErrorChannelName(errorChannelName);
this.componentsToRegister.put(errorHandler, null);
return errorHandler(errorHandler);
}
use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.
the class DelayHandlerTests method errorChannelHeaderAndHandlerThrowsExceptionWithDelay.
@Test
public void errorChannelHeaderAndHandlerThrowsExceptionWithDelay() throws Exception {
DirectChannel errorChannel = new DirectChannel();
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setDefaultErrorChannel(errorChannel);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
errorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").setErrorChannel(errorChannel).build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
Aggregations