Camel XML routes specified outside your deployed service

We and our customers wanted to specify routes in XML but outside a deployed service. The benefits is that you can update your routes without any redeploys. Just refresh your service and you are done! The main trick is to create a camel-context.xml where you import another external beans resource file. Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:osgi="http://camel.apache.org/schema/osgi"
	xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
	xmlns:ctx="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans 	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
	http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
	http://www.springframework.org/schema/osgi-compendium 	http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
	http://www.springframework.org/schema/context 		http://www.springframework.org/schema/context/spring-context.xsd">

	<import resource="file:/usr/local/xph/conf/mover.xml"/>

</beans>

As you can se, the only thing we do is to import an external file, in our case mover.xml

This is an working example of mover.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:osgi="http://camel.apache.org/schema/osgi"
	xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
	xmlns:ctx="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
	http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
	http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="OuboundTest">
	<from uri="sftp://testuser@hostname:/jail/outbound?privateKeyFile=/home/testuser/.ssh/id_rsa_passw&amp;privateKeyFilePassphrase=secretPassword&amp;stepwise=false&amp;delay=20000&amp;delete=true"/>
	<log loggingLevel="INFO" logName="mover" message="About to move ${file:onlyname}"/>
	<to uri="file:///usr/local/outbound.unverified/testuser?readLock=changed&amp;delete=true&amp;moveFailed=/usr/local/testuser/failed/failedToMoveToOutboundWorkdir.${file:onlyname}"/>
	<!-- General exception-->
	<onException>
		<exception>java.lang.Exception</exception>
		<handled>
			<constant>true</constant>
		</handled>
		<log loggingLevel="ERROR" logName="mover" message="General exception dealing with testuser file ${file:onlyname} , exeption ${exception} dumping file to ./error ,will exit...."/>
		<to uri="file:./error"/>
	</onException>
</route>
</osgi:camelContext>
</beans>

Ok, now what? Well, now you can use all the components given to you in camel without any deployment. Get files from SFTP, upload files, transform XML, Schema validate, log and much more. You will still have to load all features if you are using ServiceMix thou…..