camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: Convert a Spring xml route string in a RouteDefinition
Date Mon, 27 Jan 2014 04:59:35 GMT
You might want to have a look at the following sample. It does have namespace defined for root

You can build this string as you like with more child routes.

                CamelContext context = new DefaultCamelContext();

                String xmlString = "<routes  xmlns=\"\"><route><from
uri='direct:c'/><to uri='mock:d'/></route></routes>";

                InputStream is = new ByteArrayInputStream(xmlString.getBytes());
                RoutesDefinition routes = context.loadRoutesDefinition(is);


                ProducerTemplate template = null;
                template = context.createProducerTemplate();
                template.sendBody("direct:c", "HelloC");

-----Original Message-----
From: giacomolm []
Sent: Friday, January 24, 2014 4:26 PM
Subject: Convert a Spring xml route string in a RouteDefinition

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
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s)
and may contain confidential and privileged information. If you are not the intended recipient(s),
please reply to the sender and destroy all copies of the original message. Any unauthorized
review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or
any action taken in reliance on the contents of this e-mail is strictly prohibited and may
be unlawful.

View raw message