Hi
On Thu, Jul 29, 2010 at 10:36 PM, GSegel <[email protected]> wrote:
>
> I am trying to build a route using Java DSL and I'm getting a confusing error
> in my IDE (IntelliJ). Here's what I'm trying to do:
> 1. Receive a message from a JMS Queue
> 2. Enrich the message by querying a database to retrieve additional content
> (claim check pattern)
> 3. Filter the messages to exclude any 'test' messages
> 4. Print to the console
>
> Here's my Java DSL:
>
> public class MyRouteBuilder extends RouteBuilder {
>
> public void configure() throws Exception {
> from("jms:xmlOrders")
> .bean(enricher, "enrichData")
> .filter().xpath("/order[not(@test)]")
> .to("stream:out"); // ERROR on this line in IDE
> }
> }
>
>
> The IDE highlights the last line (.to("stream:out");) as an error and I'm
> having a hard time understanding why. If I remove the bean doing the
> enrichment it works fine. ie:
>
> from("jms:xmlOrders")
> //.bean(enricher, "enrichData") COMMENTED OUT
> .filter().xpath("/order[not(@test)]")
> .to("stream:out"); // NOW everything is fine
>
> I also tried replacing the bean with a new Processor that does the same
> thing in case the issue has to do with keeping the Exchange in tact but it
> still didn't make the error go away.
>
The issue is Java is generally not a good language to do DSL. And we
have stretched out how far you can go with using generics under the
hood as the DSL.
So there are situations where the java compiler goes "nuts".
The problem is centered when you use predicates/expressions as stacked
method calls. Instead use predicates/expressions as parameters.
.filter(xpath("/order[not(@test)]"))
Notice how xpath predicate is now a parameter to the filter method.
Then the Java DSL and generics should play well.
>
> I'm sure this is how it's supposed to work and is due to a lack of my
> understanding. I would be grateful if anyone could help me understand why
> this is happening!
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Help-with-filter-behavior-tp2256745p2256745.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus