use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessagePublisher method publish.
/**
* Publish an error message for the supplied throwable and context.
* The {@link #errorMessageStrategy} is used to build a {@link ErrorMessage}
* to publish.
* @param throwable the throwable. May be null.
* @param context the context for {@link ErrorMessage} properties.
*/
public void publish(Throwable throwable, AttributeAccessor context) {
populateChannel();
Throwable payload = determinePayload(throwable, context);
ErrorMessage errorMessage = this.errorMessageStrategy.buildErrorMessage(payload, context);
if (this.logger.isDebugEnabled() && payload instanceof MessagingException) {
MessagingException exception = (MessagingException) errorMessage.getPayload();
this.logger.debug("Sending ErrorMessage: failedMessage: " + exception.getFailedMessage(), exception);
}
this.messagingTemplate.send(errorMessage);
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method consumerSubscribedToErrorChannel.
@Test
public void consumerSubscribedToErrorChannel() throws InterruptedException {
TestApplicationContext context = TestUtils.createTestApplicationContext();
QueueChannel errorChannel = new QueueChannel();
context.registerChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, errorChannel);
final CountDownLatch latch = new CountDownLatch(1);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
latch.countDown();
return null;
}
};
PollingConsumer endpoint = new PollingConsumer(errorChannel, handler);
endpoint.setBeanFactory(mock(BeanFactory.class));
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals("handler should have received error message", 0, latch.getCount());
context.stop();
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class AggregatorIntegrationTests method testZeroGroupTimeoutExpressionScheduling.
@Test
public void testZeroGroupTimeoutExpressionScheduling() throws Exception {
try {
this.output.purge(null);
this.errors.purge(null);
GenericMessage<String> message = new GenericMessage<String>("foo");
this.output.send(message);
this.output.send(message);
this.output.send(message);
this.output.send(message);
this.output.send(message);
this.zeroGroupTimeoutExpressionAggregatorInput.send(new GenericMessage<Integer>(1, stubHeaders(1, 2, 1)));
ErrorMessage em = (ErrorMessage) this.errors.receive(10000);
assertNotNull(em);
assertThat(em.getPayload().getMessage().toLowerCase(), containsString("failed to send message to channel 'output' within timeout: 10"));
} finally {
this.output.purge(null);
this.errors.purge(null);
}
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class TcpConnectionSupport method sendExceptionToListener.
protected final void sendExceptionToListener(Exception e) {
if (!this.exceptionSent.getAndSet(true) && this.getListener() != null) {
Map<String, Object> headers = Collections.singletonMap(IpHeaders.CONNECTION_ID, (Object) this.getConnectionId());
ErrorMessage errorMessage = new ErrorMessage(e, headers);
this.getListener().onMessage(errorMessage);
}
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class WebFluxRequestExecutingMessageHandlerTests method testReactiveConnectErrorOneWay.
@Test
public void testReactiveConnectErrorOneWay() {
ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
throw new RuntimeException("Intentional connection error");
});
WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
String destinationUri = "http://www.springsource.org/spring-integration";
WebFluxRequestExecutingMessageHandler reactiveHandler = new WebFluxRequestExecutingMessageHandler(destinationUri, webClient);
reactiveHandler.setExpectReply(false);
QueueChannel errorChannel = new QueueChannel();
reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").setErrorChannel(errorChannel).build());
Message<?> errorMessage = errorChannel.receive(10000);
assertNotNull(errorMessage);
assertThat(errorMessage, instanceOf(ErrorMessage.class));
Throwable throwable = (Throwable) errorMessage.getPayload();
assertThat(throwable.getMessage(), containsString("Intentional connection error"));
}
Aggregations