BTW thanks for the great replies Roman! :)

On 28/12/2007, Robert Thullner <[EMAIL PROTECTED]> wrote:
> I wanted to replace the usage of new Expression() with an Xpath expression,
> but I cannot find the correct syntax to use, so that it will work.

You can do things like

.recipientList().xpath("/foo/bar", String.class)

to send to some endpoint defined using an XPath expression. If you
want to do something like use a JMS queue using some postfix which is
an XPath expression then something like this might help...

.recipientList().xpath("concat('activemq:Foo.', /foo/@bar)", String.class)

i.e. using a static string and adding a dynamic bit of XPath etc.

Then if the message body was

<foo bar="Cheese"/>

then the Recipient List would route the message to the ActiveMQ Queue
called Foo.Cheese


I did wonder as I started writing this mail if it was possible to use
the nice {} syntax in XQuery to make it easier to create XPath-based
Dynamic Recipient List URI strings. e.g. something vaguely like...

.recipientList().xquery("'activemq:Foo.{/foo/bar}'", String.class)

But I don't think its possible - unless I've missed something in
XQuery - I've not yet seen how to generate text output easily by
combining the concatenation of static strings and XPath expressions,
other than via the concat() call. (There's a test case called
XQueryRecipientListTest in the camel-saxon module I've just committed
if anyone fancies tinkering to try get this working).


BTW the String.class parameter in the above examples is just to tell
the XPath / XQuery expressions to evaluate as a String for the URI (as
opposed to some DOM or something). We might be able to make the
recipientList to be smart enough to pick this by default maybe (though
it could return a List of Strings I guess).


>
> My route is that:
> from("activemq:queue:camel.train.plan.queue").
> .setHeader("endpointName",
>         constant("activemq:queue:camel.train.plan.queue.").append(
>       new XPathBuilder("trainSchedule/destination/[EMAIL PROTECTED]")  ))
>         .recipientList(header("endpointName"));
>
>
> But what I get here is a queue with my xpath expression as name. I also
> tried to use XPathExpression instead of XPathBuilder, but this is not
> working either.
>
> Thanks
> Robert
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Roman Kalukiewicz [mailto:[EMAIL PROTECTED]
> Gesendet: Freitag, 28. Dezember 2007 17:05
> An: [email protected]
> Betreff: Re: XPath splitter again
>
> Notice that the method you are implementing is configure() method - it is
> executed ONCE at the very beginning. It is not executed on each message. And
> concatenation you use is executed when configure() method is executed - it
> is still Java after all.
>
> what you could do is
>
> from("activemq:queue:camel.train.plan.queue.router")
> .setHeader("endpointName",
> constant("activemq:queue:camel.train.plan.queue.").append(new
> Expression() {
>     public Object evaluate(Exchange exchange) {
>         return <evaluate your queue name postfix>
>     }))
> .receipentList(header("endpointName"));
> }
>
> Maybe instead of using new Expression() it will be enough to evaluate the
> value using xpath or el so it will be simpler?
>
> If you have only short list of destinations then maybe filter() is better
> for you?
>
> Roman
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Reply via email to