camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giacomolm <>
Subject Convert a Spring xml route string in a RouteDefinition
Date Fri, 24 Jan 2014 10:56:05 GMT
Hi all,

I saw that camel can load route from xml [1]: very useful functionality. Now
i'm trying to define a route starting only from a raw string consisting of a
single route. In example, suppose we have a string (compliant to Spring xml)
like this:

"<route id='id1'>
   <from uri='entrypoint'/>
   <to uri='exitpoint'>

In other words, my goal is to obtain a RouteDefinition Object starting from
this xml string. So, i'm trying to replicate the same behaviour defined
inside the loadRouteDefinitions method of DefaultCamelContext class. The
process is something like this:

String xmlString= ... //the string above

//Definition of route Node Element
Document doc = dBuilder.parse((new InputSource(new
Node routeEl = doc.getElementsByTagName("route").item(0);

//unmarshalling process
JAXBContext jaxbContext =
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement  obj = unmarshaller.unmarshal(routeEl, RouteDefinition.class);
RouteDefinition answer = obj.getValue();

//camel context
camelContext.start() // or camelContext can already been started

when camel (re)load the context with this new route definition, i receive a
NoSuchElementException. More specifically, after the unmarshiling process i
receive a route like this: [Route(id1)[[]->[]]. It seems that the route
content is empty. When i add the route to camel context, i receive the
NoSuchElementException discussed above.

In my opinion, there is something wrong in the unmarshalling process: JAXB
only recognize the root element (in this case the route element), while the
child element are not included in the result. Maybe the xml string doesn't
include information like namespace, and JAXB cannot proceed with a right

[1] file

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message