Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
java
java
...
   private String someValue

   // This time, the closure is stored in a variable
   def predicatepred = { Exchange e -> e.in.body != someValue }
...
   from('direct:test')
      .filter(predicatepred)
...
Aggregation Strategy Closures

...

Code Block
java
java
...
   private String separator
...
   from('direct:test1')
      .enrich('direct:enrich') { Exchange original, Exchange resource -> 
         original.in.body += resource.in.body + separator
         original  // don't forget to return resulting exchange
      }
...
Generic closure bridges

In addition to the above-mentioned DSL extensions, you can use closures even if no DSL method signature with closure parameters is available. Assuming there's no filter(Closure) method, you could instead write:

Code Block
java
java

...
   private String someValue

   // This time, the closure is stored in a variable
   def pred = { Exchange e -> e.in.body != someValue }
...
   from('direct:test')
      // predicate(Closure) -> org.apache.camel.Predicate
      .filter(predicate(pred))
...

Similarly, expression(Closure) returns a Camel expression, processor(Closure) returns a Processor, and aggregator(Closure) returns an AggregationStrategy.

Using Groovy XML processing

...