Modified: websites/production/camel/content/book-cookbook.html
==============================================================================
--- websites/production/camel/content/book-cookbook.html (original)
+++ websites/production/camel/content/book-cookbook.html Tue May 15 07:21:12 
2018
@@ -219,47 +219,81 @@ public class MySimpleIdGenerator {
 </div></div>
 
 <p>Groovy supports GStrings that is like a template where we can insert $ 
placeholders that will be evaluated by Groovy.</p>
-<h2 id="Bookcookbook-BeanBinding">Bean Binding</h2><p>Bean Binding in Camel 
defines both which methods are invoked and also how the <a shape="rect" 
href="message.html">Message</a> is converted into the parameters of the method 
when it is invoked.</p><h3 id="Bookcookbook-Choosingthemethodtoinvoke">Choosing 
the method to invoke</h3><p>The binding of a Camel <a shape="rect" 
href="message.html">Message</a> to a bean method call can occur in different 
ways, in the following order of importance:</p><ul><li>if the message contains 
the header <strong>CamelBeanMethodName</strong> then that method is invoked, 
converting the body to the type of the method's argument.<ul><li>From 
<strong>Camel 2.8</strong> onwards you can qualify parameter types to select 
exactly which method to use among overloads with the same name (see below for 
more details).</li><li>From <strong>Camel 2.9</strong> onwards you can specify 
parameter values directly in the method option (see below for more 
details).</li></ul>
 </li><li>you can explicitly specify the method name in the <a shape="rect" 
href="dsl.html">DSL</a> or when using <a shape="rect" 
href="pojo-consuming.html">POJO Consuming</a> or <a shape="rect" 
href="pojo-producing.html">POJO Producing</a></li><li>if the bean has a method 
marked with the <code>@Handler</code> annotation, then that method is 
selected</li><li>if the bean can be converted to a <a shape="rect" 
href="processor.html">Processor</a> using the <a shape="rect" 
href="type-converter.html">Type Converter</a> mechanism, then this is used to 
process the message. The <a shape="rect" href="activemq.html">ActiveMQ</a> 
component uses this mechanism to allow any JMS MessageListener to be invoked 
directly by Camel without having to write any integration glue code. You can 
use the same mechanism to integrate Camel into any other messaging/remoting 
frameworks.</li><li>if the body of the message can be converted to a <a 
shape="rect" class="external-link" href="http://camel.apache.org/maven
 
/current/camel-core/apidocs/org/apache/camel/component/bean/BeanInvocation.html">BeanInvocation</a>
 (the default payload used by the <a shape="rect" class="external-link" 
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html";>ProxyHelper</a>)
 component - then that is used to invoke the method and pass its 
arguments</li><li>otherwise the type of the body is used to find a matching 
method; an error is thrown if a single method cannot be chosen 
unambiguously.</li><li>you can also use Exchange as the parameter itself, but 
then the return type must be void.</li><li>if the bean class is private (or 
package-private), interface methods will be preferred (from <strong>Camel 
2.9</strong> onwards) since Camel can't invoke class methods on such 
beans</li></ul><p>In cases where Camel cannot choose a method to invoke, an 
<code>AmbiguousMethodCallException</code> is thrown.</p><p>By default the 
return value is set on the outbound message bo
 dy.&#160;</p><h3 id="Bookcookbook-Asynchronousprocessing">Asynchronous 
processing</h3><p>From&#160;<strong>Camel 2.18</strong>&#160;onwards you can 
return a CompletionStage implementation (e.g. a CompletableFuture) to implement 
asynchronous processing.</p><p>Please be sure to properly complete the 
CompletionStage with the result or exception, including any timeout handling. 
Exchange processing would wait for completion and would not impose any timeouts 
automatically. It's extremely useful to monitor&#160;<a shape="rect" 
class="external-link" 
href="https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/InflightRepository.html";>Inflight
 repository</a> for any hanging messages.</p><p>Note that completing with 
"null" won't set outbody message body to null, but would keep message intact. 
This is useful to support methods that don't modify exchange and return 
CompletableFuture&lt;Void&gt;. To set body to null, just add Exchange method 
parameter and directly modify 
 exchange messages.</p><p>Examples:</p><p>Simple asynchronous processor, 
modifying message body.</p><parameter 
ac:name="language">java</parameter><plain-text-body>public 
CompletableFuture&lt;String&gt; doSomethingAsync(String 
body)</plain-text-body><p>Composite processor that do not modify 
exchange</p><parameter 
ac:name="language">java</parameter><plain-text-body>public 
CompletableFuture&lt;Void&gt; doSomethingAsync(String body) {
-       return CompletableFuture.allOf(doA(body), doB(body), doC());
-}</plain-text-body><h3 id="Bookcookbook-Parameterbinding">Parameter 
binding</h3><p>When a method has been chosen for invocation, Camel will bind to 
the parameters of the method.</p><p>The following Camel-specific types are 
automatically bound:</p><ul 
class="alternate"><li><code>org.apache.camel.Exchange</code></li><li><code>org.apache.camel.Message</code></li><li><code>org.apache.camel.CamelContext</code></li><li><code>org.apache.camel.TypeConverter</code></li><li><code>org.apache.camel.spi.Registry</code></li><li><code>java.lang.Exception</code></li></ul><p>So,
 if you declare any of these types, they will be provided by Camel. 
<strong>Note that <code>Exception</code> will bind to the caught exception of 
the <a shape="rect" href="exchange.html">Exchange</a></strong> - so it's often 
usable if you employ a <a shape="rect" href="pojo.html">Pojo</a> to handle, 
e.g., an <code>onException</code> route.</p><p>What is most interesting is that 
Camel will also try to bind the body of the <a s
 hape="rect" href="exchange.html">Exchange</a> to the first parameter of the 
method signature (albeit not of any of the types above). So if, for instance, 
we declare a parameter as <code>String body</code>, then Camel will bind the IN 
body to this type. Camel will also automatically convert to the type declared 
in the method signature.</p><p>Let's review some examples:</p><p>Below is a 
simple method with a body binding. Camel will bind the IN body to the 
<code>body</code> parameter and convert it to a 
<code>String</code>.</p><plain-text-body>public String doSomething(String body)
-</plain-text-body><p>In the following sample we got one of the 
automatically-bound types as well - for instance, a <code>Registry</code> that 
we can use to lookup beans.</p><plain-text-body>public String 
doSomething(String body, Registry registry)
-</plain-text-body><p>We can use <a shape="rect" 
href="exchange.html">Exchange</a> as well:</p><plain-text-body>public String 
doSomething(String body, Exchange exchange)
-</plain-text-body><p>You can also have multiple 
types:</p><plain-text-body>public String doSomething(String body, Exchange 
exchange, TypeConverter converter)
-</plain-text-body><p>And imagine you use a <a shape="rect" 
href="pojo.html">Pojo</a> to handle a given custom exception 
<code>InvalidOrderException</code> - we can then bind that as 
well:</p><plain-text-body>public String badOrder(String body, 
InvalidOrderException invalid)
-</plain-text-body><p>Notice that we can bind to it even if we use a sub type 
of <code>java.lang.Exception</code> as Camel still knows it's an exception and 
can bind the cause (if any exists).</p><p>So what about headers and other 
stuff? Well now it gets a bit tricky - so we can use annotations to help us, or 
specify the binding in the method name option.<br clear="none"> See the 
following sections for more detail.</p><h3 
id="Bookcookbook-BindingAnnotations">Binding Annotations</h3><p>You can use the 
<a shape="rect" href="parameter-binding-annotations.html">Parameter Binding 
Annotations</a> to customize how parameter values are created from the <a 
shape="rect" href="message.html">Message</a></p><h4 
id="Bookcookbook-Examples">Examples</h4><p>For example, a <a shape="rect" 
href="bean.html">Bean</a> such as:</p><plain-text-body>public class Bar {
-
+<h2 id="Bookcookbook-BeanBinding">Bean Binding</h2><p>Bean Binding in Camel 
defines both which methods are invoked and also how the <a shape="rect" 
href="message.html">Message</a> is converted into the parameters of the method 
when it is invoked.</p><h3 id="Bookcookbook-Choosingthemethodtoinvoke">Choosing 
the method to invoke</h3><p>The binding of a Camel <a shape="rect" 
href="message.html">Message</a> to a bean method call can occur in different 
ways, in the following order of importance:</p><ul><li>if the message contains 
the header <strong>CamelBeanMethodName</strong> then that method is invoked, 
converting the body to the type of the method's argument.<ul><li>From 
<strong>Camel 2.8</strong> onwards you can qualify parameter types to select 
exactly which method to use among overloads with the same name (see below for 
more details).</li><li>From <strong>Camel 2.9</strong> onwards you can specify 
parameter values directly in the method option (see below for more 
details).</li></ul>
 </li><li>you can explicitly specify the method name in the <a shape="rect" 
href="dsl.html">DSL</a> or when using <a shape="rect" 
href="pojo-consuming.html">POJO Consuming</a> or <a shape="rect" 
href="pojo-producing.html">POJO Producing</a></li><li>if the bean has a method 
marked with the <code>@Handler</code> annotation, then that method is 
selected</li><li>if the bean can be converted to a <a shape="rect" 
href="processor.html">Processor</a> using the <a shape="rect" 
href="type-converter.html">Type Converter</a> mechanism, then this is used to 
process the message. The <a shape="rect" href="activemq.html">ActiveMQ</a> 
component uses this mechanism to allow any JMS MessageListener to be invoked 
directly by Camel without having to write any integration glue code. You can 
use the same mechanism to integrate Camel into any other messaging/remoting 
frameworks.</li><li>if the body of the message can be converted to a <a 
shape="rect" class="external-link" href="http://camel.apache.org/maven
 
/current/camel-core/apidocs/org/apache/camel/component/bean/BeanInvocation.html">BeanInvocation</a>
 (the default payload used by the <a shape="rect" class="external-link" 
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html";>ProxyHelper</a>)
 component - then that is used to invoke the method and pass its 
arguments</li><li>otherwise the type of the body is used to find a matching 
method; an error is thrown if a single method cannot be chosen 
unambiguously.</li><li>you can also use Exchange as the parameter itself, but 
then the return type must be void.</li><li>if the bean class is private (or 
package-private), interface methods will be preferred (from <strong>Camel 
2.9</strong> onwards) since Camel can't invoke class methods on such 
beans</li></ul><p>In cases where Camel cannot choose a method to invoke, an 
<code>AmbiguousMethodCallException</code> is thrown.</p><p>By default the 
return value is set on the outbound message bo
 dy.&#160;</p><h3 id="Bookcookbook-Asynchronousprocessing">Asynchronous 
processing</h3><p>From&#160;<strong>Camel 2.18</strong>&#160;onwards you can 
return a CompletionStage implementation (e.g. a CompletableFuture) to implement 
asynchronous processing.</p><p>Please be sure to properly complete the 
CompletionStage with the result or exception, including any timeout handling. 
Exchange processing would wait for completion and would not impose any timeouts 
automatically. It's extremely useful to monitor&#160;<a shape="rect" 
class="external-link" 
href="https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/InflightRepository.html";>Inflight
 repository</a> for any hanging messages.</p><p>Note that completing with 
"null" won't set outbody message body to null, but would keep message intact. 
This is useful to support methods that don't modify exchange and return 
CompletableFuture&lt;Void&gt;. To set body to null, just add Exchange method 
parameter and directly modify 
 exchange messages.</p><p>Examples:</p><p>Simple asynchronous processor, 
modifying message body.</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public CompletableFuture&lt;String&gt; 
doSomethingAsync(String body)]]></script>
+</div></div><p><br clear="none">Composite processor that do not modify 
exchange</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ public CompletableFuture&lt;Void&gt; 
doSomethingAsync(String body) {
+     return CompletableFuture.allOf(doA(body), doB(body), doC()); 
+ }]]></script>
+</div></div><h3 id="Bookcookbook-Parameterbinding"><br clear="none">Parameter 
binding</h3><p>When a method has been chosen for invocation, Camel will bind to 
the parameters of the method.</p><p>The following Camel-specific types are 
automatically bound:</p><ul 
class="alternate"><li><code>org.apache.camel.Exchange</code></li><li><code>org.apache.camel.Message</code></li><li><code>org.apache.camel.CamelContext</code></li><li><code>org.apache.camel.TypeConverter</code></li><li><code>org.apache.camel.spi.Registry</code></li><li><code>java.lang.Exception</code></li></ul><p>So,
 if you declare any of these types, they will be provided by Camel. 
