use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class XmlValidatingMessageSelector method accept.
@Override
public boolean accept(Message<?> message) {
SAXParseException[] validationExceptions = null;
try {
validationExceptions = this.xmlValidator.validate(this.converter.convertToSource(message.getPayload()));
} catch (Exception e) {
throw new MessageHandlingException(message, e);
}
boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions);
if (!validationSuccess) {
if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors", new AggregatedXmlMessageValidationException(Arrays.<Throwable>asList(validationExceptions)));
}
this.logger.debug("Message was rejected due to XML Validation errors");
}
return validationSuccess;
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MessagingAnnotationsWithBeanAnnotationTests method testMessagingAnnotationsFlow.
@Test
public void testMessagingAnnotationsFlow() {
Stream.of(this.sourcePollingChannelAdapters).forEach(a -> a.start());
// this.sourcePollingChannelAdapter.start();
for (int i = 0; i < 10; i++) {
Message<?> receive = this.discardChannel.receive(10000);
assertNotNull(receive);
assertTrue(((Integer) receive.getPayload()) % 2 == 0);
receive = this.counterErrorChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class));
MessageRejectedException exception = (MessageRejectedException) receive.getPayload();
assertThat(exception.getMessage(), containsString("MessageFilter " + "'messagingAnnotationsWithBeanAnnotationTests.ContextConfiguration.filter.filter.handler'" + " rejected Message"));
}
for (Message<?> message : collector) {
assertFalse(((Integer) message.getPayload()) % 2 == 0);
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
String messageHistoryString = messageHistory.toString();
assertThat(messageHistoryString, Matchers.containsString("routerChannel"));
assertThat(messageHistoryString, Matchers.containsString("filterChannel"));
assertThat(messageHistoryString, Matchers.containsString("aggregatorChannel"));
assertThat(messageHistoryString, Matchers.containsString("splitterChannel"));
assertThat(messageHistoryString, Matchers.containsString("serviceChannel"));
assertThat(messageHistoryString, Matchers.not(Matchers.containsString("discardChannel")));
}
assertNull(this.skippedServiceActivator);
assertNull(this.skippedMessageHandler);
assertNull(this.skippedChannel);
assertNull(this.skippedChannel2);
assertNull(this.skippedMessageSource);
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverNoLoadBalancingConcurrent.
@Test
public void noFailoverNoLoadBalancingConcurrent() throws Exception {
final DirectChannel channel = (DirectChannel) ac.getBean("noLoadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
boolean sent = false;
try {
sent = channel.send(message);
} catch (Exception e2) {
exceptionRegistry.add(e2);
}
if (!sent) {
failed.set(true);
}
allDone.countDown();
};
for (int i = 0; i < TOTAL_EXECUTIONS; i++) {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class));
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method failoverNoLoadBalancingConcurrent.
@Test
public void failoverNoLoadBalancingConcurrent() throws Exception {
final DirectChannel channel = (DirectChannel) ac.getBean("noLoadBalancerFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
dispatcher.addHandler(handlerC);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
final Message<?> message = this.message;
final AtomicBoolean failed = new AtomicBoolean(false);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
boolean sent = false;
try {
sent = channel.send(message);
} catch (Exception e2) {
exceptionRegistry.add(e2);
}
if (!sent) {
failed.set(true);
}
allDone.countDown();
};
for (int i = 0; i < TOTAL_EXECUTIONS; i++) {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertFalse("not all messages were accepted", failed.get());
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerC, never()).handleMessage(message);
verify(exceptionRegistry, never()).add(any(Exception.class));
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverLoadBalancingConcurrent.
@Test
public void noFailoverLoadBalancingConcurrent() throws Exception {
final DirectChannel channel = (DirectChannel) ac.getBean("loadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
dispatcher.addHandler(handlerC);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
final Message<?> message = this.message;
final AtomicBoolean failed = new AtomicBoolean(false);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
boolean sent = false;
try {
sent = channel.send(message);
} catch (Exception e2) {
exceptionRegistry.add(e2);
}
if (!sent) {
failed.set(true);
}
allDone.countDown();
};
for (int i = 0; i < TOTAL_EXECUTIONS; i++) {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
verify(handlerA, times(14)).handleMessage(message);
verify(handlerB, times(13)).handleMessage(message);
verify(handlerC, times(13)).handleMessage(message);
verify(exceptionRegistry, times(14)).add(any(Exception.class));
}
Aggregations