ThaDon
ThaDon

Reputation: 8068

Camel RSS component and Choice filtering

I have a camel route that looks like this:

        from("rss:" + RSS_URL)
        .marshal().rss()
        .choice()
            .when(xpath("//item/guid/text()[contains(.,'4552')]"))
                .log("Cool")
                .to("seda:end")
            .otherwise()
                .log("Other message")
                .to("seda:end");

When I check the log I see exactly one message

[example.com/feed/] route1 INFO Other message

If I replace the choice with a filter directive and throw a process in there, my filter does work:

        from("rss:" + RSS_URL)
        .marshal().rss()
        .filter().xpath("//item/guid/text()[contains(.,'4552')]")
        .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            System.out.println("Got Here");
        }
    })
        .to("seda:end");

Sure enough, I see "Got Here" in my console. To make matters even worse, if I replace my process(...) with just log("Cool") I get messages in the log stating the filter matched false and I don't see "Cool" anywhere... I don't get that.

Can anyone tell what's going on?

Upvotes: 1

Views: 458

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

Which version of camel are you using? Did you try to use endChoice() DSL to mark the block of Choice?

from("rss:" + RSS_URL)
    .marshal().rss()
    .choice()
        .when(xpath("//item/guid/text()[contains(.,'4552')]"))
            .log("Cool")
            .to("seda:end")
        .endChoice()
        .otherwise()
            .log("Other message")
        .endChoice()
        .to("seda:end");

Upvotes: 1

Related Questions