Purpose

The route module allow you to transform and route your messages. For more informations see and read the Enterprise Integration Pattern In order to use it, generate the skeleton with the Osgiliath route archetype, then, create a simple route:
1
2
3
4
5
6
7
8
9
10
11
12
13
public class HelloRoute extends RouteBuilder {
private DataFormat helloObjectJSonFormat = new JacksonDataFormat(
			HelloObject.class); //sample transformation of Json object
JAXBContext ctx = JAXBContext
				.newInstance(new Class[] { HelloObject.class });
		DataFormat jaxBDataFormat = new JaxbDataFormat(ctx);//Xml transformation of an object

from("")
				.filter(header("webSocketMsgType").isNotEqualTo("heartBeat"))
.unmarshal(helloObjectJSonFormat)
				.marshal(jaxBDataFormat)
				.to("properties:/hello")
}
The URL/entrypoints in bracket are from the cfg file of the feature module while executing on runtime and from the src/test/resources/cfg one when unit testing. Then, you’ve to reference this route on the camelContext section of the blueprint.xml file and in the src/test/resources/spring (for testing).
1
2
3
4
5
6
7
8
9
10
11
<bean id="properties"
		class="org.apache.camel.component.properties.PropertiesComponent">
		<property name="location" value="blueprint:camelRoutes" />
	</bean>
<camelContext id="camelCtx"
		xmlns="http://camel.apache.org/schema/blueprint">
		<contextScan />
		<jmxAgent id="agent" disabled="true" />
		<routeBuilder ref="helloRoute"></routeBuilder>
	</camelContext>
<bean id="helloRoute" class="net.osgiliath.hello.routes.HelloRoute"/>
You can also use @ContextName camel-cdi annotation and reference component in a configuration class For more informations, check the hello example on github

Comments