<strong>Note that <code>Exception</code> will bind to the caught exception of 
the <a shape="rect" href="exchange.html">Exchange</a></strong> - so it's often 
usable if you employ a <a shape="rect" href="pojo.html">Pojo</a> to handle, 
e.g., an <code>onException</code> route.</p><p>What is most interesting is that 
Camel will also try to bind the body o
 f the <a shape="rect" href="exchange.html">Exchange</a> to the first parameter 
of the method signature (albeit not of any of the types above). So if, for 
instance, we declare a parameter as <code>String body</code>, then Camel will 
bind the IN body to this type. Camel will also automatically convert to the 
type declared in the method signature.</p><p>Let's review some 
examples:</p><p>Below is a simple method with a body binding. Camel will bind 
the IN body to the <code>body</code> parameter and convert it to a 
<code>String</code>.</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public String doSomething(String 
body)]]></script>
+</div></div><p>In the following sample we got one of the automatically-bound 
types as well - for instance, a <code>Registry</code> that we can use to lookup 
beans.</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public String doSomething(String body, 
Registry registry) ]]></script>
+</div></div><p><br clear="none">We can use <a shape="rect" 
href="exchange.html">Exchange</a> as well:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public String doSomething(String body, 
Exchange exchange) ]]></script>
+</div></div><p><br clear="none">You can also have multiple types:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public String doSomething(String body, 
Exchange exchange, TypeConverter converter) ]]></script>
+</div></div><p><br clear="none">And imagine you use a <a shape="rect" 
href="pojo.html">Pojo</a> to handle a given custom exception 
<code>InvalidOrderException</code> - we can then bind that as well:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public String badOrder(String body, 
InvalidOrderException invalid) ]]></script>
+</div></div><p><br clear="none">Notice that we can bind to it even if we use a 
sub type of <code>java.lang.Exception</code> as Camel still knows it's an 
exception and can bind the cause (if any exists).</p><p>So what about headers 
and other stuff? Well now it gets a bit tricky - so we can use annotations to 
help us, or specify the binding in the method name option.<br clear="none"> See 
the following sections for more detail.</p><h3 
id="Bookcookbook-BindingAnnotations">Binding Annotations</h3><p>You can use the 
<a shape="rect" href="parameter-binding-annotations.html">Parameter Binding 
Annotations</a> to customize how parameter values are created from the <a 
shape="rect" href="message.html">Message</a></p><h4 
id="Bookcookbook-Examples">Examples</h4><p>For example, a <a shape="rect" 
href="bean.html">Bean</a> such as:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public class Bar {
     public String doSomething(String body) {
-      // process the in body and return whatever you want
-      return "Bye World";
-   }
-</plain-text-body><p>Or the Exchange example. Notice that the return type must 
be <strong>void</strong> when there is only a single parameter of the type 
<code>org.apache.camel.Exchange</code>:</p><plain-text-body>public class Bar {
-
-    public void doSomething(Exchange exchange) {
-      // process the exchange
-      exchange.getIn().setBody("Bye World");
-   }
-</plain-text-body><h4 id="Bookcookbook-@Handler">@Handler</h4><p>You can mark 
a method in your bean with the @Handler annotation to indicate that this method 
should be used for <a shape="rect" href="bean-binding.html">Bean 
Binding</a>.<br clear="none"> This has an advantage as you need not specify a 
method name in the Camel route, and therefore do not run into problems after 
renaming the method in an IDE that can't find all its references.</p><parameter 
ac:name="">java</parameter><plain-text-body>public class Bar {
-
-    @Handler
+    // process the in body and return whatever you want 
+    return &quot;Bye World&quot;; 
+} ]]></script>
+</div></div><p>Or the Exchange example. Notice that the return type must be 
<strong>void</strong> when there is only a single parameter of the type 
<code>org.apache.camel.Exchange</code>:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ public class Bar {
+     public void doSomething(Exchange exchange) {
+         // process the exchange 
+         exchange.getIn().setBody(&quot;Bye World&quot;); 
+ }]]></script>
+</div></div><h4 id="Bookcookbook-@Handler"><br 
clear="none">@Handler</h4><p>You can mark a method in your bean with the 
@Handler annotation to indicate that this method should be used for <a 
shape="rect" href="bean-binding.html">Bean Binding</a>.<br clear="none"> This 
has an advantage as you need not specify a method name in the Camel route, and 
therefore do not run into problems after renaming the method in an IDE that 
can't find all its references.</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public class Bar {
+    @Handler 
     public String doSomething(String body) {
-      // process the in body and return whatever you want
-      return "Bye World";
-   }
-</plain-text-body><h3 
id="Bookcookbook-Parameterbindingusingmethodoption">Parameter binding using 
method option</h3><p><strong>Available as of Camel 2.9</strong></p><p>Camel 
uses the following rules to determine if it's a parameter value in the method 
option</p><ul class="alternate"><li>The value is either <code>true</code> or 
<code>false</code> which denotes a boolean value</li><li>The value is a numeric 
value such as <code>123</code> or <code>7</code></li><li>The value is a String 
enclosed with either single or double quotes</li><li>The value is null which 
denotes a <code>null</code> value</li><li>It can be evaluated using the <a 
shape="rect" href="simple.html">Simple</a> language, which means you can use, 
e.g., body, header.foo and other <a shape="rect" href="simple.html">Simple</a> 
tokens. Notice the tokens must be enclosed with ${ }.</li></ul><p>Any other 
value is consider to be a type declaration instead - see the next section about 
specifying types for overloaded methods.</p>
 <p>When invoking a <a shape="rect" href="bean.html">Bean</a> you can instruct 
