I use Spring XML to define my Camel Context. Is it possible to get the same camelcontext object in Java at runtime? I need this object to add more data and send it to an existing route. I cannot do it in XML and need the object as I will be listening for errors and have to act when the event listener is triggered.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<camelContext id="ovcOutboundCamelContext"
errorHandlerRef="deadLetterErrorHandler"
xmlns="http://camel.apache.org/schema/spring"
useMDCLogging="true">
<route id="processAuctionMessageRoute">
<from uri="direct:processAuctionMessage"/>
<to uri="bean:CustomerService?method=processAuctionMessage"/>
<to uri="direct:splitMessage"/>
</route>
<route id="splitMessagesRoute">
<from uri="direct:splitMessage"/>
<split parallelProcessing="true" executorServiceRef="auctionsSplitThreadPoolProfile" id="splitId">
<simple>${body}</simple>
<to uri="bean:CustomerService?method=transformCompanyMessageForAuction"/>
<to uri="bean:CustomerService?method=processCompanyMessageForAuction"/>
</split>
<to uri="direct:end"/>
</route>
<route id="endProcessor">
<from uri="direct:end"/>
<log loggingLevel="INFO" message="End of route ${threadName}"/>
</route>
</camelContext>
I am trying to get this context with the already existing routes in Java, but it did not work. Please help.
public void test() throws Exception {
CamelContext context = new DefaultCamelContext();
context.start();
System.out.println("context:" + context.getRoutes().size());
context.getRoute("direct:gotoExistingProcess");
addRoutesToCamelContext(context);
System.out.println("context:" + context.getRoutes().size());
context.stop();
}