camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Thullner" <rthull...@gmx.at>
Subject AW: XPath splitter again
Date Fri, 28 Dec 2007 15:43:26 GMT
Thank you for you explanation. 

I got into some other troubles now. After my Xpath split I would like to
route the different messages to different endpoints. I thought this should
not be a big deal, but it does not work as I expect. 

My route is now like that:

XPathBuilder xPathBuilder=new XPathBuilder("trainSchedule/stops/station");
from("activemq:queue:camel.train.plan.queue")
.splitter(xPathBuilder)
.convertBodyTo(String.class)
.to("activemq:queue:camel.train.plan.queue.router");
            	
from("activemq:queue:camel.train.plan.queue.router").process(new Processor
() {
	public void process(Exchange exchange) {
      	Message in = exchange.getIn();
            String text = (String)in.getBody();
		// city is the attribute, used for routing
	      String city;
		
		...
		// find out city attribute of message content
		...			

            //destinationCity is a variable defined outside the route, so it
can be used outside, too		
            destinationCity = city;
      }
}).to("activemq:queue:camel.train.plan.queue." + destinationCity);

I would expect Camel now to route the splitted message all to different
endpoints, according to the city attributes of each
message. But no routing at all happens. When I look at the ActiveMQ web
console I see that a "camel.train.plan.queue." gets
created, but this is not what I want. Is it not allowed to use string
concatenation in the to-field of a route?

I made some workaround, where I set some header properties of the message
and then route using this attribute, but this is not
a good solution for me, because as new values get added I also have to add
new statements to my router.

Is there some solution for my problem?
Robert
 

-----Urspr√ľngliche Nachricht-----
Von: Roman Kalukiewicz [mailto:roman.kalukiewicz@gmail.com] 
Gesendet: Freitag, 28. Dezember 2007 14:49
An: camel-user@activemq.apache.org
Betreff: Re: XPath splitter again

> But I am still a little confused as I call the XML toString() method 
> to set the text of the TextMessage and I always send TextMessages. 
> Does the TextMessage get converted somewhere into an ObjectMessage?

Your TextMessage is only a way of camel endpoint invocation. Just after
received it is converted into camel Message object that contains String
payload. Then this payload is (behind the scene) converted to XML at
splitter (because if you want to use XPath you have to evaluate it on XML
object like DOM Node or SAX InputSource).
This way just after splitter you had 'DeferredElementNSImpl' instead of
String. That is good as if you would like to do something else with this
'splitted XML' it is already parsed as XML - you don't have to constantly
parse a String and then render it into String.

Hope it helps with your confusion ;)

Roman


Mime
View raw message