Camel to invoke a specific method by providing the method 
name:</p><plain-text-body>   .bean(OrderService.class, "doSomething")
-</plain-text-body><p>Here we tell Camel to invoke the doSomething method - 
Camel handles the parameters' binding. Now suppose the method has 2 parameters, 
and the 2nd parameter is a boolean where we want to pass in a true 
value:</p><plain-text-body>public void doSomething(String payload, boolean 
highPriority) {
-   ...
-}
-</plain-text-body><p>This is now possible in <strong>Camel 2.9</strong> 
onwards:</p><plain-text-body>   .bean(OrderService.class, "doSomething(*, 
true)")
-</plain-text-body><p>In the example above, we defined the first parameter 
using the wild card symbol *, which tells Camel to bind this parameter to any 
type, and let Camel figure this out. The 2nd parameter has a fixed value of 
<code>true</code>. Instead of the wildcard symbol we can instruct Camel to use 
the message body as shown:</p><plain-text-body>   .bean(OrderService.class, 
"doSomething(${body}, true)")
-</plain-text-body><p>The syntax of the parameters is using the <a shape="rect" 
href="simple.html">Simple</a> expression language so we have to use ${ } 
placeholders in the body to refer to the message body.</p><p>If you want to 
pass in a <code>null</code> value, then you can explicit define this in the 
method option as shown below:</p><plain-text-body>   
.to("bean:orderService?method=doSomething(null, true)")
-</plain-text-body><p>Specifying <code>null</code> as a parameter value 
instructs Camel to force passing a <code>null</code> value.</p><p>Besides the 
message body, you can pass in the message headers as a 
<code>java.util.Map</code>:</p><plain-text-body>   .bean(OrderService.class, 
"doSomethingWithHeaders(${body}, ${headers})")
-</plain-text-body><p>You can also pass in other fixed values besides booleans. 
For example, you can pass in a String and an integer:</p><plain-text-body>   
.bean(MyBean.class, "echo('World', 5)")
-</plain-text-body><p>In the example above, we invoke the echo method with two 
parameters. The first has the content 'World' (without quotes), and the 2nd has 
the value of 5.<br clear="none"> Camel will automatically convert these values 
to the parameters' types.</p><p>Having the power of the <a shape="rect" 
href="simple.html">Simple</a> language allows us to bind to message headers and 
other values such as:</p><plain-text-body>   .bean(OrderService.class, 
"doSomething(${body}, ${header.high})")
-</plain-text-body><p>You can also use the OGNL support of the <a shape="rect" 
href="simple.html">Simple</a> expression language. Now suppose the message body 
is an object which has a method named <code>asXml</code>. To invoke the 
<code>asXml</code> method we can do as follows:</p><plain-text-body>   
.bean(OrderService.class, "doSomething(${body.asXml}, ${header.high})")
-</plain-text-body><p>Instead of using <code>.bean</code> as shown in the 
examples above, you may want to use <code>.to</code> instead as 
shown:</p><plain-text-body>   
.to("bean:orderService?method=doSomething(${body.asXml}, ${header.high})")
-</plain-text-body><h3 
id="Bookcookbook-Usingtypequalifierstoselectamongoverloadedmethods">Using type 
qualifiers to select among overloaded methods</h3><p><strong>Available as of 
Camel 2.8</strong></p><p>If you have a <a shape="rect" 
href="bean.html">Bean</a> with overloaded methods, you can now specify 
parameter types in the method name so Camel can match the method you intend to 
use.<br clear="none"> Given the following 
bean:<plain-text-body>{snippet:id=e1|lang=java|title=MyBean|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}</plain-text-body>Then
 the <code>MyBean</code> has 2 overloaded methods with the names 
