You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tom Howe <to...@artcore.com> on 2011/03/16 17:35:24 UTC
Handling namespaces with content based routing using camel-activemq.
Hi, first post here!
We have an instance of apache-activemq running which includes camel.
We are sending some messages to a queue called 'in' that look like this:
<?xml version="1.0" encoding="utf-8"?>
<mp:command xmlns:mp="http://www.blah/blah" name="submit" >
<body>...</body>
</mp:command>
and
<?xml version="1.0" encoding="utf-8"?>
<mp:event xmlns:mp="http://www.blah/blah" name="status" >
<body>...</body>
</mp:event>
We need to route the messages based on their root element name and content
of @name
so the above messages need to go to the endpoints called commands.submit and
events.status.
I created the following route to test the @name based matching:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<route autoStartup="true" inheritErrorHandler="true" id="generalin"
xmlns:ns2="http://camel.apache.org/schema/web" xmlns="
http://camel.apache.org/schema/spring">
<from uri="activemq:in"/>
<choice inheritErrorHandler="true" id="choice1">
<when inheritErrorHandler="true">
<xpath>//*[contains(@name,"submit")]</xpath>
<to uri="activemq:commands.submit" inheritErrorHandler="true"
id="to2"/>
</when>
<otherwise inheritErrorHandler="true">
<to uri="activemq:lostandfound" inheritErrorHandler="true"
id="to4"/>
</otherwise>
</choice>
</route>
This route works fine. It routes any messages where name contains 'submit'
to the right endpoint.
I then tried to modify the route so that it matched <mp:command>. I tried
changing the xpath to
<xpath>//command[contains(@name,"submit")]</xpath>
<xpath>//mp:command[contains(@name,"submit")]</xpath>
and neither worked. Also the message did not get routed to anywhere -ie it
didnt go to lostandfound.
I also tried adding xmlns:mp="http://www.blah/blah" to the <route> part of
the route definition but it was removed when I saved the route.
Any advice appreciated.
Thanks, Tom
Re: Handling namespaces with content based routing using
camel-activemq.
Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,
Please add the following to the beans tag of you camel-context.xml
------------------------------------------------------------------------------
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mp="http://www.blah/blah"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">
----------------------------------------------------------------------------------
Cheers,
Ashwin...
-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com
Blog: http://opensourceknowledge.blogspot.com
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Handling-namespaces-with-content-based-routing-using-camel-activemq-tp3788073p3892829.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Handling namespaces with content based routing using camel-activemq.
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Mar 18, 2011 at 11:25 AM, Willem Jiang <wi...@gmail.com> wrote:
> Hi
>
> I don't think current camel spring configuration support the xpath with the
> name space.
>
Yes it does. You can use namespaces with xpath in XML DSL. See the
xpath wiki page
http://camel.apache.org/xpath
In fact you must use namespace in the XPath if your XML has namespaces in it.
> You can take a look at Java DSL one from here[1]
>
> [1]https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathNestedNamespaceTest.java
>
> Willem
>
> On 3/17/11 12:35 AM, Tom Howe wrote:
>>
>> Hi, first post here!
>>
>> We have an instance of apache-activemq running which includes camel.
>>
>> We are sending some messages to a queue called 'in' that look like this:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <mp:command xmlns:mp="http://www.blah/blah" name="submit">
>> <body>...</body>
>> </mp:command>
>>
>> and
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <mp:event xmlns:mp="http://www.blah/blah" name="status">
>> <body>...</body>
>> </mp:event>
>>
>> We need to route the messages based on their root element name and content
>> of @name
>> so the above messages need to go to the endpoints called commands.submit
>> and
>> events.status.
>>
>> I created the following route to test the @name based matching:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>> <route autoStartup="true" inheritErrorHandler="true" id="generalin"
>> xmlns:ns2="http://camel.apache.org/schema/web" xmlns="
>> http://camel.apache.org/schema/spring">
>> <from uri="activemq:in"/>
>> <choice inheritErrorHandler="true" id="choice1">
>> <when inheritErrorHandler="true">
>> <xpath>//*[contains(@name,"submit")]</xpath>
>> <to uri="activemq:commands.submit" inheritErrorHandler="true"
>> id="to2"/>
>> </when>
>> <otherwise inheritErrorHandler="true">
>> <to uri="activemq:lostandfound" inheritErrorHandler="true"
>> id="to4"/>
>> </otherwise>
>> </choice>
>> </route>
>>
>> This route works fine. It routes any messages where name contains 'submit'
>> to the right endpoint.
>>
>> I then tried to modify the route so that it matched<mp:command>. I tried
>> changing the xpath to
>>
>> <xpath>//command[contains(@name,"submit")]</xpath>
>> <xpath>//mp:command[contains(@name,"submit")]</xpath>
>>
>> and neither worked. Also the message did not get routed to anywhere -ie it
>> didnt go to lostandfound.
>>
>> I also tried adding xmlns:mp="http://www.blah/blah" to the<route> part
>> of
>> the route definition but it was removed when I saved the route.
>>
>> Any advice appreciated.
>>
>> Thanks, Tom
>>
>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Handling namespaces with content based routing using camel-activemq.
Posted by Willem Jiang <wi...@gmail.com>.
Hi
I don't think current camel spring configuration support the xpath with
the name space.
You can take a look at Java DSL one from here[1]
[1]https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathNestedNamespaceTest.java
Willem
On 3/17/11 12:35 AM, Tom Howe wrote:
> Hi, first post here!
>
> We have an instance of apache-activemq running which includes camel.
>
> We are sending some messages to a queue called 'in' that look like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mp:command xmlns:mp="http://www.blah/blah" name="submit">
> <body>...</body>
> </mp:command>
>
> and
>
> <?xml version="1.0" encoding="utf-8"?>
> <mp:event xmlns:mp="http://www.blah/blah" name="status">
> <body>...</body>
> </mp:event>
>
> We need to route the messages based on their root element name and content
> of @name
> so the above messages need to go to the endpoints called commands.submit and
> events.status.
>
> I created the following route to test the @name based matching:
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <route autoStartup="true" inheritErrorHandler="true" id="generalin"
> xmlns:ns2="http://camel.apache.org/schema/web" xmlns="
> http://camel.apache.org/schema/spring">
> <from uri="activemq:in"/>
> <choice inheritErrorHandler="true" id="choice1">
> <when inheritErrorHandler="true">
> <xpath>//*[contains(@name,"submit")]</xpath>
> <to uri="activemq:commands.submit" inheritErrorHandler="true"
> id="to2"/>
> </when>
> <otherwise inheritErrorHandler="true">
> <to uri="activemq:lostandfound" inheritErrorHandler="true"
> id="to4"/>
> </otherwise>
> </choice>
> </route>
>
> This route works fine. It routes any messages where name contains 'submit'
> to the right endpoint.
>
> I then tried to modify the route so that it matched<mp:command>. I tried
> changing the xpath to
>
> <xpath>//command[contains(@name,"submit")]</xpath>
> <xpath>//mp:command[contains(@name,"submit")]</xpath>
>
> and neither worked. Also the message did not get routed to anywhere -ie it
> didnt go to lostandfound.
>
> I also tried adding xmlns:mp="http://www.blah/blah" to the<route> part of
> the route definition but it was removed when I saved the route.
>
> Any advice appreciated.
>
> Thanks, Tom
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang