You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2013/01/03 14:18:29 UTC

svn commit: r844756 - in /websites/production/camel/content: cache/main.pageCache groovy-dsl.html

Author: buildbot
Date: Thu Jan  3 13:18:29 2013
New Revision: 844756

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/groovy-dsl.html

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/camel/content/groovy-dsl.html
==============================================================================
--- websites/production/camel/content/groovy-dsl.html (original)
+++ websites/production/camel/content/groovy-dsl.html Thu Jan  3 13:18:29 2013
@@ -179,6 +179,8 @@ With the Groovy DSL you write your Route
 
 <h4><a shape="rect" name="GroovyDSL-UsingClosuresinyourroutes"></a>Using Closures in your routes</h4>
 
+<p>Groovy closures can be used to write concise implementations of Camel processors, expressions, predicates, and aggregation strategies. It is recommended to keep more complicated implementations of these objects in their own classes, e.g. to be able to test them more easily and not to clutter up your routes with business logic.</p>
+
 <h5><a shape="rect" name="GroovyDSL-ProcessorClosures"></a>Processor Closures</h5>
 
 <p>All Java DSL parameters of type <tt>org.apache.camel.Processor</tt> can be replaced by a closure that accepts an object of type <tt>org.apache.camel.Exchange</tt> as only parameter. The return value of the closure is disregarded. All closures may also refer to variables not listed in their parameter list. Example:</p>
@@ -189,8 +191,8 @@ With the Groovy DSL you write your Route
    <span class="code-keyword">private</span> <span class="code-object">String</span> someValue
 ...
    from('direct:test')
-      .process { Exchange exchange -&gt; println exchange.in.body + someValue }
-      .process { println it.in.body + someValue } <span class="code-comment">// equivalent
+      .process { Exchange exchange -&gt; println (exchange.in.body + someValue) }
+      .process { println (it.in.body + someValue) } <span class="code-comment">// equivalent
 </span>...
 </pre>
 </div></div>
@@ -222,10 +224,10 @@ With the Groovy DSL you write your Route
    <span class="code-keyword">private</span> <span class="code-object">String</span> someValue
 
    <span class="code-comment">// This time, the closure is stored in a variable
-</span>   def predicate = { Exchange e -&gt; e.in.body != someValue }
+</span>   def pred = { Exchange e -&gt; e.in.body != someValue }
 ...
    from('direct:test')
-      .filter(predicate)
+      .filter(pred)
 ...
 </pre>
 </div></div>
@@ -249,6 +251,27 @@ With the Groovy DSL you write your Route
 </pre>
 </div></div>
 
+<h5><a shape="rect" name="GroovyDSL-Genericclosurebridges"></a>Generic closure bridges</h5>
+
+<p>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 <tt>filter(Closure)</tt> method, you could instead write:</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+...
+   <span class="code-keyword">private</span> <span class="code-object">String</span> someValue
+
+   <span class="code-comment">// This time, the closure is stored in a variable
+</span>   def pred = { Exchange e -&gt; e.in.body != someValue }
+...
+   from('direct:test')
+      <span class="code-comment">// predicate(Closure) -&gt; org.apache.camel.Predicate
+</span>      .filter(predicate(pred))
+...
+</pre>
+</div></div>
+
+<p>Similarly, <tt>expression(Closure)</tt> returns a Camel expression, <tt>processor(Closure)</tt> returns a Processor, and <tt>aggregator(Closure)</tt> returns an AggregationStrategy.</p>
+
 
 <h4><a shape="rect" name="GroovyDSL-UsingGroovyXMLprocessing"></a>Using Groovy XML processing</h4>