<code>hello</code> and <code>times</code>. So if we want to use the method 
which has 2 parameters we can do as follows in the Camel 
route:<plain-text-body>{snippet:id=e2|lang=java|title=Invoke 2 parameter 
method|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}</plain
 -text-body>We can also use a <code>*</code> as wildcard so we can just say we 
want to execute the method with 2 parameters we 
do<plain-text-body>{snippet:id=e3|lang=java|title=Invoke 2 parameter method 
using 
wildcard|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}</plain-text-body>By
 default Camel will match the type name using the simple name, e.g. any leading 
package name will be disregarded. However if you want to match using the FQN, 
then specify the FQN type and Camel will leverage that. So if you have a 
<code>com.foo.MyOrder</code> and you want to match against the FQN, and 
<strong>not</strong> the simple name "MyOrder", then follow this 
example:</p><plain-text-body>   .bean(OrderService.class, 
"doSomething(com.foo.MyOrder)")
-</plain-text-body><rich-text-body><p>Camel currently only supports either 
specifying parameter binding or type per parameter in the method name option. 
You <strong>cannot</strong> specify both at the same time, such 
as</p><plain-text-body>doSomething(com.foo.MyOrder ${body}, boolean 
${header.high})
-</plain-text-body><p>This may change in the future.</p></rich-text-body>
+        // process the in body and return whatever you want 
+        return &quot;Bye World&quot;; 
+    }
+} ]]></script>
+</div></div><h3 id="Bookcookbook-Parameterbindingusingmethodoption"><br 
clear="none">Parameter binding using method option</h3><p><strong>Available as 
of Camel 2.9</strong></p><p>Camel uses the following rules to determine if it's 
a parameter value in the method option</p><ul class="alternate"><li>The value 
is either <code>true</code> or <code>false</code> which denotes a boolean 
value</li><li>The value is a numeric value such as <code>123</code> or 
<code>7</code></li><li>The value is a String enclosed with either single or 
double quotes</li><li>The value is null which denotes a <code>null</code> 
value</li><li>It can be evaluated using the <a shape="rect" 
href="simple.html">Simple</a> language, which means you can use, e.g., body, 
header.foo and other <a shape="rect" href="simple.html">Simple</a> tokens. 
Notice the tokens must be enclosed with ${ }.</li></ul><p>Any other value is 
consider to be a type declaration instead - see the next section about 
specifying types for overloaded m
 ethods.</p><p>When invoking a <a shape="rect" href="bean.html">Bean</a> you 
