camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giacomolm <giacomo.lamon...@tirasa.net>
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'>
</route>"

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
ByteArrayInputStream(xmlString.getBytes()))));
doc.getDocumentElement().normalize();
Node routeEl = doc.getElementsByTagName("route").item(0);

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

//camel context
camelContext.addRouteDefiniton(answer);
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
unmarshalling.

[1] file http://camel.apache.org/loading-routes-from-xml-files.html



--
View this message in context: http://camel.465427.n5.nabble.com/Convert-a-Spring-xml-route-string-in-a-RouteDefinition-tp5746443.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message