You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2013/02/08 21:35:05 UTC

svn commit: r1444219 [7/20] - in /servicemix/site/production/docs/4.4.x: ./ activemq/ architecture/ camel/ camel/deployment/ commands/ developers-guide/ images/ jbi/ jbi/components/ karaf/developers-guide/ karaf/users-guide/ nmr/ quickstart/ user/ user...

Modified: servicemix/site/production/docs/4.4.x/jbi/components/servicemix-bean.html
URL: http://svn.apache.org/viewvc/servicemix/site/production/docs/4.4.x/jbi/components/servicemix-bean.html?rev=1444219&r1=1444218&r2=1444219&view=diff
==============================================================================
--- servicemix/site/production/docs/4.4.x/jbi/components/servicemix-bean.html (original)
+++ servicemix/site/production/docs/4.4.x/jbi/components/servicemix-bean.html Fri Feb  8 20:35:02 2013
@@ -118,7 +118,7 @@
             <p>JBI 1.0 support is available in Apache ServiceMix 4 to allow existing users to migrate more easily to this latest version - if you're a new user, you should consider JBI deprecated and not use it for your project.
             Take a look at our <a href="../../users-guide/getting-started/technology-selection.html"</a>technology selection guidelines</a> for more information.</p>
           </div>
-                    <h2 id="servicemixbean">servicemix-bean</h2><h3 id="Overview">Overview</h3><p>The ServiceMix Bean component provides integration with beans (POJOs) with the JBI bus to make it easy to use POJOs to process JBI message exchanges. Like in an Message Driven Bean in J2EE a POJO will receive a message from the NMR and process it in any way it likes. Unlike in a JMS component where the coding is already done the Bean component gives the developer the freedom to create any type of message handling but it must be hand coded all the way.</p><h4 id="Namespaceandxbean.xml">Namespace and xbean.xml</h4><p>The namespace URI for the servicemix-bean JBI component is <tt>http://servicemix.apache.org/bean/1.0</tt>.  This is an example of an <tt>xbean.xml</tt> file with a namespace definition with prefix <tt>bean</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemi
 x.apache.org/bean/1.0&quot;</span><span class="nt">&gt;</span>&#x000A;  <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;test:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span> <span class="na">bean=</span><span class="s">&quot;#listenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;  <span class="nt">&lt;bean</span> <span class="na">id=</span><span class="s">&quot;listenerBean&quot;</span> <span class="na">class=</span><span class="s">&quot;org.apache.servicemix.bean.beans.ListenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;<span class="nt">&lt;/beans&gt;&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="Endpointtypes">Endpoint types</h4><p>The servicemix-bean component only defines one endpoint, called <tt>bean:endpoint</tt>.  It can be used to receive and send message exchanges from/to the NMR.</p><h3 id="Endpointbeanendpoint"><tt>Endpoint bean:endpoi
 nt</tt></h3><p>There are two ways to configure the bean endpoint. The first is using the fully qualified name of the class and the second is by passing to the endpoint a reference to an existing bean.</p><h4 id="UsingaJavaclass">Using a Java class</h4><p>When definining a <tt>bean:endpoint</tt> specifying a Java class name, a new instance of this class will be created for handling a single message exchange.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemix.apache.org/bean/1.0&quot;</span>&#x000A;       <span class="na">xmlns:my=</span><span class="s">&quot;urn:org:servicmix:docs:examples&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;my:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span>&#x000A;                 <span
  class="na">class=</span><span class="s">&quot;org.apache.servicemix.docs.bean.MyHandlerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="Usingaspringbean">Using a spring bean</h4><p>Alternative, a reference to an existing bean can be passed to the bean endpoint.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemix.apache.org/bean/1.0&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;test:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span> <span class="na">bean=</span><span class="s">&quot;#listenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;    <span class="nt">&lt;bean</span> <span class="na">id=</span><span class="s">&quot;li
 stenerBean&quot;</span> <span class="na">class=</span><span class="s">&quot;org.apache.servicemix.bean.beans.ListenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><p><br/><br/><strong>Attention</strong>: The Bean Endpoint schema allows to set a Bean or a Bean Name. The Bean will create a <strong>single</strong> instance of the POJO per endpoint whereas the Bean Name will create an instance per request (message exchange).</p><h4 id="Endpointproperties">Endpoint properties</h4><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Property Name </th><th class="confluenceTh"> Type </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> applicationContext </td><td class="confluenceTd"> <em>org.springframework.context.ApplicationContext</em> </td><td class="confluenceTd"> Set the Spring ApplicationContext where the bean can be found. Defaults to
  the context defined in xbean.xml </td></tr><tr><td class="confluenceTd"> bean </td><td class="confluenceTd"> <em>java.lang.Object</em> </td><td class="confluenceTd"> Set the bean to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> beanClassName </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> Set the bean class name to be used for handling exchanges. A new instance will be created on the fly for every exchange. </td></tr><tr><td class="confluenceTd"> beanInfo </td><td class="confluenceTd"> <em>org.apache.servicemix.bean.support.BeanInfo</em> </td><td class="confluenceTd"> Set a custom bean info object to define the bean to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> beanName </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> Set the name of the bean in the application context to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> be
 anType </td><td class="confluenceTd"> <em>java.lang.Class</em> </td><td class="confluenceTd"> Set the bean class to be used for handling exchanges. A new instance will be created on the fly for every exchange. </td></tr><tr><td class="confluenceTd"> component </td><td class="confluenceTd"> <em><a href="#org.apache.servicemix.bean.BeanComponenttypes">org.apache.servicemix.bean.BeanComponent</a></em> </td><td class="confluenceTd">  </td></tr><tr><td class="confluenceTd"> correlationExpression </td><td class="confluenceTd"> <em>org.apache.servicemix.expression.Expression</em> </td><td class="confluenceTd"> Set a custom expression to use for correlating exchanges into a single request handled by the same bean instance. The default expression uses a correlation ID set on the exchange properties. </td></tr><tr><td class="confluenceTd"> endpoint </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> The name of the endpoint. </td></tr><tr><td class=
 "confluenceTd"> interfaceName </td><td class="confluenceTd"> <em>javax.xml.namespace.QName</em> </td><td class="confluenceTd"> The qualified name of the interface exposed by the endpoint. </td></tr><tr><td class="confluenceTd"> methodInvocationStrategy </td><td class="confluenceTd"> <em><a href="#org.apache.servicemix.bean.support.MethodInvocationStrategytypes">org.apache.servicemix.bean.support.MethodInvocationStrategy</a></em> </td><td class="confluenceTd"> Set a custom invocation strategy to define how the bean is being invoked. The default implementation takes some additional parameter annotations into account. </td></tr><tr><td class="confluenceTd"> service </td><td class="confluenceTd"> <em>javax.xml.namespace.QName</em> </td><td class="confluenceTd"> The qualified name of the service the endpoint exposes. </td></tr><tr><td class="confluenceTd"> serviceEndpoint </td><td class="confluenceTd"> <em>javax.jbi.servicedesc.ServiceEndpoint</em> </td><td class="confluenceTd"> 
  </td></tr></table></div><h3 id="MessageExchangeListener"><tt>MessageExchangeListener</tt></h3><p>The first kind of POJOs you can deploy implement the <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/core/servicemix-core/apidocs/org/apache/servicemix/MessageExchangeListener.html"><tt>MessageExchagneListener</tt></a> interface.  In such a case, <tt>servicemix-bean</tt> acts as a replacement of the lightweight container component.  This level offers the most control on the exchange received and sent.  This is usually used with the injected <tt>DeliveryChannel</tt> to send back the exchanges, or if the POJOs needs to act as a consumer (i.e. creating and sending exchanges to other services).</p><p>These POJOs are low-level POJOs: you need to understand the JBI Api and Message Exchange Patterns to correctly handle incoming exchanges.</p><p>Note that at this point (v 3.1), there is no base class that you can inherit to speed you in this process o
 f implementing a POJO to handle JBI exchanges, but hopefully it will come in the future.</p><h3 id="Examples">Examples</h3><p>This example on the right shows the most simple bean.  When it receives an exchange, it will print it to the console and set the status to DONE before sending the exchange back. This bean can not handle InOut exchanges, as it does not set any response (an exception would be thrown in such a case).</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span
  class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;
         <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Received exchange: &quot;</span> <span class="o">+</span> <span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="n">exchange</span><span class="o">.</span><span class="na">setStatus</span><span class="o">(</span><span class="n">ExchangeStatus</span><span class="o">.</span><span class="na">DONE</span><span class="o">);</span>&#x000A;        <span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;    <span class="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>This example will handle an InOut exchange and will send back the input as the response.<br/>Note that this example would fail if receiving an InOnly exc
 hange, as setting a response on an InOnly exchange is not a legal operation.</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.util.MessageUtil</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span cla
 ss="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;        <span class="k">if</span> <span class="o">(</span><span class="n">exchange</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span> <span class="o">==</span> <span class="n">Excha
 ngeStatus</span><span class="o">.</span><span class="na">ACTIVE</span><span class="o">)</span> <span class="o">{</span>&#x000A;            <span class="n">MessageUtil</span><span class="o">.</span><span class="na">transferInToOut</span><span class="o">(</span><span class="n">exchange</span><span class="o">,</span> <span class="n">exchange</span><span class="o">);</span>&#x000A;            <span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="o">}</span>&#x000A;    <span class="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>This is similar example as the one from above (also works only for InOut exchange) but it shows how you can extract message from an exchange in order to process it and send back.</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.
 apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.util.MessageUtil</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.jaxp.SourceTransformer</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span class="o">;</span>&#x000A;<span class="kn">impor
 t</span> <span class="nn">javax.jbi.messaging.NormalizedMessage</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.xml.transform.Source</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;        <span class="k">if<
 /span> <span class="o">(</span><span class="n">exchange</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span> <span class="o">==</span> <span class="n">ExchangeStatus</span><span class="o">.</span><span class="na">ACTIVE</span><span class="o">)</span> <span class="o">{</span>&#x000A;                        <span class="n">NormalizedMessage</span> <span class="n">message</span> <span class="o">=</span> <span class="n">exchange</span><span class="o">.</span><span class="na">getMessage</span><span class="o">(</span><span class="s">&quot;in&quot;</span><span class="o">);</span>&#x000A;		        <span class="n">Source</span> <span class="n">content</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="na">getContent</span><span class="o">();</span>&#x000A;			<span class="c1">//process content according to your logic</span>&#x000A;			<span class="c1">//e.g. to access the message body as a String use</s
 pan>&#x000A;			<span class="n">String</span> <span class="n">body</span> <span class="o">=</span> <span class="o">(</span><span class="k">new</span> <span class="n">SourceTransformer</span><span class="o">()).</span><span class="na">toString</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>&#x000A;&#x000A;			<span class="n">message</span><span class="o">.</span><span class="na">setContent</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>&#x000A;			<span class="n">exchange</span><span class="o">.</span><span class="na">setMessage</span><span class="o">(</span><span class="n">message</span><span class="o">,</span> <span class="s">&quot;out&quot;</span><span class="o">);</span>&#x000A;			<span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="o">}</span>&#x000A;    <span cla
 ss="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><h3 id="Disclaimer">Disclaimer</h3><p>In versions 3.1 to 3.1.2 the ServiceMix Bean component will not handle asynchronous messages correctly because the final send of the message marked as DONE back to the NMR will be handled as a consumer message and that fails because there is no corresponding provider message. The only workaround is to send the messages synchronously.</p><p>Note: This was resolved in 3.1.3, 3.2.x and later via <a href="https://issues.apache.org/jira/browse/SM-1110">SM-1110</a>.</p><h3 id="MessageExchangedispatching">MessageExchange dispatching</h3><p>If the POJO deployed implements the <tt>org.apache.servicemix.MessageExchangeListener</tt>, every message received for this POJO will be dispatched to the <tt>onMessageExchange</tt> method.</p><p>In other cases, exchanges in a provider role will be dispatched according to the <tt>MethodInvocationStrategy</tt> configured o
 n the endpoint.  The default one try to find the method according to the operation name defined on the exchange.  If there is only a single method acting as an operation, it will always be used.</p><h3 id="Annotations">Annotations</h3><p>The <tt>servicemix-bean</tt> component can accept different kind of POJOs.  These POJOs may be annotated to customize their behavior.  All the following annotations belong to the <tt>org.apache.servicemix.bean</tt> package.</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Annotation </th><th class="confluenceTh"> Target </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Callback.html">Callback</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href=
 "http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Content.html">Content</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Correlation.html">Correlation</a> </td><td class="confluenceTd"> Type </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Endpoint.html">Endpoint</a> </td><td class="confluenceTd"> Type </td><td class="confluenceTd"> This annotation is mandatory if the bean is automatically searched from a list of packages. </td></tr><tr><td class="confluenceTd"> <a hr
 ef="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/ExchangeTarget.html">ExchangeTarget</a> </td><td class="confluenceTd"> Field </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Operation.html">Operation</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Property.html">Property</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/si
 te/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/XPath.html">XPath</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr></table></div><p>In addition, standard annotations can be used:</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Annotation </th><th class="confluenceTh"> Target </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/Resource.html">Resource</a> </td><td class="confluenceTd"> Field </td><td class="confluenceTd"> The Resource annotation marks a resource that is needed by the application.  Currently, this annotation is only supported on fields of type <tt>ComponentContext</tt> and <tt>DeliveryChannel</tt>. The component will inject the specified resource when the POJO is instantiated. </td></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/a
 pi/javax/annotation/PostConstruct.html">PostConstruct</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. </td></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/PreDestroy.html">PreDestroy</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. </td></tr></table></div><p>The following interfaces are part of this API:</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Interface </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/core/servicemix-core/api
 docs/org/apache/servicemix/MessageExchangeListener.html">MessageExchangeListener</a> </td><td class="confluenceTd"> When the POJO implements this interface, <strong>all</strong> exchanges will be dispatched to the <tt>onMessageExchange</tt> method. </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Destination.html">Destination</a> </td><td class="confluenceTd"> This interface can be used to define a property on the bean, annotated with the <tt>@ExchangeTarget</tt> annotation.  This is a very simple API to send exchanges from a POJO.  More complex use cases can use an injected <tt>DeliveryChannel</tt> directly or to create a ServiceMix <a href="Client API.html">client</a>. </td></tr></table></div><h3 id="MoreExamples">More Examples</h3><ul><li><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/
 deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/AnnotatedBean.html">AnnotatedBean</a></li><li><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/AutoDeployedBean.html">AutoDeployedBean</a></li><li><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/ConsumerBean.html">ConsumerBean</a></li><li><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/ListenerBean.html">ListenerBean</a></li><li><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/PlainBean.html">PlainBean</a></li></u
 l>
+                    <h2 id="servicemixbean">servicemix-bean</h2><h3 id="Overview">Overview</h3><p>The ServiceMix Bean component provides integration with beans (POJOs) with the JBI bus to make it easy to use POJOs to process JBI message exchanges. Like in an Message Driven Bean in J2EE a POJO will receive a message from the NMR and process it in any way it likes. Unlike in a JMS component where the coding is already done the Bean component gives the developer the freedom to create any type of message handling but it must be hand coded all the way.</p><h4 id="Namespaceandxbean.xml">Namespace and xbean.xml</h4><p>The namespace URI for the servicemix-bean JBI component is <tt>http://servicemix.apache.org/bean/1.0</tt>.  This is an example of an <tt>xbean.xml</tt> file with a namespace definition with prefix <tt>bean</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemi
 x.apache.org/bean/1.0&quot;</span><span class="nt">&gt;</span>&#x000A;  <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;test:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span> <span class="na">bean=</span><span class="s">&quot;#listenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;  <span class="nt">&lt;bean</span> <span class="na">id=</span><span class="s">&quot;listenerBean&quot;</span> <span class="na">class=</span><span class="s">&quot;org.apache.servicemix.bean.beans.ListenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;<span class="nt">&lt;/beans&gt;&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="Endpointtypes">Endpoint types</h4><p>The servicemix-bean component only defines one endpoint, called <tt>bean:endpoint</tt>.  It can be used to receive and send message exchanges from/to the NMR.</p><h3 id="Endpointbeanendpoint"><tt>Endpoint bean:endpoi
 nt</tt></h3><p>There are two ways to configure the bean endpoint. The first is using the fully qualified name of the class and the second is by passing to the endpoint a reference to an existing bean.</p><h4 id="UsingaJavaclass">Using a Java class</h4><p>When definining a <tt>bean:endpoint</tt> specifying a Java class name, a new instance of this class will be created for handling a single message exchange.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemix.apache.org/bean/1.0&quot;</span>&#x000A;       <span class="na">xmlns:my=</span><span class="s">&quot;urn:org:servicmix:docs:examples&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;my:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span>&#x000A;                 <span
  class="na">class=</span><span class="s">&quot;org.apache.servicemix.docs.bean.MyHandlerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="Usingaspringbean">Using a spring bean</h4><p>Alternative, a reference to an existing bean can be passed to the bean endpoint.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns:bean=</span><span class="s">&quot;http://servicemix.apache.org/bean/1.0&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;bean:endpoint</span> <span class="na">service=</span><span class="s">&quot;test:service&quot;</span> <span class="na">endpoint=</span><span class="s">&quot;endpoint&quot;</span> <span class="na">bean=</span><span class="s">&quot;#listenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;    <span class="nt">&lt;bean</span> <span class="na">id=</span><span class="s">&quot;li
 stenerBean&quot;</span> <span class="na">class=</span><span class="s">&quot;org.apache.servicemix.bean.beans.ListenerBean&quot;</span><span class="nt">/&gt;</span>&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><p><br/><br/><strong>Attention</strong>: The Bean Endpoint schema allows to set a Bean or a Bean Name. The Bean will create a <strong>single</strong> instance of the POJO per endpoint whereas the Bean Name will create an instance per request (message exchange).</p><h4 id="Endpointproperties">Endpoint properties</h4><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Property Name </th><th class="confluenceTh"> Type </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> applicationContext </td><td class="confluenceTd"> <em>org.springframework.context.ApplicationContext</em> </td><td class="confluenceTd"> Set the Spring ApplicationContext where the bean can be found. Defaults to
  the context defined in xbean.xml </td></tr><tr><td class="confluenceTd"> bean </td><td class="confluenceTd"> <em>java.lang.Object</em> </td><td class="confluenceTd"> Set the bean to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> beanClassName </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> Set the bean class name to be used for handling exchanges. A new instance will be created on the fly for every exchange. </td></tr><tr><td class="confluenceTd"> beanInfo </td><td class="confluenceTd"> <em>org.apache.servicemix.bean.support.BeanInfo</em> </td><td class="confluenceTd"> Set a custom bean info object to define the bean to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> beanName </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> Set the name of the bean in the application context to be used for handling exchanges </td></tr><tr><td class="confluenceTd"> be
 anType </td><td class="confluenceTd"> <em>java.lang.Class</em> </td><td class="confluenceTd"> Set the bean class to be used for handling exchanges. A new instance will be created on the fly for every exchange. </td></tr><tr><td class="confluenceTd"> component </td><td class="confluenceTd"> <em><a href="#org.apache.servicemix.bean.BeanComponenttypes">org.apache.servicemix.bean.BeanComponent</a></em> </td><td class="confluenceTd">  </td></tr><tr><td class="confluenceTd"> correlationExpression </td><td class="confluenceTd"> <em>org.apache.servicemix.expression.Expression</em> </td><td class="confluenceTd"> Set a custom expression to use for correlating exchanges into a single request handled by the same bean instance. The default expression uses a correlation ID set on the exchange properties. </td></tr><tr><td class="confluenceTd"> endpoint </td><td class="confluenceTd"> <em>java.lang.String</em> </td><td class="confluenceTd"> The name of the endpoint. </td></tr><tr><td class=
 "confluenceTd"> interfaceName </td><td class="confluenceTd"> <em>javax.xml.namespace.QName</em> </td><td class="confluenceTd"> The qualified name of the interface exposed by the endpoint. </td></tr><tr><td class="confluenceTd"> methodInvocationStrategy </td><td class="confluenceTd"> <em><a href="#org.apache.servicemix.bean.support.MethodInvocationStrategytypes">org.apache.servicemix.bean.support.MethodInvocationStrategy</a></em> </td><td class="confluenceTd"> Set a custom invocation strategy to define how the bean is being invoked. The default implementation takes some additional parameter annotations into account. </td></tr><tr><td class="confluenceTd"> service </td><td class="confluenceTd"> <em>javax.xml.namespace.QName</em> </td><td class="confluenceTd"> The qualified name of the service the endpoint exposes. </td></tr><tr><td class="confluenceTd"> serviceEndpoint </td><td class="confluenceTd"> <em>javax.jbi.servicedesc.ServiceEndpoint</em> </td><td class="confluenceTd"> 
  </td></tr></table></div><h3 id="MessageExchangeListener"><tt>MessageExchangeListener</tt></h3><p>The first kind of POJOs you can deploy implement the <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/core/servicemix-core/apidocs/org/apache/servicemix/MessageExchangeListener.html"><tt>MessageExchagneListener</tt></a> interface.  In such a case, <tt>servicemix-bean</tt> acts as a replacement of the lightweight container component.  This level offers the most control on the exchange received and sent.  This is usually used with the injected <tt>DeliveryChannel</tt> to send back the exchanges, or if the POJOs needs to act as a consumer (i.e. creating and sending exchanges to other services).</p><p>These POJOs are low-level POJOs: you need to understand the JBI Api and Message Exchange Patterns to correctly handle incoming exchanges.</p><p>Note that at this point (v 3.1), there is no base class that you can inherit to speed you in this process o
 f implementing a POJO to handle JBI exchanges, but hopefully it will come in the future.</p><h3 id="Examples">Examples</h3><p>This example on the right shows the most simple bean.  When it receives an exchange, it will print it to the console and set the status to DONE before sending the exchange back. This bean can not handle InOut exchanges, as it does not set any response (an exception would be thrown in such a case).</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span
  class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;
         <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Received exchange: &quot;</span> <span class="o">+</span> <span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="n">exchange</span><span class="o">.</span><span class="na">setStatus</span><span class="o">(</span><span class="n">ExchangeStatus</span><span class="o">.</span><span class="na">DONE</span><span class="o">);</span>&#x000A;        <span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;    <span class="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>This example will handle an InOut exchange and will send back the input as the response.<br/>Note that this example would fail if receiving an InOnly exc
 hange, as setting a response on an InOnly exchange is not a legal operation.</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.util.MessageUtil</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span cla
 ss="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;        <span class="k">if</span> <span class="o">(</span><span class="n">exchange</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span> <span class="o">==</span> <span class="n">Excha
 ngeStatus</span><span class="o">.</span><span class="na">ACTIVE</span><span class="o">)</span> <span class="o">{</span>&#x000A;            <span class="n">MessageUtil</span><span class="o">.</span><span class="na">transferInToOut</span><span class="o">(</span><span class="n">exchange</span><span class="o">,</span> <span class="n">exchange</span><span class="o">);</span>&#x000A;            <span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="o">}</span>&#x000A;    <span class="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>This is similar example as the one from above (also works only for InOut exchange) but it shows how you can extract message from an exchange in order to process it and send back.</p><div class="syntax"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">org.
 apache.servicemix.jbi.listener.MessageExchangeListener</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.util.MessageUtil</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">org.apache.servicemix.jbi.jaxp.SourceTransformer</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">javax.annotation.Resource</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.DeliveryChannel</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.ExchangeStatus</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessageExchange</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.jbi.messaging.MessagingException</span><span class="o">;</span>&#x000A;<span class="kn">impor
 t</span> <span class="nn">javax.jbi.messaging.NormalizedMessage</span><span class="o">;</span>&#x000A;<span class="kn">import</span> <span class="nn">javax.xml.transform.Source</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ListenerBean</span> <span class="kd">implements</span> <span class="n">MessageExchangeListener</span> <span class="o">{</span>&#x000A;&#x000A;    <span class="nd">@Resource</span>&#x000A;    <span class="kd">private</span> <span class="n">DeliveryChannel</span> <span class="n">channel</span><span class="o">;</span>&#x000A;&#x000A;    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onMessageExchange</span><span class="o">(</span><span class="n">MessageExchange</span> <span class="n">exchange</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MessagingException</span> <span class="o">{</span>&#x000A;        <span class="k">if<
 /span> <span class="o">(</span><span class="n">exchange</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span> <span class="o">==</span> <span class="n">ExchangeStatus</span><span class="o">.</span><span class="na">ACTIVE</span><span class="o">)</span> <span class="o">{</span>&#x000A;                        <span class="n">NormalizedMessage</span> <span class="n">message</span> <span class="o">=</span> <span class="n">exchange</span><span class="o">.</span><span class="na">getMessage</span><span class="o">(</span><span class="s">&quot;in&quot;</span><span class="o">);</span>&#x000A;		        <span class="n">Source</span> <span class="n">content</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="na">getContent</span><span class="o">();</span>&#x000A;			<span class="c1">//process content according to your logic</span>&#x000A;			<span class="c1">//e.g. to access the message body as a String use</s
 pan>&#x000A;			<span class="n">String</span> <span class="n">body</span> <span class="o">=</span> <span class="o">(</span><span class="k">new</span> <span class="n">SourceTransformer</span><span class="o">()).</span><span class="na">toString</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>&#x000A;&#x000A;			<span class="n">message</span><span class="o">.</span><span class="na">setContent</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>&#x000A;			<span class="n">exchange</span><span class="o">.</span><span class="na">setMessage</span><span class="o">(</span><span class="n">message</span><span class="o">,</span> <span class="s">&quot;out&quot;</span><span class="o">);</span>&#x000A;			<span class="n">channel</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">exchange</span><span class="o">);</span>&#x000A;        <span class="o">}</span>&#x000A;    <span cla
 ss="o">}</span>&#x000A;&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><h3 id="Disclaimer">Disclaimer</h3><p>In versions 3.1 to 3.1.2 the ServiceMix Bean component will not handle asynchronous messages correctly because the final send of the message marked as DONE back to the NMR will be handled as a consumer message and that fails because there is no corresponding provider message. The only workaround is to send the messages synchronously.</p><p>Note: This was resolved in 3.1.3, 3.2.x and later via <a href="https://issues.apache.org/jira/browse/SM-1110">SM-1110</a>.</p><h3 id="MessageExchangedispatching">MessageExchange dispatching</h3><p>If the POJO deployed implements the <tt>org.apache.servicemix.MessageExchangeListener</tt>, every message received for this POJO will be dispatched to the <tt>onMessageExchange</tt> method.</p><p>In other cases, exchanges in a provider role will be dispatched according to the <tt>MethodInvocationStrategy</tt> configured o
 n the endpoint.  The default one try to find the method according to the operation name defined on the exchange.  If there is only a single method acting as an operation, it will always be used.</p><h3 id="Annotations">Annotations</h3><p>The <tt>servicemix-bean</tt> component can accept different kind of POJOs.  These POJOs may be annotated to customize their behavior.  All the following annotations belong to the <tt>org.apache.servicemix.bean</tt> package.</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Annotation </th><th class="confluenceTh"> Target </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Callback.html">Callback</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href=
 "http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Content.html">Content</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Correlation.html">Correlation</a> </td><td class="confluenceTd"> Type </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Endpoint.html">Endpoint</a> </td><td class="confluenceTd"> Type </td><td class="confluenceTd"> This annotation is mandatory if the bean is automatically searched from a list of packages. </td></tr><tr><td class="confluenceTd"> <a hr
 ef="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/ExchangeTarget.html">ExchangeTarget</a> </td><td class="confluenceTd"> Field </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Operation.html">Operation</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Property.html">Property</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/si
 te/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/XPath.html">XPath</a> </td><td class="confluenceTd"> Parameter </td><td class="confluenceTd"> </td></tr></table></div><p>In addition, standard annotations can be used:</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Annotation </th><th class="confluenceTh"> Target </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/Resource.html">Resource</a> </td><td class="confluenceTd"> Field </td><td class="confluenceTd"> The Resource annotation marks a resource that is needed by the application.  Currently, this annotation is only supported on fields of type <tt>ComponentContext</tt> and <tt>DeliveryChannel</tt>. The component will inject the specified resource when the POJO is instantiated. </td></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/a
 pi/javax/annotation/PostConstruct.html">PostConstruct</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. </td></tr><tr><td class="confluenceTd"> <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/PreDestroy.html">PreDestroy</a> </td><td class="confluenceTd"> Method </td><td class="confluenceTd"> The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. </td></tr></table></div><p>The following interfaces are part of this API:</p><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Interface </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/core/servicemix-core/api
 docs/org/apache/servicemix/MessageExchangeListener.html">MessageExchangeListener</a> </td><td class="confluenceTd"> When the POJO implements this interface, <strong>all</strong> exchanges will be dispatched to the <tt>onMessageExchange</tt> method. </td></tr><tr><td class="confluenceTd"> <a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/apidocs/org/apache/servicemix/bean/Destination.html">Destination</a> </td><td class="confluenceTd"> This interface can be used to define a property on the bean, annotated with the <tt>@ExchangeTarget</tt> annotation.  This is a very simple API to send exchanges from a POJO.  More complex use cases can use an injected <tt>DeliveryChannel</tt> directly or to create a ServiceMix <a href="Client API.html">client</a>. </td></tr></table></div><h3 id="MoreExamples">More Examples</h3><ul><li><p><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/si
 te/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/AnnotatedBean.html">AnnotatedBean</a></p></li><li><p><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/AutoDeployedBean.html">AutoDeployedBean</a></p></li><li><p><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/ConsumerBean.html">ConsumerBean</a></p></li><li><p><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/ListenerBean.html">ListenerBean</a></p></li><li><p><a href="http://incubator.apache.org/servicemix/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/PlainB
 ean.html">PlainBean</a></p></li></ul>
         </div>
       
           </div>

Modified: servicemix/site/production/docs/4.4.x/jbi/components/servicemix-camel.html
URL: http://svn.apache.org/viewvc/servicemix/site/production/docs/4.4.x/jbi/components/servicemix-camel.html?rev=1444219&r1=1444218&r2=1444219&view=diff
==============================================================================
--- servicemix/site/production/docs/4.4.x/jbi/components/servicemix-camel.html (original)
+++ servicemix/site/production/docs/4.4.x/jbi/components/servicemix-camel.html Fri Feb  8 20:35:02 2013
@@ -118,7 +118,7 @@
             <p>JBI 1.0 support is available in Apache ServiceMix 4 to allow existing users to migrate more easily to this latest version - if you're a new user, you should consider JBI deprecated and not use it for your project.
             Take a look at our <a href="../../users-guide/getting-started/technology-selection.html"</a>technology selection guidelines</a> for more information.</p>
           </div>
-                    <h2 id="servicemixcamel">servicemix-camel</h2><h3 id="Overview">Overview</h3><p>The servicemix-camel component provides support for using Apache Camel to provide a full set of Enterprise Integration Patterns and flexible routing and transformation in both Java code or Spring XML to route services on the Normalized Message Router.</p><h4 id="Namespaceandcamelcontext.xml">Namespace and camel-context.xml</h4><p>When creating a servicemix-camel service unit, we reuse the default Camel namespace <tt>http://camel.apache.org/schema/spring</tt>.</p><p>This is an example <tt>camel-context.xml</tt> which uses the Spring DSL to define the Camel routes</p><div class="syntax"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>&#x000A;<span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na"
 >xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;route&gt;</span>&#x000A;      <span class="c">&lt;!-- route defined in the Spring DSL --&gt;</span>&#x000A;    <span class="nt">&lt;/route&gt;</span>&#x000A;  <span class="nt">&lt;/camelCont
 ext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><p>It is also possible to use the Java DSL inside a servicemix-camel service unit by referring to the package that contains the <tt>RouteBuilder</tt> classes.  An example: this <tt>camel-context.xml</tt> file will activate all routes defined by <tt>RouteBuilder</tt>s in the <tt>org.apache.servicemix.example.camel</tt> package.</p><div class="syntax"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>&#x000A;<span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframewo
 rk.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;packages&gt;</span>org.apache.servicemix.examples.camel<span class="nt">&lt;/packages&gt;</span>&#x000A;  <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h3 id="URI">URI</h3><p>Camel routes use URIs to interact with the ESB.  You can use these URIs to expose new endpoints on the ESB as well as to send message exchanges to existing endpoints
 .</p><p>The snippet below automatically exposes a new endpoint to the bus, where the service QName is <tt>MyService</tt> and the endpoint name is <tt>MyEndpoint</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</span>&#x000A;</pre></div>&#x000A;</div><p>When a JBI endpoint appears at the end of a route, as in the example below, that will send </p><div class="syntax"><div class="highlight"><pre><span class="n">to</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</span>&#x000A;</pre></div>&#x000A;</div><p>The messages sent by this producer endpoint are sent to the already deployed JBI endpoint.</p><h4 id="URIformat">URI format</h4><div class="syntax"><div class="highlight"><pre>jbi:service:serviceNamespace[sep]serviceName[?options]&#
 x000A;jbi:endpoint:serviceNamespace[sep]serviceName[sep]endpointName[?options]&#x000A;jbi:name:endpointName[?options]&#x000A;</pre></div>&#x000A;</div><p>The separator that should be used in the endpoint URL is:</p><ul><li><tt>/</tt> (forward slash), if <tt>serviceNamespace</tt> starts with <tt>http://</tt></li><li><tt>:</tt> (colon), if <tt>serviceNamespace</tt> starts with <tt>urn:</tt>.</li></ul><p>You can append query options to the URI in the following format, <tt>?option=value&amp;ption=value&amp;..</tt></p><h5 id="Examples">Examples</h5><h6 id="Usingjbiservice">Using <tt>jbi:service</tt></h6><div class="syntax"><div class="highlight"><pre>jbi:service:http://foo.bar.org/MyService&#x000A;jbi:service:urn:foo:bar:MyService&#x000A;</pre></div>&#x000A;</div><h6 id="Usingjbiendpoint">Using <tt>jbi:endpoint</tt></h6><div class="syntax"><div class="highlight"><pre>jbi:endpoint:urn:foo:bar:MyService:MyEndpoint&#x000A;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&#x000A;<
 /pre></div>&#x000A;</div><h6 id="Usingjbiname">Using <tt>jbi:name</tt></h6><p>When using <tt>jbi:name</tt>, the component uses <tt>http://activemq.apache.org/camel/schema/jbi}endpoint</tt> as the default Service QName.</p><div class="syntax"><div class="highlight"><pre>jbi:name:MyEndpoint&#x000A;</pre></div>&#x000A;</div><h4 id="URIoptions">URI options</h4><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Name </th><th class="confluenceTh"> Default value </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <tt>mep</tt> </td><td class="confluenceTd"> MEP of the Camel Exchange </td><td class="confluenceTd"> Allows users to override the MEP set on the Exchange object. Valid values for this option are <tt>in-only</tt>, <tt>in-out</tt>, <tt>robust-in-out</tt> and <tt>in-optional-out</tt>. </td></tr><tr><td class="confluenceTd"> <tt>operation</tt> </td><td class="confluenceTd"> Value of the <tt>jbi.operation</tt> hea
 der property </td><td class="confluenceTd"> Specifies the JBI operation for the <tt>MessageExchange</tt>.  If no value is supplied, the JBI binding will use the value of the <tt>jbi.operation</tt> header property. </td></tr><tr><td class="confluenceTd"> <tt>serialization</tt> </td><td class="confluenceTd"> <tt>basic</tt> </td><td class="confluenceTd"> Default value (<tt>basic</tt>) will check if headers are serializable by looking at the type, setting this option to <tt>strict</tt> will detect objects that can not be serialized although they implement the <tt>Serializable</tt> interface.  Set to <tt>nocheck</tt> to disable this check altogether, note that this should only be used for in-memory transports like SEDAFlow, otherwise you can expect to get <tt>NotSerializableException</tt> thrown at runtime. </td></tr><tr><td class="confluenceTd"> <tt>convertException</tt> </td><td class="confluenceTd"> <tt>false</tt> </td><td class="confluenceTd"> <tt>false</tt>: send any excepti
 ons thrown from the Camel route back unmodified <br/> <tt>true</tt>: convert all exceptions to a JBI FaultException (can be used to avoid non-serializable exceptions or to implement generic error handling </td></tr></table></div><h5 id="Examples2">Examples</h5><div class="syntax"><div class="highlight"><pre>jbi:service:http://foo.bar.org/MyService?mep=in-out       (override the MEP, use InOut JBI MessageExchanges)&#x000A;jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?mep=in      (override the MEP, use InOnly JBI MessageExchanges)&#x000A;jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?operation={http://www.mycompany.org}AddNumbers&#x000A;(overide the operation for the JBI Exchange to {http://www.mycompany.org}AddNumbers)&#x000A;</pre></div>&#x000A;</div><h3 id="Exampleroutes">Example routes</h3><h4 id="SimpleSpringroute">Simple Spring route</h4><p>This simple Spring route registers a new endpoint on the ESB (service <tt>Router</tt>, endpoint name <tt>orders</tt>).  The message e
 xchange contents will be logged and then forwarded to another JBI service endpoint (service <tt>OrderService</tt>)</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;          <span class="nt">&lt;camelContext</span> <span 
 class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;            <span class="nt">&lt;route&gt;</span>&#x000A;              <span class="nt">&lt;from</span> <span class="na">uri=</span><span class="s">&quot;jbi:endpoint:urn:org:example:Router:orders&quot;</span><span class="nt">/&gt;</span>&#x000A;              <span class="nt">&lt;to</span> <span class="na">uri=</span><span class="s">&quot;log:OrderLogging&quot;</span><span class="nt">/&gt;</span>&#x000A;              <span class="nt">&lt;to</span> <span class="na">uri=</span><span class="s">&quot;jbi:service:http://services.example.org/OrderService&quot;</span> <span class="nt">/&gt;</span>&#x000A;            <span class="nt">&lt;/route&gt;</span>&#x000A;          <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="ThesamerouteusingtheJavaDSL">The same route
  using the Java DSL</h4><p>When we implement the same route in the Java DSL, we first code our <tt>RouteBuilder</tt> implementation</p><div class="syntax"><div class="highlight"><pre><span class="kn">package</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">servicemix</span><span class="o">.</span><span class="na">example</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">org.apache.camel.builder.RouteBuilder</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">JbiRouteBuilder</span> <span class="kd">extends</span> <span class="n">RouteBuilder</span> <span class="o">{</span>&#x000A;&#x000A;  <span class="nd">@Override</span>&#x000A;  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">configure</span><span class="o">()</span> <span class="kd">throws</span> <span
  class="n">Exception</span> <span class="o">{</span>&#x000A;    <span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:urn:org:example:Router:orders&quot;</span><span class="o">)</span>&#x000A;      <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;log:OrderLogging&quot;</span><span class="o">)</span>&#x000A;      <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;jbi:service:http://services.example.org/OrderService&quot;</span><span class="o">);</span>&#x000A;  <span class="o">}</span>&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>In our <tt>camel-context.xml</tt> file, we just refer to the <tt>org.apache.servicemix.example</tt> package that contains our <tt>JbiRouteBuilder</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springf
 ramework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;route&gt;</span>&#x000A;      <span class="nt">&lt;packageScan&gt;</span>&#x000A;        <span class="nt">&lt;package&gt;
 </span>org.apache.servicemix.example<span class="nt">&lt;/package&gt;</span>&#x000A;      <span class="nt">&lt;/packageScan&gt;</span>&#x000A;    <span class="nt">&lt;/route&gt;</span>&#x000A;  <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h3 id="Specialconsiderations">Special considerations</h3><h4 id="Streamhandling">Stream handling</h4><p>If you are using a stream type as the message body, you should be aware that a stream is only capable of being read once. So if you enable <tt>DEBUG</tt> logging, the body is usually logged and thus read. To deal with this, Camel has a <tt>streamCaching</tt> option that can cache the stream, enabling you to read it multiple times.</p><div class="syntax"><div class="highlight"><pre><span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</span>&#x000A;  <
 span class="o">.</span><span class="na">streamCaching</span><span class="o">()</span>&#x000A;  <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;xslt:transform.xsl&quot;</span><span class="o">,</span> <span class="s">&quot;bean:doSomething&quot;</span><span class="o">);</span>&#x000A;</pre></div>&#x000A;</div><p>Camel will cache large input streams (by default, over 64K) in a <tt>temp</tt> file using <tt>CachedOutputStream</tt>. When you close the input stream, the temp file will be deleted.</p>
+                    <h2 id="servicemixcamel">servicemix-camel</h2><h3 id="Overview">Overview</h3><p>The servicemix-camel component provides support for using Apache Camel to provide a full set of Enterprise Integration Patterns and flexible routing and transformation in both Java code or Spring XML to route services on the Normalized Message Router.</p><h4 id="Namespaceandcamelcontext.xml">Namespace and camel-context.xml</h4><p>When creating a servicemix-camel service unit, we reuse the default Camel namespace <tt>http://camel.apache.org/schema/spring</tt>.</p><p>This is an example <tt>camel-context.xml</tt> which uses the Spring DSL to define the Camel routes</p><div class="syntax"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>&#x000A;<span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na"
 >xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;route&gt;</span>&#x000A;      <span class="c">&lt;!-- route defined in the Spring DSL --&gt;</span>&#x000A;    <span class="nt">&lt;/route&gt;</span>&#x000A;  <span class="nt">&lt;/camelCont
 ext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><p>It is also possible to use the Java DSL inside a servicemix-camel service unit by referring to the package that contains the <tt>RouteBuilder</tt> classes.  An example: this <tt>camel-context.xml</tt> file will activate all routes defined by <tt>RouteBuilder</tt>s in the <tt>org.apache.servicemix.example.camel</tt> package.</p><div class="syntax"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>&#x000A;<span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframewo
 rk.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;packages&gt;</span>org.apache.servicemix.examples.camel<span class="nt">&lt;/packages&gt;</span>&#x000A;  <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h3 id="URI">URI</h3><p>Camel routes use URIs to interact with the ESB.  You can use these URIs to expose new endpoints on the ESB as well as to send message exchanges to existing endpoints
 .</p><p>The snippet below automatically exposes a new endpoint to the bus, where the service QName is <tt>MyService</tt> and the endpoint name is <tt>MyEndpoint</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</span>&#x000A;</pre></div>&#x000A;</div><p>When a JBI endpoint appears at the end of a route, as in the example below, that will send </p><div class="syntax"><div class="highlight"><pre><span class="n">to</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</span>&#x000A;</pre></div>&#x000A;</div><p>The messages sent by this producer endpoint are sent to the already deployed JBI endpoint.</p><h4 id="URIformat">URI format</h4><div class="syntax"><div class="highlight"><pre>jbi:service:serviceNamespace[sep]serviceName[?options]&#
 x000A;jbi:endpoint:serviceNamespace[sep]serviceName[sep]endpointName[?options]&#x000A;jbi:name:endpointName[?options]&#x000A;</pre></div>&#x000A;</div><p>The separator that should be used in the endpoint URL is:</p><ul><li><p><tt>/</tt> (forward slash), if <tt>serviceNamespace</tt> starts with <tt>http://</tt></p></li><li><p><tt>:</tt> (colon), if <tt>serviceNamespace</tt> starts with <tt>urn:</tt>.</p></li></ul><p>You can append query options to the URI in the following format, <tt>?option=value&amp;ption=value&amp;..</tt></p><h5 id="Examples">Examples</h5><h6 id="Usingjbiservice">Using <tt>jbi:service</tt></h6><div class="syntax"><div class="highlight"><pre>jbi:service:http://foo.bar.org/MyService&#x000A;jbi:service:urn:foo:bar:MyService&#x000A;</pre></div>&#x000A;</div><h6 id="Usingjbiendpoint">Using <tt>jbi:endpoint</tt></h6><div class="syntax"><div class="highlight"><pre>jbi:endpoint:urn:foo:bar:MyService:MyEndpoint&#x000A;jbi:endpoint:http://foo.bar.org/MyService/MyEnd
 point&#x000A;</pre></div>&#x000A;</div><h6 id="Usingjbiname">Using <tt>jbi:name</tt></h6><p>When using <tt>jbi:name</tt>, the component uses <tt>http://activemq.apache.org/camel/schema/jbi}endpoint</tt> as the default Service QName.</p><div class="syntax"><div class="highlight"><pre>jbi:name:MyEndpoint&#x000A;</pre></div>&#x000A;</div><h4 id="URIoptions">URI options</h4><div class="table-wrap"><table class="confluenceTable"><tr><th class="confluenceTh"> Name </th><th class="confluenceTh"> Default value </th><th class="confluenceTh"> Description </th></tr><tr><td class="confluenceTd"> <tt>mep</tt> </td><td class="confluenceTd"> MEP of the Camel Exchange </td><td class="confluenceTd"> Allows users to override the MEP set on the Exchange object. Valid values for this option are <tt>in-only</tt>, <tt>in-out</tt>, <tt>robust-in-out</tt> and <tt>in-optional-out</tt>. </td></tr><tr><td class="confluenceTd"> <tt>operation</tt> </td><td class="confluenceTd"> Value of the <tt>jbi.oper
 ation</tt> header property </td><td class="confluenceTd"> Specifies the JBI operation for the <tt>MessageExchange</tt>.  If no value is supplied, the JBI binding will use the value of the <tt>jbi.operation</tt> header property. </td></tr><tr><td class="confluenceTd"> <tt>serialization</tt> </td><td class="confluenceTd"> <tt>basic</tt> </td><td class="confluenceTd"> Default value (<tt>basic</tt>) will check if headers are serializable by looking at the type, setting this option to <tt>strict</tt> will detect objects that can not be serialized although they implement the <tt>Serializable</tt> interface.  Set to <tt>nocheck</tt> to disable this check altogether, note that this should only be used for in-memory transports like SEDAFlow, otherwise you can expect to get <tt>NotSerializableException</tt> thrown at runtime. </td></tr><tr><td class="confluenceTd"> <tt>convertException</tt> </td><td class="confluenceTd"> <tt>false</tt> </td><td class="confluenceTd"> <tt>false</tt>: se
 nd any exceptions thrown from the Camel route back unmodified <br/> <tt>true</tt>: convert all exceptions to a JBI FaultException (can be used to avoid non-serializable exceptions or to implement generic error handling </td></tr></table></div><h5 id="Examples2">Examples</h5><div class="syntax"><div class="highlight"><pre>jbi:service:http://foo.bar.org/MyService?mep=in-out       (override the MEP, use InOut JBI MessageExchanges)&#x000A;jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?mep=in      (override the MEP, use InOnly JBI MessageExchanges)&#x000A;jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?operation={http://www.mycompany.org}AddNumbers&#x000A;(overide the operation for the JBI Exchange to {http://www.mycompany.org}AddNumbers)&#x000A;</pre></div>&#x000A;</div><h3 id="Exampleroutes">Example routes</h3><h4 id="SimpleSpringroute">Simple Spring route</h4><p>This simple Spring route registers a new endpoint on the ESB (service <tt>Router</tt>, endpoint name <tt>orders</tt>). 
  The message exchange contents will be logged and then forwarded to another JBI service endpoint (service <tt>OrderService</tt>)</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;          <span class="nt">&lt;camelContext
 </span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;            <span class="nt">&lt;route&gt;</span>&#x000A;              <span class="nt">&lt;from</span> <span class="na">uri=</span><span class="s">&quot;jbi:endpoint:urn:org:example:Router:orders&quot;</span><span class="nt">/&gt;</span>&#x000A;              <span class="nt">&lt;to</span> <span class="na">uri=</span><span class="s">&quot;log:OrderLogging&quot;</span><span class="nt">/&gt;</span>&#x000A;              <span class="nt">&lt;to</span> <span class="na">uri=</span><span class="s">&quot;jbi:service:http://services.example.org/OrderService&quot;</span> <span class="nt">/&gt;</span>&#x000A;            <span class="nt">&lt;/route&gt;</span>&#x000A;          <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h4 id="ThesamerouteusingtheJavaDSL">
 The same route using the Java DSL</h4><p>When we implement the same route in the Java DSL, we first code our <tt>RouteBuilder</tt> implementation</p><div class="syntax"><div class="highlight"><pre><span class="kn">package</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">servicemix</span><span class="o">.</span><span class="na">example</span><span class="o">;</span>&#x000A;&#x000A;<span class="kn">import</span> <span class="nn">org.apache.camel.builder.RouteBuilder</span><span class="o">;</span>&#x000A;&#x000A;<span class="kd">public</span> <span class="kd">class</span> <span class="nc">JbiRouteBuilder</span> <span class="kd">extends</span> <span class="n">RouteBuilder</span> <span class="o">{</span>&#x000A;&#x000A;  <span class="nd">@Override</span>&#x000A;  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">configure</span><span class="o">()</span> <span class="kd">throw
 s</span> <span class="n">Exception</span> <span class="o">{</span>&#x000A;    <span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:urn:org:example:Router:orders&quot;</span><span class="o">)</span>&#x000A;      <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;log:OrderLogging&quot;</span><span class="o">)</span>&#x000A;      <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;jbi:service:http://services.example.org/OrderService&quot;</span><span class="o">);</span>&#x000A;  <span class="o">}</span>&#x000A;<span class="o">}</span>&#x000A;</pre></div>&#x000A;</div><p>In our <tt>camel-context.xml</tt> file, we just refer to the <tt>org.apache.servicemix.example</tt> package that contains our <tt>JbiRouteBuilder</tt>.</p><div class="syntax"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http
 ://www.springframework.org/schema/beans&quot;</span>&#x000A;       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>&#x000A;       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>&#x000A;<span class="s">         http://www.springframework.org/schema/beans</span>&#x000A;<span class="s">           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>&#x000A;<span class="s">         http://camel.apache.org/schema/spring</span>&#x000A;<span class="s">           http://camel.apache.org/schema/spring/camel-spring.xsd&quot;</span><span class="nt">&gt;</span>&#x000A;&#x000A;  <span class="nt">&lt;camelContext</span> <span class="na">xmlns=</span><span class="s">&quot;http://camel.apache.org/schema/spring&quot;</span><span class="nt">&gt;</span>&#x000A;    <span class="nt">&lt;route&gt;</span>&#x000A;      <span class="nt">&lt;packageScan&gt;</span>&#x000A;        <span class="nt">&
 lt;package&gt;</span>org.apache.servicemix.example<span class="nt">&lt;/package&gt;</span>&#x000A;      <span class="nt">&lt;/packageScan&gt;</span>&#x000A;    <span class="nt">&lt;/route&gt;</span>&#x000A;  <span class="nt">&lt;/camelContext&gt;</span>&#x000A;&#x000A;<span class="nt">&lt;/beans&gt;</span>&#x000A;</pre></div>&#x000A;</div><h3 id="Specialconsiderations">Special considerations</h3><h4 id="Streamhandling">Stream handling</h4><p>If you are using a stream type as the message body, you should be aware that a stream is only capable of being read once. So if you enable <tt>DEBUG</tt> logging, the body is usually logged and thus read. To deal with this, Camel has a <tt>streamCaching</tt> option that can cache the stream, enabling you to read it multiple times.</p><div class="syntax"><div class="highlight"><pre><span class="n">from</span><span class="o">(</span><span class="s">&quot;jbi:endpoint:http://foo.bar.org/MyService/MyEndpoint&quot;</span><span class="o">)</sp
 an>&#x000A;  <span class="o">.</span><span class="na">streamCaching</span><span class="o">()</span>&#x000A;  <span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">&quot;xslt:transform.xsl&quot;</span><span class="o">,</span> <span class="s">&quot;bean:doSomething&quot;</span><span class="o">);</span>&#x000A;</pre></div>&#x000A;</div><p>Camel will cache large input streams (by default, over 64K) in a <tt>temp</tt> file using <tt>CachedOutputStream</tt>. When you close the input stream, the temp file will be deleted.</p>
         </div>
       
           </div>