can instruct Camel to invoke a specific method by providing the method 
name:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething&quot;)]]></script>
+</div></div><p>&#160;</p><p>Here we tell Camel to invoke the doSomething 
method - Camel handles the parameters' binding. Now suppose the method has 2 
parameters, and the 2nd parameter is a boolean where we want to pass in a true 
value:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public void doSomething(String payload, 
boolean highPriority) {
+    ... 
+}]]></script>
+</div></div><p>&#160;</p><p>This is now possible in <strong>Camel 2.9</strong> 
onwards:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething(*, true)&quot;) ]]></script>
+</div></div><p><br clear="none">In the example above, we defined the first 
parameter using the wild card symbol *, which tells Camel to bind this 
parameter to any type, and let Camel figure this out. The 2nd parameter has a 
fixed value of <code>true</code>. Instead of the wildcard symbol we can 
instruct Camel to use the message body as shown:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething(${body}, true)&quot;) ]]></script>
+</div></div><p>&#160;</p><p>The syntax of the parameters is using the <a 
shape="rect" href="simple.html">Simple</a> expression language so we have to 
use ${ } placeholders in the body to refer to the message body.</p><p>If you 
want to pass in a <code>null</code> value, then you can explicit define this in 
the method option as shown below:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.to(&quot;bean:orderService?method=doSomething(null,
 true)&quot;)]]></script>
