camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Matèrne (jhm) <apa...@materne.de>
Subject AW: Calling count function in the camel route
Date Mon, 04 Feb 2013 13:24:28 GMT
Played a little bit with that.
This example works for me.

cheers
Jan


public class XpathCountTest extends CamelTestSupport {

	@Test
	public void count() {
		final MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);
        
        template.sendBody("direct:in", "<root><A/><A/><B/><A/></root>");
        
        assertEquals(
        	"Wrong count",
        	3,
        	mock.getExchanges().get(0).getIn().getHeader("count"));
	}
	
	@Override
	protected RouteBuilder createRouteBuilder() throws Exception {
		return new RouteBuilder() {
			public void configure() {
				from("direct:in")
				    .setHeader("count",
xpath("count(//A)").resultType(Integer.class))
				    .to("mock:result");
			}
		};
	}
	
}

-----Urspr√ľngliche Nachricht-----
Von: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Gesendet: Montag, 4. Februar 2013 14:07
An: users@camel.apache.org
Betreff: Re: Calling count function in the camel route

On Mon, Feb 4, 2013 at 1:45 PM, dkum003 <DHANANJAY.KUMAR@amadeus.com> wrote:
> Hi Claus,
>
> The xml is pretty simple.. say a list of tags...
>
>
> So i need to get the count of h3 tags and store it in the exchange header.
>

Hi

See this page
http://camel.apache.org/xpath

About namespace auditing. If your xml has namespaces, then your xpath
expression must have that as well.
And then its not so easy to get working.

There may be some xpath tools / tutorials you can take a look at to make the
count work

Maybe something like
"count(//h3)"

Mind that if you have namesapces, you need to add that to the count
"count(//foo:h3)"

Where foo is your namespace "key".



> Thanks.
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Calling-count-function-in-the-camel-
> route-tp5726886p5726891.html Sent from the Camel - Users mailing list 
> archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


Mime
View raw message