List of usage examples for org.springframework.messaging MessageHandlingException getCause
public synchronized Throwable getCause()
From source file:biz.c24.io.spring.integration.config.ValidatingSelectorTests.java
@Test public void testThrowingInvalid() { Employee employee = new Employee(); employee.setSalutation("Mr"); // Invalid as first char not capitalised employee.setFirstName("andy"); employee.setLastName("Acheson"); // Invalid as no job title //employee.setJobTitle("Software Developer"); try {//from w w w .j a va 2s .co m template.convertAndSend(exceptionThrowingInputChannel, employee); fail("Selector failed to throw exception on invalid message"); } catch (MessageHandlingException ex) { // Expected behaviour assertThat(ex.getCause(), is(C24AggregatedMessageValidationException.class)); C24AggregatedMessageValidationException vEx = (C24AggregatedMessageValidationException) ex.getCause(); ListIterator<ValidationEvent> failures = vEx.getFailEvents(); int failureCount = 0; while (failures.hasNext()) { failureCount++; failures.next(); } assertThat(failureCount, is(2)); } // Make sure there are no other messages floating around assertThat(validChannel.receive(1), is(nullValue())); assertThat(invalidChannel.receive(1), is(nullValue())); }
From source file:it.pcan.test.integration.amqp.ErrorHandler.java
@ServiceActivator public Message handleException(Message msg) { System.out.println("Exception thrown: " + msg); MessageHandlingException payload = (MessageHandlingException) msg.getPayload(); MessageHeaders headers = payload.getFailedMessage().getHeaders(); HashMap<String, Object> newHeaders = new HashMap<>(headers); newHeaders.putAll(msg.getHeaders()); Throwable cause = payload.getCause(); RuntimeException ex = (cause instanceof RuntimeException) ? (RuntimeException) cause : new RuntimeException(cause); Message m = new GenericMessage(new RuntimeExceptionHolder(ex), newHeaders); return m;//from w w w . ja va2 s .co m }