+</div></div><p><br clear="none">Specifying <code>null</code> as a parameter 
value instructs Camel to force passing a <code>null</code> value.</p><p>Besides 
the message body, you can pass in the message headers as a 
<code>java.util.Map</code>:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomethingWithHeaders(${body}, ${headers})&quot;) ]]></script>
+</div></div><p>You can also pass in other fixed values besides booleans. For 
example, you can pass in a String and an integer:</p><div class="code panel 
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(MyBean.class, 
&quot;echo(&#39;World&#39;, 5)&quot;) ]]></script>
+</div></div><p><br clear="none">In the example above, we invoke the echo 
method with two parameters. The first has the content 'World' (without quotes), 
and the 2nd has the value of 5.<br clear="none"> Camel will automatically 
convert these values to the parameters' types.</p><p>Having the power of the <a 
shape="rect" href="simple.html">Simple</a> language allows us to bind to 
message headers and other values such as:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething(${body}, ${header.high})&quot;) ]]></script>
+</div></div><p>You can also use the OGNL support of the <a shape="rect" 
href="simple.html">Simple</a> expression language. Now suppose the message body 
is an object which has a method named <code>asXml</code>. To invoke the 
<code>asXml</code> method we can do as follows:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething(${body.asXml}, ${header.high})&quot;) ]]></script>
+</div></div><p>Instead of using <code>.bean</code> as shown in the examples 
above, you may want to use <code>.to</code> instead as shown:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.to(&quot;bean:orderService?method=doSomething(${body.asXml},
 ${header.high})&quot;) ]]></script>
