Author: buildbot
Date: Tue May 15 07:21:12 2018
New Revision: 1029901
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/bean-binding.html
websites/production/camel/content/bean.html
websites/production/camel/content/book-component-appendix.html
websites/production/camel/content/book-cookbook.html
websites/production/camel/content/book-in-one-page.html
websites/production/camel/content/cache/main.pageCache
websites/production/camel/content/spring-remoting.html
Modified: websites/production/camel/content/bean-binding.html
==============================================================================
--- websites/production/camel/content/bean-binding.html (original)
+++ websites/production/camel/content/bean-binding.html Tue May 15 07:21:12 2018
@@ -36,6 +36,15 @@
<![endif]-->
+ <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
+ <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
+ <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
+ <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
+
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<title>
Apache Camel: Bean Binding
@@ -78,47 +87,81 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="BeanBinding-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="BeanBinding-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 (se
e 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 val
ue is set on the outbound message body. </p><h3
id="BeanBinding-Asynchronousprocessing">Asynchronous
processing</h3><p>From <strong>Camel 2.18</strong> 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 <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<Void>. To set body to null, just add Exchange me
thod 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<String> 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<Void> doSomethingAsync(String body) {
- return CompletableFuture.allOf(doA(body), doB(body), doC());
-}</plain-text-body><h3 id="BeanBinding-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 sh
ape="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="BeanBinding-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="BeanBinding-Examples">Examples</h4><p>For example, a <a shape="rect"
href="bean.html">Bean</a> such as:</p><plain-text-body>public class Bar {
-
+<div class="wiki-content maincontent"><h2 id="BeanBinding-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="BeanBinding-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 (se
e 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 val
ue is set on the outbound message body. </p><h3
id="BeanBinding-Asynchronousprocessing">Asynchronous
processing</h3><p>From <strong>Camel 2.18</strong> 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 <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<Void>. To set body to null, just add Exchange me
thod 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<String>
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<Void>
doSomethingAsync(String body) {
+ return CompletableFuture.allOf(doA(body), doB(body), doC());
+ }]]></script>
+</div></div><h3 id="BeanBinding-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 of
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="BeanBinding-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="BeanBinding-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="BeanBinding-@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 "Bye World";
+}Â ]]></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("Bye World");
+ }]]></script>
+</div></div><h4 id="BeanBinding-@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="BeanBinding-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="BeanBinding-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></div>
+ // process the in body and return whatever you want
+ return "Bye World";
+ }
+}Â ]]></script>
+</div></div><h3 id="BeanBinding-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 me
thods.</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,
"doSomething")]]></script>
+</div></div><p> </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> </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,
"doSomething(*, true)")Â ]]></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,
"doSomething(${body}, true)")Â ]]></script>
+</div></div><p> </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("bean:orderService?method=doSomething(null,
true)")]]></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,
"doSomethingWithHeaders(${body}, ${headers})")Â ]]></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,
"echo('World', 5)")Â ]]></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,
"doSomething(${body}, ${header.high})")Â ]]></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,
"doSomething(${body.asXml}, ${header.high})")Â ]]></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("bean:orderService?method=doSomething(${body.asXml},
${header.high})")Â ]]></script>
+</div></div><h3
id="BeanBinding-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("direct:start")
+ .bean(MyBean.class, "hello(String)")
+ .to("mock:result");]]></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("direct:start")
+ .bean(MyBean.class, "hello(String,String)")
+ .to("mock:result");Â ]]></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("direct:start")
+ .bean(MyBean.class, "hello(*,*)")
+ .to("mock:result");]]></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,
"doSomething(com.foo.MyOrder)")]]></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></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/bean.html
==============================================================================
--- websites/production/camel/content/bean.html (original)
+++ websites/production/camel/content/bean.html Tue May 15 07:21:12 2018
@@ -36,6 +36,16 @@
<![endif]-->
+ <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
+ <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
+ <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
+ <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
+ <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
+
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<title>
Apache Camel: Bean
@@ -78,27 +88,61 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Bean-BeanComponent">Bean
Component</h2><p>The <strong>bean:</strong> component binds beans to Camel
message exchanges.</p><h3 id="Bean-URIformat">URI
format</h3><plain-text-body>bean:beanID[?options]
-</plain-text-body><p>Where <strong>beanID</strong> can be any string which is
used to look up the bean in the <a shape="rect"
href="registry.html">Registry</a></p><h3
id="Bean-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>method</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The method name from the bean that will be
invoked. If not provided, Camel will try to det
ermine the method itself. In case of ambiguity an exception will be thrown.
See <a shape="rect" href="bean-binding.html">Bean Binding</a> for more details.
From <strong>Camel 2.8</strong> onwards you can specify type qualifiers to
pin-point the exact method to use for overloaded methods. From <strong>Camel
2.9</strong> onwards you can specify parameter values directly in the method
syntax. See more details at <a shape="rect" href="bean-binding.html">Bean
Binding</a>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>cache</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled, Camel will cache the result of
the first <a shape="rect" href="registry.html">Registry</a> look-up. Cache can
be enabled if the bean in the <a shape="rect" href="registry.html">Registry</a>
is defined as a
singleton scope.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>multiParameterArray</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>How to treat the parameters which are
passed from the message body; if it is <code>true</code>, the In message body
should be an array of parameters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>bean.xxx</p></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>null</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.42857;">Camel
2.17:</strong> To configure additional options on the create bean instance
from the class name. For example to configure a foo option on the bean, use
bean.foo=123.</p></td></tr></tbody></table><
/div></rich-text-body><p>You can append query options to the URI in the
following format, <code>?option=value&option=value&...</code></p><h3
id="Bean-Using">Using</h3><p>The object instance that is used to consume
messages must be explicitly registered with the <a shape="rect"
href="registry.html">Registry</a>. For example, if you are using Spring you
must define the bean in the Spring configuration, <code>spring.xml</code>; or
if you don't use Spring, by registering the bean in
JNDI.<plain-text-body>{snippet:id=register|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>Once
an endpoint has been registered, you can build Camel routes that use it to
process
exchanges.<plain-text-body>{snippet:id=route|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>A
<strong>bean:</strong> endpoint cannot be defined as the input to the route;
i.e. you c
annot consume from it, you can only route from some inbound message <a
shape="rect" href="endpoint.html">Endpoint</a> to the bean endpoint as output.
So consider using a <strong>direct:</strong> or <strong>queue:</strong>
endpoint as the input.</p><p>You can use the <code>createProxy()</code> methods
on <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>
to create a proxy that will generate BeanExchanges and send them to any
endpoint:<plain-text-body>{snippet:id=invoke|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>And
the same route using Spring DSL:</p><parameter
ac:name="">xml</parameter><plain-text-body><route>
- <from uri="direct:hello">
- <to uri="bean:bye"/>
-</route>
-</plain-text-body><h3 id="Bean-Beanasendpoint">Bean as endpoint</h3><p>Camel
also supports invoking <a shape="rect" href="bean.html">Bean</a> as an
Endpoint. In the route
below:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml}</plain-text-body>What
happens is that when the exchange is routed to the <code>myBean</code> Camel
will use the <a shape="rect" href="bean-binding.html">Bean Binding</a> to
invoke the bean.<br clear="none"> The source for the bean is just a plain
POJO:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ExampleBean.java}</plain-text-body>Camel
will use <a shape="rect" href="bean-binding.html">Bean Binding</a> to invoke
the <code>sayHello</code> method, by converting the Exchange's In body to the
<code>String</code> type and storing the output of the method on the Exchange
Out body.</p><h3 id=
"Bean-JavaDSLbeansyntax">Java DSL bean syntax</h3><p>Java DSL comes with
syntactic sugar for the <a shape="rect" href="bean.html">Bean</a> component.
Instead of specifying the bean explicitly as the endpoint (i.e.
<code>to("bean:beanName")</code>) you can use the following
syntax:</p><parameter ac:name="">java</parameter><plain-text-body>// Send
message to the bean endpoint
-// and invoke method resolved using Bean Binding.
-from("direct:start").beanRef("beanName");
-
-// Send message to the bean endpoint
-// and invoke given method.
-from("direct:start").beanRef("beanName", "methodName");
-</plain-text-body><p>Instead of passing name of the reference to the bean (so
that Camel will lookup for it in the registry), you can specify the bean
itself:</p><parameter ac:name="">java</parameter><plain-text-body>// Send
message to the given bean instance.
-from("direct:start").bean(new ExampleBean());
-
+<div class="wiki-content maincontent"><h2 id="Bean-BeanComponent">Bean
Component</h2><p>The <strong>bean:</strong> component binds beans to Camel
message exchanges.</p><h3 id="Bean-URIformat">URI
format</h3><p>bean:beanID[?options]</p><p>Where <strong>beanID</strong> can be
any string which is used to look up the bean in the <a shape="rect"
href="registry.html">Registry</a></p><h3
id="Bean-Options">Options</h3><p>confluenceTableSmall</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>method</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p
><code>null</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p>The method name from the bean that will be invoked.
>If not provided, Camel will try to determine the method itself. In case of
>ambiguity an exception will be thrown. See <a shape="rect"
>href="bean-binding.html">Bean Binding</a> for more details. From
><strong>Camel 2.8</strong> onwards you can specify type qualifiers to
>pin-point the exact method to use for overloaded methods. From <strong>Camel
>2.9</strong> onwards you can specify parameter values directly in the method
>syntax. See more details at <a shape="rect" href="bean-binding.html">Bean
>Binding</a>.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>cache</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
>colspan="1" rowspan="1"
>class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p>If enabled, Camel will cache the result
>of the f
irst <a shape="rect" href="registry.html">Registry</a> look-up. Cache can be
enabled if the bean in the <a shape="rect" href="registry.html">Registry</a> is
defined as a singleton scope.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>multiParameterArray</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>How to treat the parameters which are
passed from the message body; if it is <code>true</code>, the In message body
should be an array of parameters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>bean.xxx</p></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>null</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.42857;">Camel
2.17:</strong> To configur
e additional options on the create bean instance from the class name. For
example to configure a foo option on the bean, use
bean.foo=123.</p></td></tr></tbody></table></div><p>You can append query
options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="Bean-Using">Using</h3><p>The object instance that is used to consume
messages must be explicitly registered with the <a shape="rect"
href="registry.html">Registry</a>. For example, if you are using Spring you
must define the bean in the Spring configuration, <code>spring.xml</code>; or
if you don't use Spring, by registering the bean in JNDI.</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[// lets populate the context with the
services we need
+// note that we could just use a spring.xml file to avoid this step
+JndiContext context = new JndiContext();
+context.bind("bye", new SayService("Good Bye!"));
+
+CamelContext camelContext = new DefaultCamelContext(context);]]></script>
+</div></div><p>{snippet:id=register|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</p><p>Once
an endpoint has been registered, you can build Camel routes that use it to
process exchanges.</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[camelContext.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:hello").to("bean:bye");
+ }
+});]]></script>
+</div></div><p>A <strong>bean:</strong> endpoint cannot be defined as the
input to the route; i.e. you cannot consume from it, you can only route from
some inbound message <a shape="rect" href="endpoint.html">Endpoint</a> to the
bean endpoint as output. So consider using a <strong>direct:</strong> or
<strong>queue:</strong> endpoint as the input.</p><p>You can use the
<code>createProxy()</code> methods on <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>
to create a proxy that will generate BeanExchanges and send them to any
endpoint:</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[Endpoint endpoint =
camelContext.getEndpoint("direct:hello");
+ISay proxy = PojoComponent.createProxy(endpoint, ISay.class);
+String rc = proxy.say();
+assertEquals("Good Bye!", rc);]]></script>
+</div></div><p>And the same route using Spring DSL:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<route>
+ <from uri="direct:hello">
+ <to uri="bean:bye"/>
+</route>]]></script>
+</div></div><h3 id="Bean-Beanasendpoint"><br clear="none">Bean as
endpoint</h3><p>Camel also supports invoking <a shape="rect"
href="bean.html">Bean</a> as an Endpoint. In the route below:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="myBean"/>
+ <to uri="mock:results"/>
+ </route>
+</camelContext>
+
+<bean id="myBean"
class="org.apache.camel.spring.bind.ExampleBean"/>]]></script>
+</div></div><p>What happens is that when the exchange is routed to the
<code>myBean</code> Camel will use the <a shape="rect"
href="bean-binding.html">Bean Binding</a> to invoke the bean.<br clear="none">
The source for the bean is just a plain POJO:</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 ExampleBean {
+ public String sayHello(String name) {
+ return "Hello " + name + "!";
+ }
+}]]></script>
+</div></div><p>Camel will use <a shape="rect" href="bean-binding.html">Bean
Binding</a> to invoke the <code>sayHello</code> method, by converting the
Exchange's In body to the <code>String</code> type and storing the output of
the method on the Exchange Out body.</p><h3 id="Bean-JavaDSLbeansyntax">Java
DSL bean syntax</h3><p>Java DSL comes with syntactic sugar for the <a
shape="rect" href="bean.html">Bean</a> component. Instead of specifying the
bean explicitly as the endpoint (i.e. <code>to("bean:beanName")</code>) you can
use the following syntax:</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[//Send message to the bean endpoint
+// and invoke method resolved using Bean Binding.
+from("direct:start").beanRef("beanName");
+Â
+// Send message to the bean endpoint
+// and invoke given method.
+from("direct:start").beanRef("beanName",
"methodName");]]></script>
+</div></div><p><br clear="none">Instead of passing name of the reference to
the bean (so that Camel will lookup for it in the registry), you can specify
the bean itself:</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[// Send message to the given bean instance.
+from("direct:start").bean(new ExampleBean());
// Explicit selection of bean method to be invoked.
-from("direct:start").bean(new ExampleBean(), "methodName");
-
+from("direct:start").bean(new ExampleBean(), "methodName");
// Camel will create the instance of bean and cache it for you.
-from("direct:start").bean(ExampleBean.class);
-</plain-text-body><h3 id="Bean-BeanBinding">Bean Binding</h3><p>How bean
methods to be invoked are chosen (if they are not specified explicitly through
the <strong>method</strong> parameter) and how parameter values are constructed
from the <a shape="rect" href="message.html">Message</a> are all defined by the
<a shape="rect" href="bean-binding.html">Bean Binding</a> mechanism which is
used throughout all of the various <a shape="rect"
href="bean-integration.html">Bean Integration</a> mechanisms in
Camel.</p><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p><ul><li><a
shape="rect" href="class.html">Class</a> component</li><li><a shape="rect"
href="bean-binding.html">Bean Binding</a></li><li><a shape="rect"
href="bean-integration.html">Bean Integration</a></li></ul></div>
+from("direct:start").bean(ExampleBean.class);]]></script>
+</div></div><h3 id="Bean-BeanBinding"><br clear="none">Bean Binding</h3><p>How
bean methods to be invoked are chosen (if they are not specified explicitly
through the <strong>method</strong> parameter) and how parameter values are
constructed from the <a shape="rect" href="message.html">Message</a> are all
defined by the <a shape="rect" href="bean-binding.html">Bean Binding</a>
mechanism which is used throughout all of the various <a shape="rect"
href="bean-integration.html">Bean Integration</a> mechanisms in Camel.</p><p><a
shape="rect" href="endpoint-see-also.html">Endpoint See Also</a></p><ul><li><a
shape="rect" href="class.html">Class</a> component</li><li><a shape="rect"
href="bean-binding.html">Bean Binding</a></li><li><a shape="rect"
href="bean-integration.html">Bean Integration</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/book-component-appendix.html
==============================================================================
--- websites/production/camel/content/book-component-appendix.html (original)
+++ websites/production/camel/content/book-component-appendix.html Tue May 15
07:21:12 2018
@@ -324,27 +324,61 @@ registry.bind("client", client
</dependency>
</plain-text-body><h3 id="BookComponentAppendix-URIformat.2">URI
format</h3><plain-text-body>atom://atomUri[?options]
</plain-text-body><p>Where <strong>atomUri</strong> is the URI to the Atom
feed to poll.</p><h3
id="BookComponentAppendix-Options.1">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>splitEntries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If <code>true</code> Camel will
poll the feed and for the subsequent polls return each entry poll by poll. If
the feed contains 7 entries then Camel will return the first entry on the first
poll, the 2nd entry on the next poll, until no more entries where as Camel will
do a ne
w update on the feed. If <code>false</code> then Camel will poll a fresh feed
on every invocation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>filter</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Is only used by the split entries to filter the entries
to return. Camel will default use the <code>UpdateDateFilter</code> that only
return new entries from the feed. So the client consuming from the feed never
receives the same entry more than once. The filter will return the entries
ordered by the newest last.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>lastUpdate</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Is only used by the filter, as the starting
timestamp for selection never entries (uses the <code>entry.updated</code>
timest
amp). Syntax format is: <code>yyyy-MM-ddTHH:MM:ss</code>. Example:
<code>2007-12-24T17:45:59</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throttleEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> Sets whether
all entries identified in a single feed poll should be delivered immediately.
If <code>true</code>, only one entry is processed per
<code>consumer.delay</code>. Only applicable when <code>splitEntries</code> is
set to <code>true</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>feedHeader</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Sets whether to add the Abdera Feed object
as a header.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sortEntries</code></
p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>If <code>splitEntries</code> is <code>true</code>, this
sets whether to sort those entries by updated date.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.delay</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>500</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Delay in millis between each
poll.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.initialDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Millis before polling
starts.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.userFixedDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" r
owspan="1" class="confluenceTd"><p>If <code>true</code>, use fixed delay
between pools, otherwise fixed rate is used. See <a shape="rect"
class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>username</code></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong> For basic authentication when
polling from a HTTP feed</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>password</code></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong><span> For basic
authentication when polling from a HTTP
feed</span></td></tr></tbody></table></div></rich-text-body><p>You can append
query options to the URI in th
e following format, <code>?option=value&option=value&...</code></p><h3
id="BookComponentAppendix-Exchangedataformat">Exchange data format</h3><p>Camel
will set the In body on the returned <code>Exchange</code> with the entries.
Depending on the <code>splitEntries</code> flag Camel will either return one
<code>Entry</code> or a <code>List<Entry></code>.</p><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Behavior</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>splitEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Only a single entry from the currently
being processed fe
ed is set: <code>exchange.in.body(Entry)</code></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>splitEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The entire list of entries from the feed is
set:
<code>exchange.in.body(List<Entry>)</code></p></td></tr></tbody></table></div></rich-text-body><p>Camel
can set the <code>Feed</code> object on the In header (see
<code>feedHeader</code> option to disable this):</p><h3
id="BookComponentAppendix-MessageHeaders">Message Headers</h3><p>Camel atom
uses these headers.</p><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><
code>CamelAtomFeed</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>When consuming the
<code>org.apache.abdera.model.Feed</code> object is set to this
header.</p></td></tr></tbody></table></div></rich-text-body><h3
id="BookComponentAppendix-Samples">Samples</h3><p>In this sample we poll James
Strachan's
blog.</p><plain-text-body>from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds");
-</plain-text-body><p>In this sample we want to filter only good blogs we like
to a SEDA queue. The sample also shows how to setup Camel standalone, not
running in any Container or using
Spring.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomGoodBlogsTest.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul class="alternate"><li><a shape="rect"
href="rss.html">RSS</a></li></ul> <h2
id="BookComponentAppendix-BeanComponent">Bean Component</h2><p>The
<strong>bean:</strong> component binds beans to Camel message exchanges.</p><h3
id="BookComponentAppendix-URIformat.3">URI
format</h3><plain-text-body>bean:beanID[?options]
-</plain-text-body><p>Where <strong>beanID</strong> can be any string which is
used to look up the bean in the <a shape="rect"
href="registry.html">Registry</a></p><h3
id="BookComponentAppendix-Options.2">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>method</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The method name from the bean that will be
invoked. If not provided, Ca
mel will try to determine the method itself. In case of ambiguity an exception
will be thrown. See <a shape="rect" href="bean-binding.html">Bean Binding</a>
for more details. From <strong>Camel 2.8</strong> onwards you can specify type
qualifiers to pin-point the exact method to use for overloaded methods. From
<strong>Camel 2.9</strong> onwards you can specify parameter values directly in
the method syntax. See more details at <a shape="rect"
href="bean-binding.html">Bean Binding</a>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>cache</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If enabled, Camel will cache
the result of the first <a shape="rect" href="registry.html">Registry</a>
look-up. Cache can be enabled if the bean in the <a shape="rect"
href="registry.html">Registry<
/a> is defined as a singleton scope.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>multiParameterArray</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>How to treat the parameters which are
passed from the message body; if it is <code>true</code>, the In message body
should be an array of parameters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>bean.xxx</p></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>null</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.42857;">Camel
2.17:</strong> To configure additional options on the create bean instance
from the class name. For example to configure a foo option on the bean, use
bean.foo=123.</p></td></t
r></tbody></table></div></rich-text-body><p>You can append query options to
the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="BookComponentAppendix-Using">Using</h3><p>The object instance that is used
to consume messages must be explicitly registered with the <a shape="rect"
href="registry.html">Registry</a>. For example, if you are using Spring you
must define the bean in the Spring configuration, <code>spring.xml</code>; or
if you don't use Spring, by registering the bean in
JNDI.<plain-text-body>{snippet:id=register|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>Once
an endpoint has been registered, you can build Camel routes that use it to
process
exchanges.<plain-text-body>{snippet:id=route|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>A
<strong>bean:</strong> endpoint cannot be defined a
s the input to the route; i.e. you cannot consume from it, you can only route
from some inbound message <a shape="rect" href="endpoint.html">Endpoint</a> to
the bean endpoint as output. So consider using a <strong>direct:</strong> or
<strong>queue:</strong> endpoint as the input.</p><p>You can use the
<code>createProxy()</code> methods on <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>
to create a proxy that will generate BeanExchanges and send them to any
endpoint:<plain-text-body>{snippet:id=invoke|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</plain-text-body>And
the same route using Spring DSL:</p><parameter
ac:name="">xml</parameter><plain-text-body><route>
- <from uri="direct:hello">
- <to uri="bean:bye"/>
-</route>
-</plain-text-body><h3 id="BookComponentAppendix-Beanasendpoint">Bean as
endpoint</h3><p>Camel also supports invoking <a shape="rect"
href="bean.html">Bean</a> as an Endpoint. In the route
below:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml}</plain-text-body>What
happens is that when the exchange is routed to the <code>myBean</code> Camel
will use the <a shape="rect" href="bean-binding.html">Bean Binding</a> to
invoke the bean.<br clear="none"> The source for the bean is just a plain
POJO:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ExampleBean.java}</plain-text-body>Camel
will use <a shape="rect" href="bean-binding.html">Bean Binding</a> to invoke
the <code>sayHello</code> method, by converting the Exchange's In body to the
<code>String</code> type and storing the output of the method on the Exchange
Out
body.</p><h3 id="BookComponentAppendix-JavaDSLbeansyntax">Java DSL bean
syntax</h3><p>Java DSL comes with syntactic sugar for the <a shape="rect"
href="bean.html">Bean</a> component. Instead of specifying the bean explicitly
as the endpoint (i.e. <code>to("bean:beanName")</code>) you can use the
following syntax:</p><parameter ac:name="">java</parameter><plain-text-body>//
Send message to the bean endpoint
-// and invoke method resolved using Bean Binding.
-from("direct:start").beanRef("beanName");
+</plain-text-body><p>In this sample we want to filter only good blogs we like
to a SEDA queue. The sample also shows how to setup Camel standalone, not
running in any Container or using
Spring.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomGoodBlogsTest.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul class="alternate"><li><a shape="rect"
href="rss.html">RSS</a></li></ul> <h2
id="BookComponentAppendix-BeanComponent">Bean Component</h2><p>The
<strong>bean:</strong> component binds beans to Camel message exchanges.</p><h3
id="BookComponentAppendix-URIformat.3">URI
format</h3><p>bean:beanID[?options]</p><p>Where <strong>beanID</strong> can be
any string which is used to look up the bean in the <a shape="rect"
href="registry.html">Registry</a></p><h3
id="BookComponentAppendix-Options.2">Options</h3><p>confluenceTableSmall</
p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>method</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The method name from the bean that will be
invoked. If not provided, Camel will try to determine the method itself. In
case of ambiguity an exception will be thrown. See <a shape="rect"
href="bean-binding.html">Bean Binding</a> for more details. From <strong>Camel
2.8</strong> onwards you can specify type qualifiers to pin-point the exact
method to use for o
verloaded methods. From <strong>Camel 2.9</strong> onwards you can specify
parameter values directly in the method syntax. See more details at <a
shape="rect" href="bean-binding.html">Bean Binding</a>.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>cache</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled, Camel will cache the result of
the first <a shape="rect" href="registry.html">Registry</a> look-up. Cache can
be enabled if the bean in the <a shape="rect" href="registry.html">Registry</a>
is defined as a singleton scope.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>multiParameterArray</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>fal
se</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>How to
treat the parameters which are passed from the message body; if it is
<code>true</code>, the In message body should be an array of
parameters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>bean.xxx</p></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>null</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.42857;">Camel
2.17:</strong> To configure additional options on the create bean instance
from the class name. For example to configure a foo option on the bean, use
bean.foo=123.</p></td></tr></tbody></table></div><p>You can append query
options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="BookComponentAppendix-Using">Using</h3><p>The object instance that is used
to consume messages must be explicitly registered with the
<a shape="rect" href="registry.html">Registry</a>. For example, if you are
using Spring you must define the bean in the Spring configuration,
<code>spring.xml</code>; or if you don't use Spring, by registering the bean in
JNDI.</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[// lets populate the context with the
services we need
+// note that we could just use a spring.xml file to avoid this step
+JndiContext context = new JndiContext();
+context.bind("bye", new SayService("Good Bye!"));
-// Send message to the bean endpoint
-// and invoke given method.
-from("direct:start").beanRef("beanName", "methodName");
-</plain-text-body><p>Instead of passing name of the reference to the bean (so
that Camel will lookup for it in the registry), you can specify the bean
itself:</p><parameter ac:name="">java</parameter><plain-text-body>// Send
message to the given bean instance.
-from("direct:start").bean(new ExampleBean());
+CamelContext camelContext = new DefaultCamelContext(context);]]></script>
+</div></div><p>{snippet:id=register|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}</p><p>Once
an endpoint has been registered, you can build Camel routes that use it to
process exchanges.</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[camelContext.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:hello").to("bean:bye");
+ }
+});]]></script>
+</div></div><p>A <strong>bean:</strong> endpoint cannot be defined as the
input to the route; i.e. you cannot consume from it, you can only route from
some inbound message <a shape="rect" href="endpoint.html">Endpoint</a> to the
bean endpoint as output. So consider using a <strong>direct:</strong> or
<strong>queue:</strong> endpoint as the input.</p><p>You can use the
<code>createProxy()</code> methods on <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>
to create a proxy that will generate BeanExchanges and send them to any
endpoint:</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[Endpoint endpoint =
camelContext.getEndpoint("direct:hello");
+ISay proxy = PojoComponent.createProxy(endpoint, ISay.class);
+String rc = proxy.say();
+assertEquals("Good Bye!", rc);]]></script>
+</div></div><p>And the same route using Spring DSL:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<route>
+ <from uri="direct:hello">
+ <to uri="bean:bye"/>
+</route>]]></script>
+</div></div><h3 id="BookComponentAppendix-Beanasendpoint"><br
clear="none">Bean as endpoint</h3><p>Camel also supports invoking <a
shape="rect" href="bean.html">Bean</a> as an Endpoint. In the route
below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="myBean"/>
+ <to uri="mock:results"/>
+ </route>
+</camelContext>
+<bean id="myBean"
class="org.apache.camel.spring.bind.ExampleBean"/>]]></script>
+</div></div><p>What happens is that when the exchange is routed to the
<code>myBean</code> Camel will use the <a shape="rect"
href="bean-binding.html">Bean Binding</a> to invoke the bean.<br clear="none">
The source for the bean is just a plain POJO:</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 ExampleBean {
+ public String sayHello(String name) {
+ return "Hello " + name + "!";
+ }
+}]]></script>
+</div></div><p>Camel will use <a shape="rect" href="bean-binding.html">Bean
Binding</a> to invoke the <code>sayHello</code> method, by converting the
Exchange's In body to the <code>String</code> type and storing the output of
the method on the Exchange Out body.</p><h3
id="BookComponentAppendix-JavaDSLbeansyntax">Java DSL bean syntax</h3><p>Java
DSL comes with syntactic sugar for the <a shape="rect"
href="bean.html">Bean</a> component. Instead of specifying the bean explicitly
as the endpoint (i.e. <code>to("bean:beanName")</code>) you can use the
following syntax:</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[//Send message to the bean endpoint
+// and invoke method resolved using Bean Binding.
+from("direct:start").beanRef("beanName");
+Â
+// Send message to the bean endpoint
+// and invoke given method.
+from("direct:start").beanRef("beanName",
"methodName");]]></script>
+</div></div><p><br clear="none">Instead of passing name of the reference to
the bean (so that Camel will lookup for it in the registry), you can specify
the bean itself:</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[// Send message to the given bean instance.
+from("direct:start").bean(new ExampleBean());
// Explicit selection of bean method to be invoked.
-from("direct:start").bean(new ExampleBean(), "methodName");
-
+from("direct:start").bean(new ExampleBean(), "methodName");
// Camel will create the instance of bean and cache it for you.
-from("direct:start").bean(ExampleBean.class);
-</plain-text-body><h3 id="BookComponentAppendix-BeanBinding">Bean
Binding</h3><p>How bean methods to be invoked are chosen (if they are not
specified explicitly through the <strong>method</strong> parameter) and how
parameter values are constructed from the <a shape="rect"
href="message.html">Message</a> are all defined by the <a shape="rect"
href="bean-binding.html">Bean Binding</a> mechanism which is used throughout
all of the various <a shape="rect" href="bean-integration.html">Bean
Integration</a> mechanisms in Camel.</p><p><parameter ac:name=""><a
shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul><li><a shape="rect" href="class.html">Class</a>
component</li><li><a shape="rect" href="bean-binding.html">Bean
Binding</a></li><li><a shape="rect" href="bean-integration.html">Bean
Integration</a></li></ul> <div class="error"><span class="error">Unable to
render {include}</span> The included page could not be found.</div> <h2
id="BookComponentAppendix
-BrowseComponent">Browse Component</h2>
+from("direct:start").bean(ExampleBean.class);]]></script>
+</div></div><h3 id="BookComponentAppendix-BeanBinding"><br clear="none">Bean
Binding</h3><p>How bean methods to be invoked are chosen (if they are not
specified explicitly through the <strong>method</strong> parameter) and how
parameter values are constructed from the <a shape="rect"
href="message.html">Message</a> are all defined by the <a shape="rect"
href="bean-binding.html">Bean Binding</a> mechanism which is used throughout
all of the various <a shape="rect" href="bean-integration.html">Bean
Integration</a> mechanisms in Camel.</p><p><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></p><ul><li><a shape="rect"
href="class.html">Class</a> component</li><li><a shape="rect"
href="bean-binding.html">Bean Binding</a></li><li><a shape="rect"
href="bean-integration.html">Bean Integration</a></li></ul> <div
class="error"><span class="error">Unable to render {include}</span> The
included page could not be found.</div> <h2
id="BookComponentAppendix-BrowseComponent">Brows
e Component</h2>
<p>The Browse component provides a simple <a shape="rect"
href="browsableendpoint.html">BrowsableEndpoint</a> which can be useful for
testing, visualisation tools or debugging. The exchanges sent to the endpoint
are all available to be browsed.</p>