use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverNoLoadBalancing.
@Test
public void noFailoverNoLoadBalancing() {
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);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
verify(handlerA, times(2)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class IdempotentReceiverTests method testIdempotentReceiverInterceptor.
@Test
public void testIdempotentReceiverInterceptor() {
ConcurrentMetadataStore store = new SimpleMetadataStore();
ExpressionEvaluatingMessageProcessor<String> idempotentKeyStrategy = new ExpressionEvaluatingMessageProcessor<>(new SpelExpressionParser().parseExpression("payload"));
BeanFactory beanFactory = Mockito.mock(BeanFactory.class);
idempotentKeyStrategy.setBeanFactory(beanFactory);
IdempotentReceiverInterceptor idempotentReceiverInterceptor = new IdempotentReceiverInterceptor(new MetadataStoreSelector(idempotentKeyStrategy, store));
idempotentReceiverInterceptor.setThrowExceptionOnRejection(true);
AtomicReference<Message<?>> handled = new AtomicReference<>();
MessageHandler idempotentReceiver = handled::set;
ProxyFactory proxyFactory = new ProxyFactory(idempotentReceiver);
proxyFactory.addAdvice(idempotentReceiverInterceptor);
idempotentReceiver = (MessageHandler) proxyFactory.getProxy();
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
assertEquals(1, TestUtils.getPropertyValue(store, "metadata", Map.class).size());
assertNotNull(store.get("foo"));
try {
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
fail("MessageRejectedException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageRejectedException.class));
}
idempotentReceiverInterceptor.setThrowExceptionOnRejection(false);
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
assertTrue(handled.get().getHeaders().get(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, Boolean.class));
assertEquals(1, TestUtils.getPropertyValue(store, "metadata", Map.class).size());
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method testHierarchicalMapping.
@Test
public void testHierarchicalMapping() {
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
MessageHandlingException error = new MessageRejectedException(new GenericMessage<Object>("foo"), "failed", rootCause);
ErrorMessage message = new ErrorMessage(error);
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
router.setBeanFactory(beanFactory);
router.setApplicationContext(TestUtils.createTestApplicationContext());
router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(messageHandlingExceptionChannel.receive(1000));
assertNull(defaultChannel.receive(0));
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class IdempotentReceiverIntegrationTests method testIdempotentReceiver.
@Test
public void testIdempotentReceiver() {
this.idempotentReceiverInterceptor.setThrowExceptionOnRejection(true);
TestUtils.getPropertyValue(this.store, "metadata", Map.class).clear();
Message<String> message = new GenericMessage<>("foo");
this.input.send(message);
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(1, this.adviceCalled.get());
assertEquals(1, TestUtils.getPropertyValue(this.store, "metadata", Map.class).size());
String foo = this.store.get("foo");
assertEquals("FOO", foo);
try {
this.input.send(message);
fail("MessageRejectedException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageRejectedException.class));
}
this.idempotentReceiverInterceptor.setThrowExceptionOnRejection(false);
this.input.send(message);
receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(2, this.adviceCalled.get());
assertTrue(receive.getHeaders().get(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, Boolean.class));
assertEquals(1, TestUtils.getPropertyValue(store, "metadata", Map.class).size());
assertTrue(this.txSupplied.get());
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class XmlPayloadValidatingFilterParserTests method testInvalidMessageWithThrowException.
@Test
public void testInvalidMessageWithThrowException() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<greeting ping=\"pong\"><other/></greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
MessageChannel inputChannel = ac.getBean("inputChannelB", MessageChannel.class);
try {
inputChannel.send(docMessage);
fail("MessageRejectedException expected");
} catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessageRejectedException.class));
Throwable cause = e.getCause();
assertThat(cause, Matchers.instanceOf(AggregatedXmlMessageValidationException.class));
assertThat(cause.getMessage(), Matchers.containsString("Element 'greeting' is a simple type, so it must have no element information item [children]."));
assertThat(cause.getMessage(), Matchers.containsString("Element 'greeting' is a simple type, so it cannot have attributes,"));
}
}
Aggregations