+</div></div><h3 
id="Bookcookbook-Usingtypequalifierstoselectamongoverloadedmethods"><br 
clear="none">Using type qualifiers to select among overloaded 
methods</h3><p><strong>Available as of Camel 2.8</strong></p><p>If you have a 
<a shape="rect" href="bean.html">Bean</a> with overloaded methods, you can now 
specify parameter types in the method name so Camel can match the method you 
intend to use.<br clear="none"> Given the following bean:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ from(&quot;direct:start&quot;)
+    .bean(MyBean.class, &quot;hello(String)&quot;)
+    .to(&quot;mock:result&quot;);]]></script>
+</div></div><p>Then the <code>MyBean</code> has 2 overloaded methods with the 
names <code>hello</code> and <code>times</code>. So if we want to use the 
method which has 2 parameters we can do as follows in the Camel route:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[from(&quot;direct:start&quot;)
+    .bean(MyBean.class, &quot;hello(String,String)&quot;)
+    .to(&quot;mock:result&quot;); ]]></script>
+</div></div><p>We can also use a <code>*</code> as wildcard so we can just say 
we want to execute the method with 2 parameters we do</p><div class="code panel 
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ from(&quot;direct:start&quot;)
+    .bean(MyBean.class, &quot;hello(*,*)&quot;)
+    .to(&quot;mock:result&quot;);]]></script>
+</div></div><p>By default Camel will match the type name using the simple 
name, e.g. any leading package name will be disregarded. However if you want to 
match using the FQN, then specify the FQN type and Camel will leverage that. So 
if you have a <code>com.foo.MyOrder</code> and you want to match against the 
FQN, and <strong>not</strong> the simple name "MyOrder", then follow this 
example:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[.bean(OrderService.class, 
&quot;doSomething(com.foo.MyOrder)&quot;)]]></script>
+</div></div><p><br clear="none">Camel currently only supports either 
specifying parameter binding or type per parameter in the method name option. 
You <strong>cannot</strong> specify both at the same time, such as</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ doSomething(com.foo.MyOrder ${body}, 
boolean ${header.high})]]></script>
+</div></div><p>This may change in the future.</p>
 <h3 id="Bookcookbook-BeanInjection">Bean Injection</h3>
 
 <p>We support the injection of various resources using @EndpointInject or 
@BeanInject. This can be used to inject</p>


Reply via email to