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 predicate = { Exchange e -> e.in.body != someValue }
...
   from('direct:test')
      .filter { it.in.body != someValue }(predicate)
...
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
      }
...

Using Groovy XML processing

Groovy provides special XML processing support through its XmlParser, XmlNodePrinter and XmlSlurper classes. camel-groovy provides two data formats to use these classes directly in your routes.

Code Block
java
java
titleUnmarshal XML with XmlParser

...
   from('direct:test1')
      .unmarshal().gnode() 
      // message body is now of type groovy.util.Node
...

By default, XML processing is namespace-aware. You can change this by providing a boolean false parameter.

Code Block
java
java
titleUnmarshal XML with XmlSlurper

...
   from('direct:test1')
      .unmarshal().gpath(false) // explicitly namespace-unaware
      // message body is now of type groovy.util.slurpersupport.GPathResult
...

Currently, marshalling is only supported for groovy.util.Node objects.

Code Block
java
java
titleMarshal XML with XmlNodePrinter

...
   from('direct:test1')
      // message body must be of type groovy.util.Node
      .marshal().gnode()
...

Using Groovy GStrings

Groovy GStrings are declared inside double-quotes and can contain arbitrary Groovy expressions like accessing properties or calling methods, e.g.

...