camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arjan Moraal <nab...@ajmoraal.fastmail.net>
Subject Splitter advice
Date Fri, 26 Oct 2007 11:58:16 GMT

Hi all,

Take the following XML:
  <cats>
    <cat name="Ginger"><colour id="1"/></cat>
    <cat name="Mr Boots"><colour id="3"/></cat>
    <cat name="Delphi"><colour id="1"/></cat>
  </cats>

Is it possible to use the Splitter to break split up this XML, but grouped
by colour id? So it should result in two messages:

  <cats>
    <cat name="Ginger"><colour id="1"/></cat>
    <cat name="Delphi"><colour id="1"/></cat>
  </cats>

and

  <cats>
    <cat name="Mr Boots"><colour id="3"/></cat>
  </cats>

Without the surrounding <cats> tags would be fine as well since I could add
these manually using setBody().

So far, I have set up this TestCase, but the problem is it breaks the xml up
into 3 messages instead of 2.

    public void testGroupedXMLSplitter() throws Exception {
        log.debug("testGroupedXMLSplitter()");
        
        final String xml = "<cats>" +
                        "<cat name=\"Ginger\"><colour id=\"1\"/></cat>"
+
                        "<cat name=\"Mr Boots\"><colour id=\"3\"/></cat>"
+
                        "<cat name=\"Delphi\"><colour id=\"1\"/></cat>"
+
                     "</cats>";
        
        context.addRoutes(
                new RouteBuilder() {
                    @Override
                    public void configure() {
                        from("direct:cats")
                            .splitter(xpath("/cats/cat/colour/@id"))
                            .to("mock:result");
                    }
                }
            );

            resultEndpoint.expectedMessageCount(2);
            
            template.send("direct:cats", new Processor() {
                public void process(Exchange exchange) {
                    Message in = exchange.getIn();
                    in.setBody(xml);
                }
            });
            
            resultEndpoint.assertIsSatisfied();
    }

Any help would be appreciated very much!

Thanks,
Arjan

-- 
View this message in context: http://www.nabble.com/Splitter-advice-tf4696876s22882.html#a13425803
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message