I have this Camel Route and would like to test it.
from("jms:queue:importer.messageImport")
.routeId("Import")
.onException(Exception.class)
.maximumRedeliveries(0)
.handled(true)
.process(this.exceptionHandleProcessor)
.to("jms:queue:importer.error").id("error")
.end()
.transacted()
.process(convertDocument)
.to("file:"+StringHelper.after(importedDirectory,"/")+"?fileName=${id}.json");
from("jms:queue:importer.error")
.routeId("Error")
.errorHandler(noErrorHandler())
.transacted()
.log(LoggingLevel.ERROR, LOG, "Import Error")
....
I do this as follows:
AdviceWith.adviceWith(camelContext, "Import", routeBuilder -> {
routeBuilder.replaceFromWith("direct:to-import");
routeBuilder.weaveByToUri("jms:queue:importer.error")
.replace()
.to("mock:importError");
/*
Same Problem with this code.
routeBuilder.interceptSendToEndpoint("jms:queue:importer.error")
.skipSendToOriginalEndpoint()
.to("mock:importError");
*/
});
MockEndpoint mockImportError = getMockEndpoint("mock:importError");
mockImportError.expectedMessageCount(1);
// Here comes the exception
template.sendBody("direct:to-import", Files.readString(testFile.toPath()));
// ------------------------
mockImportError.assertIsSatisfied();
String bodyImportError = mockImportError.getExchanges()
.get(0)
.getMessage()
.getBody(String.class);
The only problem is that the OnException route and the processor are called but the endpoint “Error” does not get the message. An exception occurs with template.sendBody()
. How can I prevent this? I would like to have the message in the Error queue to read the body and can test.
Exception is:
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange
Caused by: org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only