camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Book Component Appendix
Date Fri, 05 Feb 2010 07:17:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Book+Component+Appendix">Book Component Appendix</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <div class="chapter" id="chapter-component-appendix"><h1><a name="BookComponentAppendix-ComponentAppendix"></a>Component Appendix</h1>

<p>There now follows the documentation on each Camel component.</p>

<h2><a name="BookComponentAppendix-ActiveMQComponent"></a>ActiveMQ Component</h2>

<p>The ActiveMQ component allows messages to be sent to a <a href="http://java.sun.com/products/jms/" rel="nofollow">JMS</a> Queue or Topic; or messages to be consumed from a JMS Queue or Topic using <a href="http://activemq.apache.org/" title="The most popular and powerful open source message broker" rel="nofollow">Apache ActiveMQ</a>. </p>

<p>This component is based on the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS Component</a> and uses Spring's JMS support for declarative transactions, using Spring's <tt>JmsTemplate</tt> for sending and a <tt>MessageListenerContainer</tt> for consuming. All the options from the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component also applies for this component.</p>

<p>To use this component make sure you have the <tt>activemq.jar</tt> or <tt>activemq-core.jar</tt> on your classpath along with any Camel dependencies such as <tt>camel-core.jar</tt>, <tt>camel-spring.jar</tt> and <tt>camel-jms.jar</tt>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq:[queue:|topic:]destinationName
</pre>
</div></div>

<p>Where <b>destinationName</b> is an ActiveMQ queue or topic name. By default, the <b>destinationName</b> is interpreted as a queue name. For example, to connect to the queue, <tt>FOO.BAR</tt>, use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq:FOO.BAR
</pre>
</div></div>

<p>You can include the optional <tt>queue:</tt> prefix, if you prefer:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq:queue:FOO.BAR
</pre>
</div></div>

<p>To connect to a topic, you must include the <tt>topic:</tt> prefix. For example, to connect to the topic, <tt>Stocks.Prices</tt>, use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq:topic:Stocks.Prices
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<p>See Options on the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component as all these options also apply for this component.</p>

<h3><a name="BookComponentAppendix-ConfiguringtheConnectionFactory"></a>Configuring the Connection Factory</h3>

<p>The following <a href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-camel/src/test/java/org/apache/camel/component/ActiveMQRouteTest.java" rel="nofollow">test case</a> shows how to add an ActiveMQComponent to the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> using the <a href="http://camel.apache.org/maven/camel-activemq/apidocs/org/apache/camel/component/activemq/ActiveMQComponent.html#activeMQComponent(java.lang.String)" rel="nofollow"><tt>activeMQComponent()</tt> method</a> while specifying the <a href="http://activemq.apache.org/configuring-transports.html" rel="nofollow">brokerURL</a> used to connect to ActiveMQ </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">camelContext.addComponent(<span class="code-quote">"activemq"</span>, activeMQComponent(<span class="code-quote">"vm:<span class="code-comment">//localhost?broker.persistent=<span class="code-keyword">false</span>"</span>));</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfiguringtheConnectionFactoryusingSpringXML"></a>Configuring the Connection Factory using Spring XML</h3>

<p>You can configure the ActiveMQ broker URL on the ActiveMQComponent as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;

  <span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>


  <span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span> class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span class="code-quote">"tcp://somehost:61616"</span>/&gt;</span>
  <span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Usingconnectionpooling"></a>Using connection pooling</h3>
<p>When sending to an AcitveMQ broker using Camel its recommended to use a JMS connection pooling such as Jencks. See more here <a href="http://fusesource.com/docs/esb/3.3/jms/ESBJMSConnectFactoryAMQ.html" rel="nofollow">Jencks Connection Pooling</a></p>

<p>You can grab Jencks AMQ pool with maven:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;dependency&gt;</span>
      <span class="code-tag">&lt;groupId&gt;</span>org.jencks<span class="code-tag">&lt;/groupId&gt;</span>
      <span class="code-tag">&lt;artifactId&gt;</span>jencks-amqpool<span class="code-tag">&lt;/artifactId&gt;</span>
      <span class="code-tag">&lt;version&gt;</span>2.1<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>And then setup the <b>activemq</b> Camel component as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag"><span class="code-comment">&lt;!-- use jencks connection pooling so its more effecient to send JMS messages --&gt;</span></span>
    &lt;amqpool:pool id=<span class="code-quote">"jmsConnectionFactory"</span> <span class="code-keyword">xmlns:amqpool</span>=<span class="code-quote">"http://jencks.org/amqpool/2.0"</span>
                  brokerURL=<span class="code-quote">"tcp://localhost:61616"</span>
                  maxConnections=<span class="code-quote">"8"</span>/&gt;

    <span class="code-tag">&lt;bean id=<span class="code-quote">"jmsConfig"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsConfiguration"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span class="code-quote">"jmsConnectionFactory"</span>/&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"transacted"</span> value=<span class="code-quote">"false"</span>/&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"concurrentConsumers"</span> value=<span class="code-quote">"10"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>

    <span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span> class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"configuration"</span> ref=<span class="code-quote">"jmsConfig"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-InvokingMessageListenerPOJOsinaCamelroute"></a>Invoking MessageListener POJOs in a Camel route</h3>

<p>The ActiveMQ component also provides a helper <a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> from a JMS MessageListener to a <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a>. This means that the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component is capable of invoking any JMS MessageListener bean directly inside any route.</p>

<p>So for example you can create a MessageListener in JMS like this....</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class MyListener <span class="code-keyword">implements</span> MessageListener {
   <span class="code-keyword">public</span> void onMessage(Message jmsMessage) {
       <span class="code-comment">// ...
</span>   }
}
</pre>
</div></div>

<p>Then use it in your Camel route as follows</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//foo/bar"</span>).
</span>  bean(MyListener.class);
</pre>
</div></div>

<p>That is, you can reuse any of the Camel <a href="/confluence/display/CAMEL/Components" title="Components">Components</a> and easily integrate them into your JMS <tt>MessageListener</tt> POJO!</p>

<h3><a name="BookComponentAppendix-GettingComponentJAR"></a>Getting Component JAR</h3>

<p>You need these dependencies</p>
<ul class="alternate" type="square">
	<li><tt>camel-jms</tt></li>
	<li><tt>activemq-camel</tt></li>
</ul>


<h4><a name="BookComponentAppendix-cameljms"></a>camel-jms</h4>
<p>You <b>must</b> have the <tt>camel-jms</tt> as dependency as <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> is an extension to the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-jms&lt;/artifactId&gt;
  &lt;version&gt;1.6.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<p>The ActiveMQ Camel component is released with the ActiveMQ project itself.<br/>
For Maven 2 users you simply just need to add the following dependency to your project.</p>

<h4><a name="BookComponentAppendix-ActiveMQ5.2orlater"></a>ActiveMQ 5.2 or later</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
  &lt;artifactId&gt;activemq-camel&lt;/artifactId&gt;
  &lt;version&gt;5.2.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ActiveMQ5.1.0"></a>ActiveMQ 5.1.0</h4>

<p>For 5.1.0 its in the activemq-core library</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
  &lt;artifactId&gt;activemq-core&lt;/artifactId&gt;
  &lt;version&gt;5.1.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<p>Alternatively you can download the component jar directly from the Maven repository:</p>

<ul>
	<li><a href="http://repo2.maven.org/maven2/org/apache/activemq/activemq-camel/5.2.0/activemq-camel-5.2.0.jar" rel="nofollow">activemq-camel-5.2.0.jar</a></li>
	<li><a href="http://repo2.maven.org/maven2/org/apache/activemq/activemq-core/5.1.0/activemq-core-5.1.0.jar" rel="nofollow">activemq-core-5.1.0.jar</a></li>
</ul>


<h4><a name="BookComponentAppendix-ActiveMQ4.x"></a>ActiveMQ 4.x</h4>

<p>For this version you must use the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component instead. Please be careful to use a pooling connection factory as described in the <a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">JmsTemplate Gotchas</a></p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-ActiveMQJournalComponent"></a>ActiveMQ Journal Component</h2>

<p>The ActiveMQ Journal Component allows messages to be stored in a rolling log file and then consumed from that log file.  The journal aggregates and batches up concurrent writes so that to overhead of writing and waiting for the disk sync is relatively constant regardless of how many concurrent writes are being done.  Therefore, this component supports and encourages you to use multiple concurrent producers to the same journal endpoint.</p>

<p>Each journal endpoint uses a different log file and therefore write batching (and the associated performance boost) does not occur between multiple endpoints.</p>

<p>This component only supports 1 active consumer on the endpoint.  After the message is processed by the consumer's processor, the log file is marked and only subsequent messages in the log file will get delivered to consumers.</p>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq.journal:directoryName[?options]
</pre>
</div></div>

<p>So for example, to send to the journal located in the <tt>/tmp/data</tt> directory you would use the following URI:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
activemq.journal:/tmp/data
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>syncConsume</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If set to <tt>true</tt>, when the journal is marked after a message is consumed, wait till the Operating System has verified the mark update is safely stored on disk. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>syncProduce</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If set to <tt>true</tt>, wait till the Operating System has verified the message is safely stored on disk. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-ExpectedExchangeDataTypes"></a>Expected Exchange Data Types</h3>

<p>The consumer of a Journal endpoint generates <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/impl/DefaultExchange.html" rel="nofollow">DefaultExchange</a> objects with the <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Exchange.html#getIn()" rel="nofollow">in message</a> :</p>
<ul>
	<li><a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Message.html#getHeader(java.lang.String)" rel="nofollow">header</a> "journal" : set to the endpoint uri of the journal the message came from</li>
	<li><a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Message.html#getHeader(java.lang.String)" rel="nofollow">header</a> "location" : set to a <a href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/kaha/impl/async/Location.html" rel="nofollow">Location</a> which identifies where the recored was stored on disk</li>
	<li><a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Message.html#getBody()" rel="nofollow">body</a> : set to <a href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/util/ByteSequence.html" rel="nofollow">ByteSequence</a> which contains the byte array data of the stored message</li>
</ul>


<p>The producer to a Journal endpoint expects an <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Exchange.html" rel="nofollow">Exchange</a> with an In message where the body can be converted to a <a href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/util/ByteSequence.html" rel="nofollow">ByteSequence</a> or a byte[].</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-AMQP"></a>AMQP</h2>

<p>The AMQP component supports the <a href="http://www.amqp.org/" rel="nofollow">AMQP protocol</a> via the <a href="http://cwiki.apache.org/qpid/" rel="nofollow">Qpid</a> project.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
amqp:[queue:|topic:]destinationName[?options]
</pre>
</div></div>

<p>You can specify all of the various configuration options of the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component after the destination name.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-AtomComponent"></a>Atom Component</h2>

<p>The <b>atom:</b> component is used for polling atom feeds.</p>

<p>Camel will default poll the feed every 60th seconds.<br/>
<b>Note:</b> The component currently only supports polling (consuming) feeds.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
atom:<span class="code-comment">//atomUri[?options]</span>
</pre>
</div></div>

<p>Where <b>atomUri</b> is the URI to the atom feed to poll. </p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If <tt>true</tt> 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 new update on the feed. If <tt>false</tt> then Camel will poll a fresh feed on every invocation. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  Is only used by the split entries to filter the entries to return. Camel will default use the <tt>UpdateDateFilter</tt> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lastUpdate</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Is only used by the filter, as the starting timestamp for selection never entries (uses the <tt>entry.updated</tt> timestamp). Syntax format is: <tt>yyyy-MM-ddTHH:MM:ss</tt>. Example: <tt>2007-12-24T17:45:59</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>feedHeader</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Sets whether to add the Abdera Feed object as a header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sortEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>splitEntries</tt> is <tt>true</tt>, this sets whether to sort those entries by updated date. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> Delay in millis between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Millis before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, use fixed delay between pools, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Exchangedataformat"></a>Exchange data format</h3>

<p>Camel will set the In body on the returned <tt>Exchange</tt> with the entries. Depending on the <tt>splitEntries</tt> flag Camel will either return one <tt>Entry</tt> or a <tt>List&lt;Entry&gt;</tt>.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Value </th>
<th class='confluenceTh'> Behavior </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  Only a single entry from the currently being processed feed is set: <tt>exchange.in.body(Entry)</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> The entire list of entries from the feed is set: <tt>exchange.in.body(List&lt;Entry&gt;)</tt> </td>
</tr>
</tbody></table>

<p>Camel can set the <tt>Feed</tt> object on the In header (see <tt>feedHeader</tt> option to disable this):</p>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel atom uses these headers.</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.component.atom.feed</tt> </td>
<td class='confluenceTd'> Camel 1.x: When consuming the <tt>org.apache.abdera.model.Feed</tt> object is set to this header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAtomFeed</tt> </td>
<td class='confluenceTd'> Camel 2.0: When consuming the <tt>org.apache.abdera.model.Feed</tt> object is set to this header. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>
<p>In this sample we poll James Strachan's blog.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"atom:<span class="code-comment">//http://macstrac.blogspot.com/feeds/posts/<span class="code-keyword">default</span>"</span>).to(<span class="code-quote">"seda:feeds"</span>);</span>
</pre>
</div></div>

<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.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// This is the CamelContext that is the heart of Camel
</span><span class="code-keyword">private</span> CamelContext context;

<span class="code-comment">// We use a simple Hashtable <span class="code-keyword">for</span> our bean registry. For more advanced usage Spring is supported out-of-the-box
</span><span class="code-keyword">private</span> Hashtable beans = <span class="code-keyword">new</span> Hashtable();

<span class="code-comment">// We initialize Camel
</span><span class="code-keyword">private</span> void setupCamel() <span class="code-keyword">throws</span> Exception {
    <span class="code-comment">// First we register a blog service in our bean registry
</span>    beans.put(<span class="code-quote">"blogService"</span>, <span class="code-keyword">new</span> BlogService());

    <span class="code-comment">// Then we create the camel context with our bean registry
</span>    context = <span class="code-keyword">new</span> DefaultCamelContext(<span class="code-keyword">new</span> CamelInitialContextFactory().getInitialContext(beans));

    <span class="code-comment">// Then we add all the routes we need using the route builder DSL syntax
</span>    context.addRoutes(createRouteBuilder());

    <span class="code-comment">// And <span class="code-keyword">finally</span> we must start Camel to let the magic routing begins
</span>    context.start();
}

/**
 * This is the route builder where we create our routes in the advanced Camel DSL syntax
 */
<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// We pool the atom feeds from the source <span class="code-keyword">for</span> further processing in the seda queue
</span>            <span class="code-comment">// we set the delay to 1 second <span class="code-keyword">for</span> each pool as <span class="code-keyword">this</span> is a unit test also and we can
</span>            <span class="code-comment">// not wait the <span class="code-keyword">default</span> poll interval of 60 seconds.
</span>            <span class="code-comment">// Using splitEntries=<span class="code-keyword">true</span> will during polling only fetch one Atom Entry at any given time.
</span>            <span class="code-comment">// As the feed.atom file contains 7 entries, using <span class="code-keyword">this</span> will require 7 polls to fetch the entire
</span>            <span class="code-comment">// content. When Camel have reach the end of entries it will refresh the atom feed from URI source
</span>            <span class="code-comment">// and restart - but as Camel by <span class="code-keyword">default</span> uses the UpdatedDateFilter it will only deliver <span class="code-keyword">new</span>
</span>            <span class="code-comment">// blog entries to <span class="code-quote">"seda:feeds"</span>. So only when James Straham updates his blog with a <span class="code-keyword">new</span> entry
</span>            <span class="code-comment">// Camel will create an exchange <span class="code-keyword">for</span> the seda:feeds.
</span>            from(<span class="code-quote">"atom:file:src/test/data/feed.atom?splitEntries=<span class="code-keyword">true</span>&amp;consumer.delay=1000"</span>).to(<span class="code-quote">"seda:feeds"</span>);

            <span class="code-comment">// From the feeds we filter each blot entry by using our blog service class
</span>            from(<span class="code-quote">"seda:feeds"</span>).filter().method(<span class="code-quote">"blogService"</span>, <span class="code-quote">"isGoodBlog"</span>).to(<span class="code-quote">"seda:goodBlogs"</span>);

            <span class="code-comment">// And the good blogs is moved to a mock queue as <span class="code-keyword">this</span> sample is also used <span class="code-keyword">for</span> unit testing
</span>            <span class="code-comment">// <span class="code-keyword">this</span> is one of the strengths in Camel that you can also use the mock endpoint <span class="code-keyword">for</span> your
</span>            <span class="code-comment">// unit tests
</span>            from(<span class="code-quote">"seda:goodBlogs"</span>).to(<span class="code-quote">"mock:result"</span>);
        }
    };
}

/**
 * This is the actual junit test method that does the assertion that our routes is working
 * as expected
 */
@Test
<span class="code-keyword">public</span> void testFiltering() <span class="code-keyword">throws</span> Exception {
    <span class="code-comment">// Get the mock endpoint
</span>    MockEndpoint mock = context.getEndpoint(<span class="code-quote">"mock:result"</span>, MockEndpoint.class);

    <span class="code-comment">// There should be two good blog entries from the feed
</span>    mock.expectedMessageCount(2);

    <span class="code-comment">// Asserts that the above expectations is <span class="code-keyword">true</span>, will <span class="code-keyword">throw</span> assertions exception <span class="code-keyword">if</span> it failed
</span>    <span class="code-comment">// Camel will <span class="code-keyword">default</span> wait max 20 seconds <span class="code-keyword">for</span> the assertions to be <span class="code-keyword">true</span>, <span class="code-keyword">if</span> the conditions
</span>    <span class="code-comment">// is <span class="code-keyword">true</span> sooner Camel will <span class="code-keyword">continue</span>
</span>    mock.assertIsSatisfied();
}

/**
 * Services <span class="code-keyword">for</span> blogs
 */
<span class="code-keyword">public</span> class BlogService {

    /**
     * Tests the blogs <span class="code-keyword">if</span> its a good blog entry or not
     */
    <span class="code-keyword">public</span> <span class="code-object">boolean</span> isGoodBlog(Exchange exchange) {
        Entry entry = exchange.getIn().getBody(Entry.class);
        <span class="code-object">String</span> title = entry.getTitle();            

        <span class="code-comment">// We like blogs about Camel
</span>        <span class="code-object">boolean</span> good = title.toLowerCase().contains(<span class="code-quote">"camel"</span>);
        <span class="code-keyword">return</span> good;
    }

}

</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-BeanComponent"></a>Bean Component</h2>

<p>The <b>bean:</b> component binds beans to Camel message exchanges.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
bean:beanID[?options]
</pre>
</div></div>
<p>Where <b>beanID</b> can be any string which is used to look up the bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>method</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The method name that bean will be invoked. If not provided, Camel will try to pick the method itself. In case of ambiguity an exception is thrown. See <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cache</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enabled, Camel will cache the result of the first <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> look-up. Cache can be enabled if the bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> is defined as a singleton scope. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiParameterArray</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5:</b> How to treat the parameters which are passed from the message body; if it is <tt>true</tt>, the In message body should be an array of parameters. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Using"></a>Using</h3>

<p>The object instance that is used to consume messages must be explicitly registered with the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. For example, if you are using Spring you must define the bean in the Spring configuration, <tt>spring.xml</tt>; or if you don't use Spring, put the bean in JNDI.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// lets populate the context with the services we need
</span><span class="code-comment">// note that we could just use a spring.xml file to avoid <span class="code-keyword">this</span> step
</span>JndiContext context = <span class="code-keyword">new</span> JndiContext();
context.bind(<span class="code-quote">"bye"</span>, <span class="code-keyword">new</span> SayService(<span class="code-quote">"Good Bye!"</span>));

CamelContext camelContext = <span class="code-keyword">new</span> DefaultCamelContext(context);
</pre>
</div></div>

<p>Once an endpoint has been registered, you can build Camel routes that use it to process exchanges.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// lets add simple route
</span>camelContext.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
        from(<span class="code-quote">"direct:hello"</span>).to(<span class="code-quote">"bean:bye"</span>);
    }
});
</pre>
</div></div>

<p>A <b>bean:</b> 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 href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> to the bean endpoint as output.  So consider using a <b>direct:</b> or <b>queue:</b> endpoint as the input.  </p>

<p>You can use the <tt>createProxy()</tt> methods on <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html" rel="nofollow">ProxyHelper</a> to create a proxy that will generate BeanExchanges and send them to any endpoint:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Endpoint endpoint = camelContext.getEndpoint(<span class="code-quote">"direct:hello"</span>);
ISay proxy = ProxyHelper.createProxy(endpoint, ISay.class);
<span class="code-object">String</span> rc = proxy.say();
assertEquals(<span class="code-quote">"Good Bye!"</span>, rc);
</pre>
</div></div>

<p>And the same route using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;route&gt;</span>
       <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:hello"</span>&gt;</span>
       <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:bye"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Beanasendpoint"></a>Bean as endpoint</h3>
<p>Camel also supports invoking <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> as an Endpoint. In the route below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"myBean"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:results"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myBean"</span> class=<span class="code-quote">"org.apache.camel.spring.bind.ExampleBean"</span>/&gt;</span>
</pre>
</div></div>
<p>What happens is that when the exchange is routed to the <tt>myBean</tt> Camel will use the <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> to invoke the bean.<br/>
The source for the bean is just a plain POJO:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class ExampleBean {

    <span class="code-keyword">public</span> <span class="code-object">String</span> sayHello(<span class="code-object">String</span> name) {
        <span class="code-keyword">return</span> <span class="code-quote">"Hello "</span> + name + <span class="code-quote">"!"</span>;
    }
}
</pre>
</div></div>
<p>Camel will use <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> to invoke the <tt>sayHello</tt> method, by converting the Exchange's In body to the <tt>String</tt> type and storing the output of the method on the Exchange Out body.</p>

<h3><a name="BookComponentAppendix-BeanBinding"></a>Bean Binding</h3>

<p>How bean methods to be invoked are chosen (if they are not specified explicitly through the <b>method</b> parameter) and how parameter values are constructed from the <a href="/confluence/display/CAMEL/Message" title="Message">Message</a> are all defined by the <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> mechanism which is used throughout all of the various <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a> mechanisms in Camel.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a></li>
	<li><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a></li>
</ul>


<h2><a name="BookComponentAppendix-BrowseComponent"></a>Browse Component</h2>

<p><b>Available as of Camel 2.0</b></p>

<p>The Browse component provides a simple <a href="/confluence/display/CAMEL/BrowsableEndpoint" title="BrowsableEndpoint">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>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
browse:someName
</pre>
</div></div>

<p>Where <b>someName</b> can be any string to uniquely identify the endpoint.</p>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In the route below, we insert a <tt>browse:</tt> component to be able to browse the Exchanges that are passing through:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"activemq:order.in"</span>).to(<span class="code-quote">"browse:orderReceived"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<p>We can now inspect the received exchanges from within the Java code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">private</span> CamelContext context;

    <span class="code-keyword">public</span> void inspectRecievedOrders() {
        BrowsableEndpoint browse = context.getEndpoint(<span class="code-quote">"browse:orderReceived"</span>, BrowsableEndpoint.class);
        List&lt;Exchange&gt; exchanges = browse.getExchanges();
        ...
        <span class="code-comment">// then we can inspect the list of received exchanges from Java
</span>        <span class="code-keyword">for</span> (Exchange exchange : exchanges) {
            <span class="code-object">String</span> payload = exchange.getIn().getBody();
            ...
        }
   }
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-CacheComponent"></a>Cache Component</h2>

<p><b>Available as of Camel 2.1</b></p>

<p>The <b>cache</b> component enables you to perform caching operations using EHCache as the Cache Implementation. The cache itself is created on demand or if a cache of that name already exists then it is simply utilized with its original settings.</p>

<p>This component supports producer and event based consumer endpoints.</p>

<p>The Cache consumer is an event based consumer and can be used to listen and respond to specific cache activities. If you need to perform selections from a pre-existing cache, used the processors defined for the cache component.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cache:<span class="code-comment">//cacheName[?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxElementsInMemory</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> The numer of elements that may be stored in the defined cache </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>memoryStoreEvictionPolicy</tt> </td>
<td class='confluenceTd'> <tt>MemoryStoreEvictionPolicy.LFU</tt> </td>
<td class='confluenceTd'> The number of elements that may be stored in the defined cache. Options include
<ul class="alternate" type="square">
	<li>MemoryStoreEvictionPolicy.LFU - Least frequently used</li>
	<li>MemoryStoreEvictionPolicy.LRU - Least recently used</li>
	<li>MemoryStoreEvictionPolicy.FIFO - first in first out, the oldest element by creation time</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>overflowToDisk</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether cache may overflow to disk</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eternal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Sets whether elements are eternal. If eternal, timeouts are ignored and the<br/>
element is never expired. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToLiveSeconds</tt> </td>
<td class='confluenceTd'> <tt>300</tt> </td>
<td class='confluenceTd'> The maximum time between creation time and when an element expires.<br/>
Is only used if the element is not eternal </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToIdleSeconds</tt> </td>
<td class='confluenceTd'> <tt>300</tt> </td>
<td class='confluenceTd'> The maximum amount of time between accesses before an element expires </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>diskPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the disk store persists between restarts of the Virtual Machine.<br/>
The default value is false. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>diskExpiryThreadIntervalSeconds</tt> </td>
<td class='confluenceTd'> <tt>120</tt> </td>
<td class='confluenceTd'> The number of seconds between runs of the disk expiry thread. The default value<br/>
is 120 seconds </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Sending%2FReceivingMessagesto%2Ffromthecache"></a>Sending/Receiving Messages to/from the cache</h3>

<h4><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CACHE_OPERATION</tt> </td>
<td class='confluenceTd'> The operation to be performed on the cache. The valid options are
<ul class="alternate" type="square">
	<li>ADD</li>
	<li>UPDATE</li>
	<li>DELETE</li>
	<li>DELETEALL</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CACHE_KEY</tt> </td>
<td class='confluenceTd'> The cache key used to store the Message in the cache. The cache key is optional if the CACHE_OPERATION is DELETEALL </td>
</tr>
</tbody></table>
<h4><a name="BookComponentAppendix-CacheProducer"></a>Cache Producer </h4>
<p>Sending data to the cache involves the ability to direct payloads in exchanges to be stored in a pre-existing or created-on-   demand cache. The mechanics of doing this involve</p>
<ul class="alternate" type="square">
	<li>setting the Message Exchange Headers shown above.</li>
	<li>ensuring that the Message Exchange Body contains the message directed to the cache</li>
</ul>


<h4><a name="BookComponentAppendix-CacheConsumer"></a>Cache Consumer </h4>
<p>Receiving data from the cache involves the ability of the CacheConsumer to listen on a pre-existing or created-on-demand Cache using an event Listener and receive automatic notifications when any cache activity take place (i.e ADD/UPDATE/DELETE/DELETEALL). Upon such an activity taking place</p>
<ul class="alternate" type="square">
	<li>an exchange containing Message Exchange Headers and a Message Exchange Body containing the just added/updated payload is placed and sent.</li>
	<li>in case of a DELETEALL operation, the Message Exchange Header CACHE_KEY and the Message Exchange Body are not populated.</li>
</ul>


<h4><a name="BookComponentAppendix-CacheProcessors"></a>Cache Processors </h4>
<p>There are a set of nice processors with the ability to perform cache lookups and selectively replace payload content at the</p>
<ul class="alternate" type="square">
	<li>body</li>
	<li>token</li>
	<li>xpath level</li>
</ul>


<h3><a name="BookComponentAppendix-CacheUsageSamples"></a>Cache Usage Samples</h3>

<h4><a name="BookComponentAppendix-Example1%3AConfiguringthecache"></a>Example 1: Configuring the cache</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"cache:<span class="code-comment">//MyApplicationCache"</span> +
</span>          <span class="code-quote">"?maxElementsInMemory=1000"</span> + 
          <span class="code-quote">"&amp;memoryStoreEvictionPolicy="</span> +
              <span class="code-quote">"MemoryStoreEvictionPolicy.LFU"</span> +
          <span class="code-quote">"&amp;overflowToDisk=<span class="code-keyword">true</span>"</span> +
          <span class="code-quote">"&amp;eternal=<span class="code-keyword">true</span>"</span> +
          <span class="code-quote">"&amp;timeToLiveSeconds=300"</span> + 
          <span class="code-quote">"&amp;timeToIdleSeconds=<span class="code-keyword">true</span>"</span> +
          <span class="code-quote">"&amp;diskPersistent=<span class="code-keyword">true</span>"</span> +
          <span class="code-quote">"&amp;diskExpiryThreadIntervalSeconds=300"</span>)
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3AAddingkeystothecache"></a>Example 2: Adding keys to the cache </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
     from(<span class="code-quote">"direct:start"</span>)
     .setHeader(<span class="code-quote">"CACHE_OPERATION"</span>, constant(<span class="code-quote">"ADD"</span>))
     .setHeader(<span class="code-quote">"CACHE_KEY"</span>, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>))
     .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>   }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3AUpdatingexistingkeysinacache"></a>Example 2: Updating existing keys in a cache </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
     from(<span class="code-quote">"direct:start"</span>)
     .setHeader(<span class="code-quote">"CACHE_OPERATION"</span>, constant(<span class="code-quote">"UPDATE"</span>))
     .setHeader(<span class="code-quote">"CACHE_KEY"</span>, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>))
     .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>   }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example3%3ADeletingexistingkeysinacache"></a>Example 3: Deleting existing keys in a cache </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
     from(<span class="code-quote">"direct:start"</span>)
     .setHeader(<span class="code-quote">"CACHE_OPERATION"</span>, constant(<span class="code-quote">"DELETE"</span>))
     .setHeader(<span class="code-quote">"CACHE_KEY"</span>, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>))
     .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>   }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example4%3ADeletingallexistingkeysinacache"></a>Example 4: Deleting all existing keys in a cache </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
     from(<span class="code-quote">"direct:start"</span>)
     .setHeader(<span class="code-quote">"CACHE_OPERATION"</span>, constant(<span class="code-quote">"DELETEALL"</span>))
     .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>);
</span>    }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example5%3ANotifyinganychangesregisteringinaCachetoProcessorsandotherProducers"></a>Example 5: Notifying any changes registering in a Cache to Processors and other Producers</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
     from(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>     .process(<span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) 
               <span class="code-keyword">throws</span> Exception {
           <span class="code-object">String</span> operation = (<span class="code-object">String</span>) exchange.getIn().getHeader(<span class="code-quote">"CACHE_OPERATION"</span>);
           <span class="code-object">String</span> key = (<span class="code-object">String</span>) exchange.getIn().getHeader(<span class="code-quote">"CACHE_KEY"</span>);
           <span class="code-object">Object</span> body = exchange.getIn().getBody();
           <span class="code-comment">// Do something
</span>        } 
     })
   } 
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example6%3AUsingProcessorstoselectivelyreplacepayloadwithcachevalues"></a>Example 6: Using Processors to selectively replace payload with cache values</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
   <span class="code-keyword">public</span> void configure() {
     <span class="code-comment">//Message Body Replacer
</span>     from(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>     .filter(header(<span class="code-quote">"CACHE_KEY"</span>).isEqualTo(<span class="code-quote">"greeting"</span>))
     .process(<span class="code-keyword">new</span> CacheBasedMessageBodyReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"farewell"</span>))
</span>     .to(<span class="code-quote">"direct:next"</span>);  

    <span class="code-comment">//Message Token replacer
</span>    from(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>    .filter(header(<span class="code-quote">"CACHE_KEY"</span>).isEqualTo(<span class="code-quote">"quote"</span>))
    .process(<span class="code-keyword">new</span> CacheBasedTokenReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"novel"</span>,<span class="code-quote">"#novel#"</span>))
</span>    .process(<span class="code-keyword">new</span> CacheBasedTokenReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"author"</span>,<span class="code-quote">"#author#"</span>))
</span>    .process(<span class="code-keyword">new</span> CacheBasedTokenReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"number"</span>,<span class="code-quote">"#number#"</span>))
</span>    .to(<span class="code-quote">"direct:next"</span>);

    <span class="code-comment">//Message XPath replacer
</span>    from(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>).
</span>    .filter(header(<span class="code-quote">"CACHE_KEY"</span>).isEqualTo(<span class="code-quote">"XML_FRAGMENT"</span>))
    .process(<span class="code-keyword">new</span> CacheBasedXPathReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"book1"</span>,<span class="code-quote">"/books/book1"</span>))
</span>    .process (<span class="code-keyword">new</span> CacheBasedXPathReplacer(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>,<span class="code-quote">"book2"</span>,<span class="code-quote">"/books/book2"</span>))
</span>    .to(<span class="code-quote">"direct:next"</span>);
   }
};
</pre>
</div></div>
<h2><a name="BookComponentAppendix-CometdComponent"></a>Cometd Component</h2>

<p>The <b>cometd:</b> component is a transport for working with the <a href="http://www.mortbay.org/jetty" rel="nofollow">jetty</a> implementation of the <a href="http://docs.codehaus.org/display/JETTY/Cometd+%28aka+Bayeux%29" rel="nofollow">cometd/bayeux protocol</a>.<br/>
Using this component in combination with the dojo toolkit library it's possible to push Camel messages directly into the browser using an AJAX based mechanism.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cometd:<span class="code-comment">//host:port/channelName[?options]</span>
</pre>
</div></div>

<p>The <b>channelName</b> represents a topic that can be subscribed to by the Camel endpoints.</p>

<h3><a name="BookComponentAppendix-Examples"></a>Examples</h3>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>cometd://localhost:8080/service/mychannel
cometds://localhost:8443/service/mychannel
</pre>
</div></div>
<p>where <tt>cometds:</tt> represents an SSL configured endpoint.</p>

<p>See this <a href="http://www.davidgreco.it/MySite/Blog/Entries/2008/12/4_Camel,_Cometd_and_Bayeux_what_a_nice_combination.html" rel="nofollow">blog entry</a> by David Greco who contributed this component to Apache Camel, for a full sample. </p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name         </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>resourceBase</tt>  </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The root directory for the web resources</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>240000</tt> </td>
<td class='confluenceTd'> The server side poll timeout in milliseconds. This is how long the server will hold a reconnect request before responding. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>interval</tt> </td>
<td class='confluenceTd'>      <tt>0</tt>          </td>
<td class='confluenceTd'> The client side poll timeout in milliseconds. How long a client will wait between reconnects</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxInterval</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> The max client side poll timeout in milliseconds. A client will be removed if a connection is not received in this time. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiFrameInterval</tt>   </td>
<td class='confluenceTd'> <tt>1500</tt> </td>
<td class='confluenceTd'> The client side poll timeout, if multiple connections are detected from the same browser. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jsonCommented</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  If <tt>true</tt>, the server will accept JSON wrapped in a comment and will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>logLevel</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <tt>0</tt>=none, <tt>1</tt>=info, <tt>2</tt>=debug. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-CXFComponent"></a>CXF Component</h2>

<p>The <b>cxf:</b> component provides integration with <a href="http://incubator.apache.org/cxf/" rel="nofollow">Apache CXF</a> for connecting to JAX-WS services hosted in CXF.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt> for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-cxf&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>CXF dependencies</b><br /><p>If you want to learn about CXF dependencies you can checkout the <tt><a href="http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/lib/WHICH_JARS" rel="nofollow">WHICH-JARS</a></tt> text file.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxf:bean:cxfEndpoint[?options]
</pre>
</div></div>
<p>Where <b>cxfEndpoint</b> represents a bean ID that references a bean in the Spring bean registry. With this URI format, most of the endpoint details are specified in the bean definition.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxf:<span class="code-comment">//someAddress[?options]</span>
</pre>
</div></div>
<p>Where <b>someAddress</b> specifies the CXF endpoint's address. With this URI format, most of the endpoint details are specified using options.</p>

<p>For either style above, you can append options to the URI as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxf:bean:cxfEndpoint?wsdlURL=wsdl/hello_world.wsdl&amp;dataFormat=PAYLOAD
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>wsdlURL</tt> </td>
<td class='confluenceTd'> The location of the WSDL. </td>
<td class='confluenceTd'> <a href="file://local/wsdl/hello.wsdl" rel="nofollow">file://local/wsdl/hello.wsdl</a> or <tt>wsdl/hello.wsdl</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> WSDL is obtained from endpoint address by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClass</tt> </td>
<td class='confluenceTd'> The name of the SEI (Service Endpoint Interface) class.  This class can have, but does not require, JSR181 annotations.&nbsp; <br clear="all" />
<b>Since 2.0,</b> this option is only required by POJO mode.&nbsp;&nbsp; If the wsdlURL option is provided, serviceClass is not required for PAYLOAD and MESSAGE mode.&nbsp; When wsdlURL option is used without serviceClass, the serviceName and portName (endpointName for Spring configuration) options <b>MUST</b> be provided. <br clear="all" />
<br clear="all" />
<b>Since 2.0</b>, it is possible to use <tt>&#35;</tt> notation to reference a <tt>serviceClass</tt> object instance from the registry.&nbsp; E.g. <tt>serviceClass=#beanName</tt>. <br clear="all" />
<br clear="all" />
<b>Please be advised that the referenced object cannot be a Proxy (Spring AOP Proxy is OK)</b> as it relies on <tt>Object.getClass().getName()</tt> method for non Spring AOP Proxy. <br clear="all" /> </td>
<td class='confluenceTd'> <tt>org.apache.camel.Hello</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClassInstance</tt> </td>
<td class='confluenceTd'> <b>In 1.6 or later (will be deprecated in 2.0)</b>, <tt>serviceClassInstance</tt> works like <tt>serviceClass=#beanName</tt>, which looks up a <tt>serviceObject</tt> instance from the registry. </td>
<td class='confluenceTd'> <tt>serviceClassInstance=beanName</tt> </td>
<td class='confluenceTd'> No (use either <tt>serviceClass</tt> or <tt>serviceClassInstance</tt>) </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceName</tt> </td>
<td class='confluenceTd'> The service name this service is implementing, it maps to the <tt>wsdl:service@name</tt>. </td>
<td class='confluenceTd'> {http:­//org.apache.camel}ServiceName </td>
<td class='confluenceTd'> Only if more than one <tt>serviceName</tt> in WSDL present, and it is required for camel-cxf consumer since camel 2.2 </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>portName</tt> </td>
<td class='confluenceTd'> The port name this service is implementing, it maps to the <tt>wsdl:port@name</tt>. </td>
<td class='confluenceTd'> {http:­//org.apache.camel}PortName </td>
<td class='confluenceTd'> Only if more than one <tt>portName</tt> under the <tt>serviceName</tt> is present, and it is required for camel-cxf consumer since camel 2.2 </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>dataFormat</tt> </td>
<td class='confluenceTd'> Which data type messages the CXF endpoint supports </td>
<td class='confluenceTd'> <tt>POJO</tt>, <tt>PAYLOAD</tt>, <tt>MESSAGE</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>POJO</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayHeaders</tt> </td>
<td class='confluenceTd'> Available since 1.6.1. Please see the <b>Description of</b> <tt><b>relayHeaders</b></tt> <b>option</b> section for this option in 2.0.  Should a CXF endpoint relay headers along the route. Currently only available when <tt>dataFormat=POJO</tt> </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wrapped</tt> </td>
<td class='confluenceTd'> Which kind of operation that CXF  endpoint producer will invoke </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> Will set the default bus when CXF endpoint create a bus by itself </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a bus object from the registry. The referenced object must be an instance of <tt>org.apache.cxf.Bus</tt>. <br clear="all" /> </td>
<td class='confluenceTd'> <tt>bus=#busName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Default bus created by CXF Bus Factory <br clear="all" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxfBinding</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a CXF binding object from the registry. The referenced object must be an instance of <tt>org.apache.camel.component.cxf.CxfBinding</tt>. </td>
<td class='confluenceTd'> <tt>cxfBinding=#bindingName</tt> <br clear="all" /> </td>
<td class='confluenceTd'> No <br clear="all" /> </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.DefaultCxfBinding</tt> <br clear="all" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a header filter strategy object from the registry. The referenced object must be an instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>. </td>
<td class='confluenceTd'> <tt>headerFilterStrategy=#strategyName</tt> </td>
<td class='confluenceTd'> No <br clear="all" /> </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.CxfHeaderFilterStrategy</tt> <br clear="all" /> </td>
</tr>
</tbody></table>
<p>The <tt>serviceName</tt> and <tt>portName</tt> are <a href="http://en.wikipedia.org/wiki/QName" rel="nofollow">QNames</a>, so if you provide them be sure to prefix them with their {<tt><em>namespace</em></tt>} as shown in the examples above.</p>

<p><b>NOTE</b> From CAMEL 1.5.1 , the <tt>serviceClass</tt> for a CXF producer (that is, the <tt>to</tt> endpoint) should be a Java interface.</p>

<h4><a name="BookComponentAppendix-Thedescriptionsofthedataformats"></a>The descriptions of the dataformats</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> DataFormat </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>POJO</tt> </td>
<td class='confluenceTd'> POJOs (Plain old Java objects) are the Java parameters to the method being invoked on the target server.  Both Protocol and Logical JAX-WS handlers are supported. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>PAYLOAD</tt> </td>
<td class='confluenceTd'> <tt>PAYLOAD</tt> is the message payload (the contents of the <tt>soap:body</tt>) after message configuration in the CXF endpoint is applied.  Only Protocol JAX-WS handler is supported.  Logical JAX-WS handler is not supported. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>MESSAGE</tt> </td>
<td class='confluenceTd'> <tt>MESSAGE</tt> is the raw message that is received from the transport layer.  JAX-WS handler is not supported. </td>
</tr>
</tbody></table>
<p>You can determine the data format mode of an exchange by retrieving the exchange property, <tt>CamelCXFDataFormat</tt>.  The exchange key constant is defined in <tt>org.apache.camel.component.cxf.CxfConstants.DATA_FORMAT_PROPERTY</tt>.</p>

<h5><a name="BookComponentAppendix-HowtoenableCXF%27sLoggingOutInterceptorinMESSAGEmode"></a>How to enable CXF's LoggingOutInterceptor in MESSAGE mode</h5>

<p>CXF's <tt>LoggingOutInterceptor</tt> outputs outbound message that goes on the wire to logging system (Java Util Logging).  Since the <tt>LoggingOutInterceptor</tt> is in <tt>PRE_STREAM</tt> phase (but <tt>PRE_STREAM</tt> phase is removed in <tt>MESSAGE</tt> mode), you have to configure <tt>LoggingOutInterceptor</tt> to be run during the <tt>WRITE</tt> phase.  The following is an example.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">   <span class="code-tag">&lt;bean id=<span class="code-quote">"loggingOutInterceptor"</span> class=<span class="code-quote">"org.apache.cxf.interceptor.LoggingOutInterceptor"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!--  it really should have been user-prestream but CXF does have such phase! --&gt;</span></span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"write"</span>/&gt;</span> 
   <span class="code-tag">&lt;/bean&gt;</span>
   		
&lt;cxf:cxfEndpoint id=<span class="code-quote">"serviceEndpoint"</span> address=<span class="code-quote">"http://localhost:9002/helloworld"</span>
	serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.HelloService"</span>&gt;
	<span class="code-tag">&lt;cxf:outInterceptors&gt;</span>
	    <span class="code-tag">&lt;ref bean=<span class="code-quote">"loggingOutInterceptor"</span>/&gt;</span>
	<span class="code-tag">&lt;/cxf:outInterceptors&gt;</span>
	<span class="code-tag">&lt;cxf:properties&gt;</span>
		<span class="code-tag">&lt;entry key=<span class="code-quote">"dataFormat"</span> value=<span class="code-quote">"MESSAGE"</span>/&gt;</span>
	<span class="code-tag">&lt;/cxf:properties&gt;</span>
<span class="code-tag">&lt;/cxf:cxfEndpoint&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-DescriptionofrelayHeadersoption"></a>Description of relayHeaders option</h4>

<p>There are <em>in-band</em> and <em>out-of-band</em> on-the-wire headers from the perspective of a JAXWS WSDL-first developer.</p>

<p>The <em>in-band</em> headers are headers that are explicitly defined as part of the WSDL binding contract for an endpoint such as SOAP headers.</p>

<p>The <em>out-of-band</em> headers are headers that are serialized over the wire, but are not explicitly part of the WSDL binding contract.</p>

<p>Headers relaying/filtering is bi-directional.</p>

<p>When a route has a CXF endpoint and the developer needs to have on-the-wire headers, such as SOAP headers, be relayed along the route to be consumed say by another JAXWS endpoint, then <tt>relayHeaders</tt> should be set to <tt>true</tt>, which is the default value.</p>

<h5><a name="BookComponentAppendix-AvailableinRelease1.6.1andafter%28onlyinPOJOmode%29"></a>Available in Release 1.6.1 and after (only in POJO mode)</h5>

<p>The <tt>relayHeaders=true</tt> express an intent to relay the headers. The actual decision on whether a given header is relayed is delegated to a pluggable instance that implements the <tt>MessageHeadersRelay</tt> interface. A concrete implementation of <tt>MessageHeadersRelay</tt> will be consulted to decide if a header needs to be relayed or not. There is already an implementation of <tt>SoapMessageHeadersRelay</tt> which binds itself to well-known SOAP name spaces. Currently only out-of-band headers are filtered, and in-band headers will always be relayed when <tt>relayHeaders=true</tt>. If there is a header on the wire, whose name space is unknown to the runtime, then a fall back <tt>DefaultMessageHeadersRelay</tt> will be used, which simply allows all headers to be relayed.</p>

<p>The <tt>relayHeaders=false</tt> setting asserts that all headers in-band and out-of-band will be dropped.</p>

<p>You can plugin your own <tt>MessageHeadersRelay</tt> implementations overriding or adding additional ones to the list of relays. In order to override a preloaded relay instance just make sure that your <tt>MessageHeadersRelay</tt> implementation services the same name spaces as the one you looking to override. Also note, that the overriding relay has to service all of the name spaces as the one you looking to override, or else a runtime exception on route start up will be thrown as this would introduce an ambiguity in name spaces to relay instance mappings.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;cxf:cxfEndpoint ...&gt;</span>
   <span class="code-tag">&lt;cxf:properties&gt;</span>
     <span class="code-tag">&lt;entry key=<span class="code-quote">"org.apache.camel.cxf.message.headers.relays"</span>&gt;</span>
       <span class="code-tag">&lt;list&gt;</span>
         <span class="code-tag">&lt;ref bean=<span class="code-quote">"customHeadersRelay"</span>/&gt;</span>
       <span class="code-tag">&lt;/list&gt;</span>
     <span class="code-tag">&lt;/entry&gt;</span>
   <span class="code-tag">&lt;/cxf:properties&gt;</span>
 <span class="code-tag">&lt;/cxf:cxfEndpoint&gt;</span>
 <span class="code-tag">&lt;bean id=<span class="code-quote">"customHeadersRelay"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.soap.headers.CustomHeadersRelay"</span>/&gt;</span>
</pre>
</div></div>
<p>Take a look at the tests that show how you'd be able to relay/drop headers here:</p>

<p><a href="https://svn.apache.org/repos/asf/camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java" rel="nofollow">https://svn.apache.org/repos/asf/camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java</a></p>

<h5><a name="BookComponentAppendix-ChangessinceRelease2.0"></a>Changes since Release 2.0</h5>

<ul>
	<li><tt>POJO</tt> and <tt>PAYLOAD</tt> modes are supported.  In <tt>POJO</tt> mode, only out-of-band message headers are available for filtering as the in-band headers have been processed and removed from header list by CXF.  The in-band headers are incorporated into the <tt>MessageContentList</tt> in POJO mode.  The <tt>camel-cxf</tt> component does make any attempt to remove the in-band headers from the <tt>MessageContentList</tt> as it does in 1.6.1.  If filtering of in-band headers is required, please use <tt>PAYLOAD</tt> mode or plug in a (pretty straightforward) CXF interceptor/JAXWS Handler to the CXF endpoint.</li>
	<li>The Message Header Relay mechanism has been merged into <tt>CxfHeaderFilterStrategy</tt>.  The <tt>relayHeaders</tt> option, its semantics, and default value remain the same, but it is a property of <tt>CxfHeaderFilterStrategy</tt>.<br/>
Here is an example of configuring it.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"dropAllMessageHeadersStrategy"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.CxfHeaderFilterStrategy"</span>&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!--  Set relayHeaders to false to drop all SOAP headers --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"relayHeaders"</span> value=<span class="code-quote">"false"</span>/&gt;</span>
    
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<p>Then, your endpoint can reference the <tt>CxfHeaderFilterStrategy</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"cxf:bean:routerNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"</span>/&gt;</span>          
    <span class="code-tag">&lt;to uri=<span class="code-quote">"cxf:bean:serviceNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div></li>
	<li>The <tt>MessageHeadersRelay</tt> interface has changed slightly and has been renamed to <tt>MessageHeaderFilter</tt>.  It is a property of <tt>CxfHeaderFilterStrategy</tt>.  Here is an example of configuring user defined Message Header Filters:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"customMessageFilterStrategy"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.CxfHeaderFilterStrategy"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"messageHeaderFilters"</span>&gt;</span>
        <span class="code-tag">&lt;list&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!--  SoapMessageHeaderFilter is the built in filter.  It can be removed by omitting it. --&gt;</span></span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.SoapMessageHeaderFilter"</span>/&gt;</span>          
            
            <span class="code-tag"><span class="code-comment">&lt;!--  Add custom filter here --&gt;</span></span>    
            <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.soap.headers.CustomHeaderFilter"</span>/&gt;</span>
        <span class="code-tag">&lt;/list&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div></li>
	<li>Other than <tt>relayHeaders</tt>, there are new properties that can be configured in <tt>CxfHeaderFilterStrategy</tt>.
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> type </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayHeaders</tt> </td>
<td class='confluenceTd'> All message headers will be processed by Message Header Filters </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>true</tt> (1.6.1 behavior) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayAllMessageHeaders</tt> </td>
<td class='confluenceTd'> All message headers will be propagated (without processing by Message Header Filters) </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> (1.6.1 behavior) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowFilterNamespaceClash</tt> </td>
<td class='confluenceTd'> If two filters overlap in activation namespace, the property control how it should be handled.  If the value is <tt>true</tt>, last one wins.  If the value is <tt>false</tt>, it will throw an exception </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> (1.6.1 behavior) </td>
</tr>
</tbody></table></li>
</ul>


<h3><a name="BookComponentAppendix-ConfiguretheCXFendpointswithSpring"></a>Configure the CXF endpoints with Spring</h3>

<p>You can configure the CXF endpoint with the Spring configuration file shown below, and you can also embed the endpoint into the <tt>camelContext</tt> tags.  When you are invoking the service endpoint, you can set the <tt>operationName</tt> and <tt>operationNameSpace</tt> headers to explicitly state which operation you are calling.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;beans xmlns=<span class="code-quote">"http:<span class="code-comment">//www.springframework.org/schema/beans"</span>
</span>        xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema-instance"</span>
</span>        xmlns:cxf=<span class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/cxfEndpoint"</span>
</span>        xsi:schemaLocation="
                http:<span class="code-comment">//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
</span>                http:<span class="code-comment">//activemq.apache.org/camel/schema/cxfEndpoint http://activemq.apache.org/camel/schema/cxf/camel-cxf-1.6.0.xsd
</span>                http:<span class="code-comment">//activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd     "&gt;
</span>     &lt;cxf:cxfEndpoint id=<span class="code-quote">"routerEndpoint"</span> address=<span class="code-quote">"http:<span class="code-comment">//localhost:9003/CamelContext/RouterPort"</span>
</span>     		serviceClass=<span class="code-quote">"org.apache.hello_world_soap_http.GreeterImpl"</span>/&gt;
     &lt;cxf:cxfEndpoint id=<span class="code-quote">"serviceEndpoint"</span> address=<span class="code-quote">"http:<span class="code-comment">//localhost:9000/SoapContext/SoapPort"</span>
</span>     		wsdlURL=<span class="code-quote">"testutils/hello_world.wsdl"</span>
     		serviceClass=<span class="code-quote">"org.apache.hello_world_soap_http.Greeter"</span>
     		endpointName=<span class="code-quote">"s:SoapPort"</span>
     		serviceName=<span class="code-quote">"s:SOAPService"</span>
     	xmlns:s=<span class="code-quote">"http:<span class="code-comment">//apache.org/hello_world_soap_http"</span> /&gt;
</span>     &lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span>&gt;
</span>       &lt;route&gt;
         &lt;from uri=<span class="code-quote">"cxf:bean:routerEndpoint"</span> /&gt;
         &lt;to uri=<span class="code-quote">"cxf:bean:serviceEndpoint"</span> /&gt;
       &lt;/route&gt;
    &lt;/camelContext&gt;
  &lt;/beans&gt;
</pre>
</div></div>
<p><b>NOTE</b> In Camel 2.x we change to use {{http:­//camel.apache.org/schema/cxf}} as the CXF endpoint's target namespace.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;beans xmlns=<span class="code-quote">"http:<span class="code-comment">//www.springframework.org/schema/beans"</span>
</span>        xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema-instance"</span>
</span>        xmlns:cxf=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/cxf"</span>
</span>        xsi:schemaLocation="
        http:<span class="code-comment">//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
</span>        http:<span class="code-comment">//camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
</span>        http:<span class="code-comment">//camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd     "&gt;
</span> ...
</pre>
</div></div>
<p>Be sure to include the JAX-WS <tt>schemaLocation</tt> attribute specified on the root beans element. This allows CXF to validate the file and is required.  Also note the namespace declarations at the end of the <tt>&lt;cxf:cxfEndpoint/&gt;</tt> tag--these are required because the combined {<tt>namespace}localName</tt> syntax is presently not supported for this tag's attribute values.</p>

<p>The <tt>cxf:cxfEndpoint</tt> element supports many additional attributes:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>PortName</tt> </td>
<td class='confluenceTd'> The endpoint name this service is implementing, it maps to the <tt>wsdl:port@name</tt>. In the format of <tt>ns:PORT_NAME</tt> where <tt>ns</tt> is a namespace prefix valid at this scope. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceName</tt> </td>
<td class='confluenceTd'> The service name this service is implementing, it maps to the <tt>wsdl:service@name</tt>. In the format of <tt>ns:SERVICE_NAME</tt> where <tt>ns</tt> is a namespace prefix valid at this scope. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wsdlURL</tt> </td>
<td class='confluenceTd'> The location of the WSDL. Can be on the classpath, file system, or be hosted remotely. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bindingId</tt> </td>
<td class='confluenceTd'> The <tt>bindingId</tt> for the service model to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>address</tt> </td>
<td class='confluenceTd'> The service publish address. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> The bus name that will be used in the JAX-WS endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClass</tt> </td>
<td class='confluenceTd'> The class name of the SEI (Service Endpoint Interface) class which could have JSR181 annotation or not. </td>
</tr>
</tbody></table>
<p>It also supports many child elements:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:inInterceptors</tt> </td>
<td class='confluenceTd'> The incoming interceptors for this endpoint. A list of <tt>&lt;bean&gt;</tt> or <tt>&lt;ref&gt;</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:inFaultInterceptors</tt> </td>
<td class='confluenceTd'> The incoming fault interceptors for this endpoint.  A list of <tt>&lt;bean&gt;</tt> or <tt>&lt;ref&gt;</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:outInterceptors</tt> </td>
<td class='confluenceTd'> The outgoing interceptors for this endpoint. A list of <tt>&lt;bean&gt;</tt> or <tt>&lt;ref&gt;</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:outFaultInterceptors</tt> </td>
<td class='confluenceTd'> The outgoing fault interceptors for this endpoint. A list of <tt>&lt;bean&gt;</tt> or <tt>&lt;ref&gt;</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:properties</tt> </td>
<td class='confluenceTd'> A properties map which should be supplied to the JAX-WS endpoint. See below. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:handlers</tt> </td>
<td class='confluenceTd'> A JAX-WS handler list which should be supplied to the JAX-WS endpoint. See below. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:dataBinding</tt> </td>
<td class='confluenceTd'> You can specify the which <tt>DataBinding</tt> will be use in the endpoint. This can be supplied using the Spring <tt>&lt;bean class="MyDataBinding"/&gt;</tt> syntax. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:binding</tt> </td>
<td class='confluenceTd'> You can specify the <tt>BindingFactory</tt> for this endpoint to use.  This can be supplied using the Spring <tt>&lt;bean class="MyBindingFactory"/&gt;</tt> syntax. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:features</tt> </td>
<td class='confluenceTd'> The features that hold the interceptors for this endpoint. A list of {{&lt;bean&gt;}}s or {{&lt;ref&gt;}}s </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:schemaLocations</tt> </td>
<td class='confluenceTd'> The schema locations for endpoint to use. A list of {{&lt;schemaLocation&gt;}}s </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxf:serviceFactory</tt> </td>
<td class='confluenceTd'> The service factory for this endpoint to use. This can be supplied using the Spring <tt>&lt;bean class="MyServiceFactory"/&gt;</tt> syntax </td>
</tr>
</tbody></table>
<p>You can find more advanced examples which show how to provide interceptors , properties and handlers here:<br/>
<a href="http://cwiki.apache.org/CXF20DOC/jax-ws-configuration.html" rel="nofollow">http://cwiki.apache.org/CXF20DOC/jax-ws-configuration.html</a></p>

<p><b>NOTE</b><br/>
You can use cxf:properties to set the camel-cxf endpoint's dataFormat and setDefaultBus properties from spring configuration file.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;cxf:cxfEndpoint id=<span class="code-quote">"testEndpoint"</span> address=<span class="code-quote">"http://localhost:9000/router"</span>
     serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.HelloService"</span>
     endpointName=<span class="code-quote">"s:PortName"</span>
     serviceName=<span class="code-quote">"s:ServiceName"</span>
     <span class="code-keyword">xmlns:s</span>=<span class="code-quote">"http://www.example.com/test"</span>&gt;
     <span class="code-tag">&lt;cxf:properties&gt;</span>
       <span class="code-tag">&lt;entry key=<span class="code-quote">"dataFormat"</span> value=<span class="code-quote">"MESSAGE"</span>/&gt;</span>
       <span class="code-tag">&lt;entry key=<span class="code-quote">"setDefaultBus"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
     <span class="code-tag">&lt;/cxf:properties&gt;</span>
   <span class="code-tag">&lt;/cxf:cxfEndpoint&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Howtomakethecamelcxfcomponentuselog4jinsteadofjava.util.logging"></a>How to make the camel-cxf component use log4j instead of java.util.logging</h3>

<p>CXF's default logger is <tt>java.util.logging</tt>. If you want to change it to log4j, proceed as follows. Create a file, in the classpath, named <tt>META-INF/cxf/org.apache.cxf.logger</tt>. This file should contain the fully-qualified name of the class, <tt>org.apache.cxf.common.logging.Log4jLogger</tt>, with no comments, on a single line.</p>

<h3><a name="BookComponentAppendix-HowtoconsumeamessagefromacamelcxfendpointinPOJOdataformat"></a>How to consume a message from a camel-cxf endpoint in POJO data format</h3>

<p>The <tt>camel-cxf</tt> endpoint consumer POJO data format is based on the <a href="http://cwiki.apache.org/CXF20DOC/invokers.html" rel="nofollow">cxf invoker</a>, so the message header has a property with the name of <tt>CxfConstants.OPERATION_NAME</tt> and the message body is a list of the SEI method parameters.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class PersonProcessor <span class="code-keyword">implements</span> Processor {

    <span class="code-keyword">private</span> <span class="code-keyword">static</span> <span class="code-keyword">final</span> <span class="code-keyword">transient</span> Log LOG = LogFactory.getLog(PersonProcessor.class);

    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        LOG.info(<span class="code-quote">"processing exchange in camel"</span>);

        BindingOperationInfo boi = (BindingOperationInfo)exchange.getProperty(BindingOperationInfo.class.toString());
        <span class="code-keyword">if</span> (boi != <span class="code-keyword">null</span>) {
            LOG.info(<span class="code-quote">"boi.isUnwrapped"</span> + boi.isUnwrapped());
        }
        <span class="code-comment">// Get the parameters list which element is the holder.
</span>        MessageContentsList msgList = (MessageContentsList)exchange.getIn().getBody();
        Holder&lt;<span class="code-object">String</span>&gt; personId = (Holder&lt;<span class="code-object">String</span>&gt;)msgList.get(0);
        Holder&lt;<span class="code-object">String</span>&gt; ssn = (Holder&lt;<span class="code-object">String</span>&gt;)msgList.get(1);
        Holder&lt;<span class="code-object">String</span>&gt; name = (Holder&lt;<span class="code-object">String</span>&gt;)msgList.get(2);

        <span class="code-keyword">if</span> (personId.value == <span class="code-keyword">null</span> || personId.value.length() == 0) {
            LOG.info(<span class="code-quote">"person id 123, so throwing exception"</span>);
            <span class="code-comment">// Try to <span class="code-keyword">throw</span> out the soap fault message
</span>            org.apache.camel.wsdl_first.types.UnknownPersonFault personFault =
                <span class="code-keyword">new</span> org.apache.camel.wsdl_first.types.UnknownPersonFault();
            personFault.setPersonId("");
            org.apache.camel.wsdl_first.UnknownPersonFault fault =
                <span class="code-keyword">new</span> org.apache.camel.wsdl_first.UnknownPersonFault(<span class="code-quote">"Get the <span class="code-keyword">null</span> value of person name"</span>, personFault);
            <span class="code-comment">// Since camel has its own exception handler framework, we can't <span class="code-keyword">throw</span> the exception to trigger it
</span>            <span class="code-comment">// We just set the fault message in the exchange <span class="code-keyword">for</span> camel-cxf component handling and <span class="code-keyword">return</span>
</span>            exchange.getOut().setFault(<span class="code-keyword">true</span>);
            exchange.getOut().setBody(fault);
            <span class="code-keyword">return</span>;
        }

        name.value = <span class="code-quote">"Bonjour"</span>;
        ssn.value = <span class="code-quote">"123"</span>;
        LOG.info(<span class="code-quote">"setting Bonjour as the response"</span>);
        <span class="code-comment">// Set the response message, first element is the <span class="code-keyword">return</span> value of the operation,
</span>        <span class="code-comment">// the others are the holders of method parameters
</span>        exchange.getOut().setBody(<span class="code-keyword">new</span> <span class="code-object">Object</span>[] {<span class="code-keyword">null</span>, personId, ssn, name});
    }

}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HowtopreparethemessageforthecamelcxfendpointinPOJOdataformat"></a>How to prepare the message for the camel-cxf endpoint in POJO data format</h3>

<p>The <tt>camel-cxf</tt> endpoint producer is based on the <a href="https://svn.apache.org/repos/asf/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java" rel="nofollow">cxf client API</a>. First you need to specify the operation name in the message header, then add the method parameters to a list, and initialize the message with this parameter list. The response message's body is a messageContentsList, you can get the result from that list.</p>

<p><b>NOTE</b> After Camel 1.5 , we change the message body from object array to message content list. If you still want to get the object array from the message body, you can get the body using <tt>message.getbody(Object[].class)</tt>, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Exchange senderExchange = <span class="code-keyword">new</span> DefaultExchange(context, ExchangePattern.InOut);
<span class="code-keyword">final</span> List&lt;<span class="code-object">String</span>&gt; params = <span class="code-keyword">new</span> ArrayList&lt;<span class="code-object">String</span>&gt;();
<span class="code-comment">// Prepare the request message <span class="code-keyword">for</span> the camel-cxf procedure
</span>params.add(TEST_MESSAGE);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);

Exchange exchange = template.send(<span class="code-quote">"direct:EndpointA"</span>, senderExchange);

org.apache.camel.Message out = exchange.getOut();
<span class="code-comment">// The response message's body is an MessageContentsList which first element is the <span class="code-keyword">return</span> value of the operation,
</span><span class="code-comment">// If there are some holder parameters, the holder parameter will be filled in the reset of List.
</span><span class="code-comment">// The result will be extract from the MessageContentsList with the <span class="code-object">String</span> class type
</span>MessageContentsList result = (MessageContentsList)out.getBody();
LOG.info(<span class="code-quote">"Received output text: "</span> + result.get(0));
Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; responseContext = CastUtils.<span class="code-keyword">cast</span>((Map)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals(<span class="code-quote">"We should get the response context here"</span>, <span class="code-quote">"UTF-8"</span>, responseContext.get(org.apache.cxf.message.Message.ENCODING));
assertEquals(<span class="code-quote">"Reply body on Camel is wrong"</span>, <span class="code-quote">"echo "</span> + TEST_MESSAGE, result.get(0));
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HowtodealwiththemessageforacamelcxfendpointinPAYLOADdataformat"></a>How to deal with the message for a camel-cxf endpoint in PAYLOAD data format</h3>

<p><tt>PAYLOAD</tt> means that you process the payload message from the SOAP envelope. You can use the <tt>Header.HEADER_LIST</tt> as the key to set or get the SOAP headers and use the <tt>List&lt;Element&gt;</tt> to set or get SOAP body elements.<br/>
Camel 1.x branch, you can get the <tt>List&lt;Element&gt;</tt> and header from the CXF Message, but if you want to set the response message, you need to create the CXF message using the CXF API.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            from(SIMPLE_ENDPOINT_URI + <span class="code-quote">"&amp;dataFormat=PAYLOAD"</span>).to(<span class="code-quote">"log:info"</span>).process(<span class="code-keyword">new</span> Processor() {
                <span class="code-keyword">public</span> void process(<span class="code-keyword">final</span> Exchange exchange) <span class="code-keyword">throws</span> Exception {
                    Message inMessage = exchange.getIn();
                    <span class="code-keyword">if</span> (inMessage <span class="code-keyword">instanceof</span> CxfMessage) {
                        CxfMessage cxfInMessage = (CxfMessage) inMessage;
                        CxfMessage cxfOutMessage = (CxfMessage) exchange.getOut();
                        List&lt;Element&gt; inElements = cxfInMessage.getMessage().get(List.class);
                        List&lt;Element&gt; outElements = <span class="code-keyword">new</span> ArrayList&lt;Element&gt;();
                        XmlConverter converter = <span class="code-keyword">new</span> XmlConverter();
                        <span class="code-object">String</span> documentString = ECHO_RESPONSE;
                        <span class="code-keyword">if</span> (inElements.get(0).getLocalName().equals(<span class="code-quote">"echoBoolean"</span>)) {
                            documentString = ECHO_BOOLEAN_RESPONSE;
                        }
                        org.apache.cxf.message.Exchange ex = ((CxfExchange)exchange).getExchange();
                        Endpoint ep = ex.get(Endpoint.class);
                        org.apache.cxf.message.Message response = ep.getBinding().createMessage();
                        Document outDocument = converter.toDOMDocument(documentString);
                        outElements.add(outDocument.getDocumentElement());
                        response.put(List.class, outElements);
                        cxfOutMessage.setMessage(response);                            
                    }
                }
            });
        }
    };
}
</pre>
</div></div>
<p><b>Change in 2.0</b>, <tt>CxfMessage.getBody()</tt> will return an <tt>org.apache.camel.component.cxf.CxfPayload</tt> object, which has getters for SOAP message headers and Body elements. This change enables decoupling the native CXF message from the Camel message.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            from(SIMPLE_ENDPOINT_URI + <span class="code-quote">"&amp;dataFormat=PAYLOAD"</span>).to(<span class="code-quote">"log:info"</span>).process(<span class="code-keyword">new</span> Processor() {
                <span class="code-keyword">public</span> void process(<span class="code-keyword">final</span> Exchange exchange) <span class="code-keyword">throws</span> Exception {                        
                    CxfPayload&lt;SoapHeader&gt; requestPayload = exchange.getIn().getBody(CxfPayload.class);
                    List&lt;Element&gt; inElements = requestPayload.getBody();
                    List&lt;Element&gt; outElements = <span class="code-keyword">new</span> ArrayList&lt;Element&gt;();
                    XmlConverter converter = <span class="code-keyword">new</span> XmlConverter();
                    <span class="code-object">String</span> documentString = ECHO_RESPONSE;
                    <span class="code-keyword">if</span> (inElements.get(0).getLocalName().equals(<span class="code-quote">"echoBoolean"</span>)) {
                        documentString = ECHO_BOOLEAN_RESPONSE;
                    }
                    Document outDocument = converter.toDOMDocument(documentString);
                    outElements.add(outDocument.getDocumentElement());
                    <span class="code-comment">// set the payload header with <span class="code-keyword">null</span>
</span>                    CxfPayload&lt;SoapHeader&gt; responsePayload = <span class="code-keyword">new</span> CxfPayload&lt;SoapHeader&gt;(<span class="code-keyword">null</span>, outElements);
                    exchange.getOut().setBody(responsePayload); 
                }
            });
        }
    };
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HowtogetandsetSOAPheadersinPOJOmode"></a>How to get and set SOAP headers in POJO mode</h3>

<p><tt>POJO</tt> means that the data format is a "list of Java objects" when the Camel-cxf endpoint produces or consumes Camel exchanges.  Even though Camel expose message body as POJOs in this mode, Camel-cxf still provides access to read and write SOAP headers.  However, since CXF interceptors remove in-band SOAP headers from Header list after they have been processed, only out-of-band SOAP headers are available to Camel-cxf in POJO mode.</p>

<p>The following example illustrate how to get/set SOAP headers.  Suppose we have a route that forwards from one Camel-cxf endpoint to another.  That is, SOAP Client &#45;&gt; Camel &#45;&gt; CXF service.   We can attach two processors to obtain/insert SOAP headers at (1) before request goes out to the CXF service and (2) before response comes back to the SOAP Client.  Processor (1) and (2) in this example are InsertRequestOutHeaderProcessor and InsertResponseOutHeaderProcessor.  Our route looks like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"cxf:bean:routerRelayEndpointWithInsertion"</span>/&gt;</span>
    <span class="code-tag">&lt;process ref=<span class="code-quote">"InsertRequestOutHeaderProcessor"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"cxf:bean:serviceRelayEndpointWithInsertion"</span>/&gt;</span>
    <span class="code-tag">&lt;process ref=<span class="code-quote">"InsertResponseOutHeaderProcessor"</span> /&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>     
</pre>
</div></div>

<p><b>In 2.x</b> SOAP headers are propagated to and from Camel Message headers.  The Camel message header name is "org.apache.cxf.headers.Header.list" which is a constant defined in CXF (org.apache.cxf.headers.Header.HEADER_LIST).  The header value is a List of CXF SoapHeader objects (org.apache.cxf.binding.soap.SoapHeader).  The following snippet is the InsertResponseOutHeaderProcessor (that insert a new SOAP header in the response message).  The way to access SOAP headers in both InsertResponseOutHeaderProcessor and InsertRequestOutHeaderProcessor are actually the same.  The only difference between the two processors is setting the direction of the inserted SOAP header.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">static</span> class InsertResponseOutHeaderProcessor <span class="code-keyword">implements</span> Processor {

    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        List&lt;SoapHeader&gt; soapHeaders = (List)exchange.getIn().getHeader(Header.HEADER_LIST);

        <span class="code-comment">// Insert a <span class="code-keyword">new</span> header
</span>        <span class="code-object">String</span> xml = <span class="code-quote">"&lt;?xml version=\"</span>1.0\<span class="code-quote">" encoding=\"</span>utf-8\<span class="code-quote">"?&gt;&lt;outofbandHeader "</span>
            + <span class="code-quote">"xmlns=\"</span>http:<span class="code-comment">//cxf.apache.org/outofband/Header\<span class="code-quote">" hdrAttribute=\"</span>testHdrAttribute\<span class="code-quote">" "</span>
</span>            + <span class="code-quote">"xmlns:soap=\"</span>http:<span class="code-comment">//schemas.xmlsoap.org/soap/envelope/\<span class="code-quote">" soap:mustUnderstand=\"</span>1\<span class="code-quote">"&gt;"</span>
</span>            + <span class="code-quote">"&lt;name&gt;New_testOobHeader&lt;/name&gt;&lt;value&gt;New_testOobHeaderValue&lt;/value&gt;&lt;/outofbandHeader&gt;"</span>;
        SoapHeader newHeader = <span class="code-keyword">new</span> SoapHeader(soapHeaders.get(0).getName(),
                       DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(xml)).getDocumentElement());
        <span class="code-comment">// make sure direction is OUT since it is a response message.
</span>        newHeader.setDirection(Direction.DIRECTION_OUT);
        <span class="code-comment">//newHeader.setMustUnderstand(<span class="code-keyword">false</span>);
</span>        soapHeaders.add(newHeader);
        
    }
    
}

</pre>
</div></div>

<p><b>In 1.x</b> SOAP headers are not propagated to and from Camel Message headers. Users have to go deeper into CXF APIs to access SOAP headers.  Also, accessing the SOAP headers in a request message is slight different than in a response message.  The InsertRequestOutHeaderProcessor and InsertResponseOutHeaderProcessor are as follow.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">static</span> class InsertRequestOutHeaderProcessor <span class="code-keyword">implements</span> Processor {
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        CxfMessage message = exchange.getIn().getBody(CxfMessage.class);
        Message cxf = message.getMessage();
        List&lt;SoapHeader&gt; soapHeaders = (List)cxf.get(Header.HEADER_LIST);

        <span class="code-comment">// Insert a <span class="code-keyword">new</span> header
</span>        <span class="code-object">String</span> xml = <span class="code-quote">"&lt;?xml version=\"</span>1.0\<span class="code-quote">" encoding=\"</span>utf-8\<span class="code-quote">"?&gt;&lt;outofbandHeader "</span>
            + <span class="code-quote">"xmlns=\"</span>http:<span class="code-comment">//cxf.apache.org/outofband/Header\<span class="code-quote">" hdrAttribute=\"</span>testHdrAttribute\<span class="code-quote">" "</span>
</span>            + <span class="code-quote">"xmlns:soap=\"</span>http:<span class="code-comment">//schemas.xmlsoap.org/soap/envelope/\<span class="code-quote">" soap:mustUnderstand=\"</span>1\<span class="code-quote">"&gt;"</span>
</span>            + <span class="code-quote">"&lt;name&gt;New_testOobHeader&lt;/name&gt;&lt;value&gt;New_testOobHeaderValue&lt;/value&gt;&lt;/outofbandHeader&gt;"</span>;
        
        SoapHeader newHeader = <span class="code-keyword">new</span> SoapHeader(soapHeaders.get(0).getName(),
                                              DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(xml)).getDocumentElement());
        <span class="code-comment">// make sure direction is IN since it is a request message.
</span>        newHeader.setDirection(Direction.DIRECTION_IN);
        <span class="code-comment">//newHeader.setMustUnderstand(<span class="code-keyword">false</span>);
</span>        soapHeaders.add(newHeader);
        
    }
}

<span class="code-keyword">public</span> <span class="code-keyword">static</span> class InsertResponseOutHeaderProcessor <span class="code-keyword">implements</span> Processor {
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        CxfMessage message = exchange.getIn().getBody(CxfMessage.class);
        Map responseContext = (Map)message.getMessage().get(Client.RESPONSE_CONTEXT);
        List&lt;SoapHeader&gt; soapHeaders = (List)responseContext.get(Header.HEADER_LIST);
        
        <span class="code-comment">// Insert a <span class="code-keyword">new</span> header
</span>        <span class="code-object">String</span> xml = <span class="code-quote">"&lt;?xml version=\"</span>1.0\<span class="code-quote">" encoding=\"</span>utf-8\<span class="code-quote">"?&gt;&lt;outofbandHeader "</span>
            + <span class="code-quote">"xmlns=\"</span>http:<span class="code-comment">//cxf.apache.org/outofband/Header\<span class="code-quote">" hdrAttribute=\"</span>testHdrAttribute\<span class="code-quote">" "</span>
</span>            + <span class="code-quote">"xmlns:soap=\"</span>http:<span class="code-comment">//schemas.xmlsoap.org/soap/envelope/\<span class="code-quote">" soap:mustUnderstand=\"</span>1\<span class="code-quote">"&gt;"</span>
</span>            + <span class="code-quote">"&lt;name&gt;New_testOobHeader&lt;/name&gt;&lt;value&gt;New_testOobHeaderValue&lt;/value&gt;&lt;/outofbandHeader&gt;"</span>;
        SoapHeader newHeader = <span class="code-keyword">new</span> SoapHeader(soapHeaders.get(0).getName(),
                       DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(xml)).getDocumentElement());
        <span class="code-comment">// make sure direction is OUT since it is a response message.
</span>        newHeader.setDirection(Direction.DIRECTION_OUT);
        <span class="code-comment">//newHeader.setMustUnderstand(<span class="code-keyword">false</span>);
</span>        soapHeaders.add(newHeader);
                                       
    }
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HowtogetandsetSOAPheadersinPAYLOADmode"></a>How to get and set SOAP headers in PAYLOAD mode</h3>

<p>We've already shown how to access SOAP message (CxfPayload object) in PAYLOAD mode (See "How to deal with the message for a camel-cxf endpoint in PAYLOAD data format").</p>

<p><b>In 2.x</b> Once you obtain a CxfPayload object, you can invoke the CxfPayload.getHeaders() method that returns a List of DOM Elements (SOAP headers).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(routerEndpointURI).process(<span class="code-keyword">new</span> Processor() {
    @SuppressWarnings(<span class="code-quote">"unchecked"</span>)
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        CxfPayload&lt;SoapHeader&gt; payload = exchange.getIn().getBody(CxfPayload.class);
        List&lt;Element&gt; elements = payload.getBody();
        assertNotNull(<span class="code-quote">"We should get the elements here"</span>, elements);
        assertEquals(<span class="code-quote">"Get the wrong elements size"</span>, 1, elements.size());
        assertEquals(<span class="code-quote">"Get the wrong namespace URI"</span>, <span class="code-quote">"http:<span class="code-comment">//camel.apache.org/pizza/types"</span>, 
</span>                elements.get(0).getNamespaceURI());
            
        List&lt;SoapHeader&gt; headers = payload.getHeaders();
        assertNotNull(<span class="code-quote">"We should get the headers here"</span>, headers);
        assertEquals(<span class="code-quote">"Get the wrong headers size"</span>, headers.size(), 1);
        assertEquals(<span class="code-quote">"Get the wrong namespace URI"</span>, 
                ((Element)(headers.get(0).getObject())).getNamespaceURI(), 
                <span class="code-quote">"http:<span class="code-comment">//camel.apache.org/pizza/types"</span>);         
</span>    }
    
})
.to(serviceEndpointURI);
</pre>
</div></div>

<p>&#42;In 1.x" You can get/set to the CXF Message by the key "org.apache.cxf.headers.Header.list" which is a constant defined in CXF (org.apache.cxf.headers.Header.HEADER_LIST).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(routerEndpointURI).process(<span class="code-keyword">new</span> Processor() {
    @SuppressWarnings(<span class="code-quote">"unchecked"</span>)
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        Message inMessage = exchange.getIn();
        CxfMessage message = (CxfMessage) inMessage;
        List&lt;Element&gt; elements = message.getMessage().get(List.class);
        assertNotNull(<span class="code-quote">"We should get the payload elements here"</span> , elements);
        assertEquals(<span class="code-quote">"Get the wrong elements size"</span> , elements.size(), 1);
        assertEquals(<span class="code-quote">"Get the wrong namespace URI"</span> , elements.get(0).getNamespaceURI(), <span class="code-quote">"http:<span class="code-comment">//camel.apache.org/pizza/types"</span>);
</span>            
        List&lt;SoapHeader&gt; headers = CastUtils.<span class="code-keyword">cast</span>((List&lt;?&gt;)message.getMessage().get(Header.HEADER_LIST));
        assertNotNull(<span class="code-quote">"We should get the headers here"</span>, headers);
        assertEquals(<span class="code-quote">"Get the wrong headers size"</span>, headers.size(), 1);
        assertEquals(<span class="code-quote">"Get the wrong namespace URI"</span> , ((Element)(headers.get(0).getObject())).getNamespaceURI(), <span class="code-quote">"http:<span class="code-comment">//camel.apache.org/pizza/types"</span>);
</span>        
    }
    
})
.to(serviceEndpointURI);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SOAPheadersarenotavailableinMESSAGEmode"></a>SOAP headers are not available in MESSAGE mode</h3>

<p>SOAP headers are not available in MESSAGE mode as SOAP processing is skipped.</p>

<h3><a name="BookComponentAppendix-HowtothrowaSOAPFaultfromCamel"></a>How to throw a SOAP Fault from Camel</h3>

<p>If you are using a <tt>camel-cxf</tt> endpoint to consume the SOAP request, you may need to throw the SOAP Fault from the camel context.<br/>
Basically, you can use the <tt>throwFault</tt> DSL to do that; it works for <tt>POJO</tt>, <tt>PAYLOAD</tt> and <tt>MESSAGE</tt> data format.<br/>
You can define the soap fault like this</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">SOAP_FAULT = <span class="code-keyword">new</span> SoapFault(EXCEPTION_MESSAGE, SoapFault.FAULT_CODE_CLIENT);
Element detail = SOAP_FAULT.getOrCreateDetail();
Document doc = detail.getOwnerDocument();
Text tn = doc.createTextNode(DETAIL_TEXT);
detail.appendChild(tn);
</pre>
</div></div>
<p>Then throw it as you like</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(routerEndpointURI).setFaultBody(constant(SOAP_FAULT));
</pre>
</div></div>
<p>If your CXF endpoint is working in the <tt>MESSAGE</tt> data format, you could set the the SOAP Fault message in the message body and set the response code in the message header.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(routerEndpointURI).process(<span class="code-keyword">new</span> Processor() {

    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        Message out = exchange.getOut();
        <span class="code-comment">// Set the message body with the 
</span>        out.setBody(<span class="code-keyword">this</span>.getClass().getResourceAsStream(<span class="code-quote">"SoapFaultMessage.xml"</span>));
        <span class="code-comment">// Set the response code here
</span>        out.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, <span class="code-keyword">new</span> <span class="code-object">Integer</span>(500));
    }

});
</pre>
</div></div>
<p><b>NOTE</b> the response code setting only works in Camel's version &gt;= 1.5.1</p>

<h3><a name="BookComponentAppendix-Howtopropagateacamelcxfendpoint%27srequestandresponsecontext"></a>How to propagate a camel-cxf endpoint's request and response context</h3>

<p><a href="https://svn.apache.org/repos/asf/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java" rel="nofollow">cxf client API</a> provides a way to invoke the operation with request and response context. If you are using a <tt>camel-cxf</tt> endpoint producer to invoke the outside web service, you can set the request context and get response context with the following code:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        CxfExchange exchange = (CxfExchange)template.send(getJaxwsEndpointUri(), <span class="code-keyword">new</span> Processor() {
             <span class="code-keyword">public</span> void process(<span class="code-keyword">final</span> Exchange exchange) {
                 <span class="code-keyword">final</span> List&lt;<span class="code-object">String</span>&gt; params = <span class="code-keyword">new</span> ArrayList&lt;<span class="code-object">String</span>&gt;();
                 params.add(TEST_MESSAGE);
                 <span class="code-comment">// Set the request context to the inMessage
</span>                 Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; requestContext = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
                 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, JAXWS_SERVER_ADDRESS);
                 exchange.getIn().setBody(params);
                 exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
                 exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
             }
         });
         org.apache.camel.Message out = exchange.getOut();
         <span class="code-comment">// The output is an object array, the first element of the array is the <span class="code-keyword">return</span> value
</span>         <span class="code-object">Object</span>\[\] output = out.getBody(<span class="code-object">Object</span>\[\].class);
         LOG.info(<span class="code-quote">"Received output text: "</span> + output\[0\]);
         <span class="code-comment">// Get the response context form outMessage
</span>         Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; responseContext = CastUtils.<span class="code-keyword">cast</span>((Map)out.getHeader(Client.RESPONSE_CONTEXT));
         assertNotNull(responseContext);
         assertEquals(<span class="code-quote">"Get the wrong wsdl opertion name"</span>, <span class="code-quote">"{http:<span class="code-comment">//apache.org/hello_world_soap_http}greetMe"</span>,
</span>                      responseContext.get(<span class="code-quote">"javax.xml.ws.wsdl.operation"</span>).toString());
</pre>
</div></div>

<h3><a name="BookComponentAppendix-AttachmentSupport"></a>Attachment Support</h3>

<p><b>POJO Mode:</b> Both SOAP with Attachment and MTOM are supported (see example in Payload Mode for enabling MTOM).&nbsp; However, SOAP with Attachment is not tested.&nbsp; Since attachments are marshalled and unmarshalled into POJOs, users typically do not need to deal with the attachment themself.&nbsp; Attachments are propagated to Camel message's attachments since 2.1.&nbsp; So, it is possible to retreive attachments by Camel Message API <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">DataHandler Message.getAttachment(<span class="code-object">String</span> id)</pre>
</div></div>.</p>

<p><b>Payload Mode:</b> MTOM is supported since 2.1.  Attachments can be retrieve by Camel Message APIs mentioned above.  SOAP with Attachment is not supported as there is no SOAP processing in this mode.</p>

<p>To enable MTOM, set the CXF endpoint property "mtom_enabled" to <em>true</em>.  (I believe you can only do it with Spring.)</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;cxf:cxfEndpoint id=<span class="code-quote">"routerEndpoint"</span> address=<span class="code-quote">"http://localhost:9091/jaxws-mtom/hello"</span>
         wsdlURL=<span class="code-quote">"mtom.wsdl"</span>
         serviceName=<span class="code-quote">"ns:HelloService"</span>
         endpointName=<span class="code-quote">"ns:HelloPort"</span>
         <span class="code-keyword">xmlns:ns</span>=<span class="code-quote">"http://apache.org/camel/cxf/mtom_feature"</span>&gt;

     <span class="code-tag">&lt;cxf:properties&gt;</span>
         <span class="code-tag"><span class="code-comment">&lt;!--  enable mtom by setting this property to true --&gt;</span></span>
         <span class="code-tag">&lt;entry key=<span class="code-quote">"mtom-enabled"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
         
         <span class="code-tag"><span class="code-comment">&lt;!--  set the camel-cxf endpoint data fromat to PAYLOAD mode --&gt;</span></span>
         <span class="code-tag">&lt;entry key=<span class="code-quote">"dataFormat"</span> value=<span class="code-quote">"PAYLOAD"</span>/&gt;</span>
     <span class="code-tag">&lt;/cxf:properties&gt;</span>      
     
</pre>
</div></div>

<p>You can produce a Camel message with attachment to send to a CXF endpoint in Payload mode.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Exchange exchange = context.createProducerTemplate().send(<span class="code-quote">"direct:testEndpoint"</span>, <span class="code-keyword">new</span> Processor() {

    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        exchange.setPattern(ExchangePattern.InOut);
        List&lt;Element&gt; elements = <span class="code-keyword">new</span> ArrayList&lt;Element&gt;();
        elements.add(DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement());
        CxfPayload&lt;SoapHeader&gt; body = <span class="code-keyword">new</span> CxfPayload&lt;SoapHeader&gt;(<span class="code-keyword">new</span> ArrayList&lt;SoapHeader&gt;(),
            elements);
        exchange.getIn().setBody(body);
        exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, 
            <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, <span class="code-quote">"application/octet-stream"</span>)));

        exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, 
            <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> ByteArrayDataSource(MtomTestHelper.requestJpeg, <span class="code-quote">"image/jpeg"</span>)));

    }
    
});

<span class="code-comment">// process response 
</span>
CxfPayload&lt;SoapHeader&gt; out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());

Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt; ns = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;();
ns.put(<span class="code-quote">"ns"</span>, MtomTestHelper.SERVICE_TYPES_NS);
ns.put(<span class="code-quote">"xop"</span>, MtomTestHelper.XOP_NS);

XPathUtils xu = <span class="code-keyword">new</span> XPathUtils(ns);
Element ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:DetailResponse/ns:photo/xop:Include"</span>, out.getBody().get(0),
</span>                                   XPathConstants.NODE);
<span class="code-object">String</span> photoId = ele.getAttribute(<span class="code-quote">"href"</span>).substring(4); <span class="code-comment">// skip <span class="code-quote">"cid:"</span>
</span>
ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:DetailResponse/ns:image/xop:Include"</span>, out.getBody().get(0),
</span>                                   XPathConstants.NODE);
<span class="code-object">String</span> imageId = ele.getAttribute(<span class="code-quote">"href"</span>).substring(4); <span class="code-comment">// skip <span class="code-quote">"cid:"</span>
</span>
DataHandler dr = exchange.getOut().getAttachment(photoId);
Assert.assertEquals(<span class="code-quote">"application/octet-stream"</span>, dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
   
dr = exchange.getOut().getAttachment(imageId);
Assert.assertEquals(<span class="code-quote">"image/jpeg"</span>, dr.getContentType());

BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());

</pre>
</div></div>

<p>You can also consume a Camel message received from a CXF endpoint in Payload mode.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span class="code-keyword">static</span> class MyProcessor <span class="code-keyword">implements</span> Processor {

    @SuppressWarnings(<span class="code-quote">"unchecked"</span>)
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        CxfPayload&lt;SoapHeader&gt; in = exchange.getIn().getBody(CxfPayload.class);
        
        <span class="code-comment">// verify request
</span>        Assert.assertEquals(1, in.getBody().size());
        
        Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt; ns = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;();
        ns.put(<span class="code-quote">"ns"</span>, MtomTestHelper.SERVICE_TYPES_NS);
        ns.put(<span class="code-quote">"xop"</span>, MtomTestHelper.XOP_NS);

        XPathUtils xu = <span class="code-keyword">new</span> XPathUtils(ns);
        Element ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:Detail/ns:photo/xop:Include"</span>, in.getBody().get(0),
</span>                                           XPathConstants.NODE);
        <span class="code-object">String</span> photoId = ele.getAttribute(<span class="code-quote">"href"</span>).substring(4); <span class="code-comment">// skip <span class="code-quote">"cid:"</span>
</span>        Assert.assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);

        ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:Detail/ns:image/xop:Include"</span>, in.getBody().get(0),
</span>                                           XPathConstants.NODE);
        <span class="code-object">String</span> imageId = ele.getAttribute(<span class="code-quote">"href"</span>).substring(4); <span class="code-comment">// skip <span class="code-quote">"cid:"</span>
</span>        Assert.assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);

        DataHandler dr = exchange.getIn().getAttachment(photoId);
        Assert.assertEquals(<span class="code-quote">"application/octet-stream"</span>, dr.getContentType());
        MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
   
        dr = exchange.getIn().getAttachment(imageId);
        Assert.assertEquals(<span class="code-quote">"image/jpeg"</span>, dr.getContentType());
        MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));

        <span class="code-comment">// create response
</span>        List&lt;Element&gt; elements = <span class="code-keyword">new</span> ArrayList&lt;Element&gt;();
        elements.add(DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement());
        CxfPayload&lt;SoapHeader&gt; body = <span class="code-keyword">new</span> CxfPayload&lt;SoapHeader&gt;(<span class="code-keyword">new</span> ArrayList&lt;SoapHeader&gt;(),
            elements);
        exchange.getOut().setBody(body);
        exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID, 
            <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, <span class="code-quote">"application/octet-stream"</span>)));

        exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID, 
            <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> ByteArrayDataSource(MtomTestHelper.responseJpeg, <span class="code-quote">"image/jpeg"</span>)));

    }
}
</pre>
</div></div>

<p><b>Message Mode:</b> Attachments are not supported as it does not process the message at all.</p>


<h2><a name="BookComponentAppendix-CXFBeanComponent%282.0orlater%29"></a>CXF Bean Component (<b>2.0 or later</b>)</h2>

<p>The <b>cxfbean:</b> component allows other Camel endpoints to send exchange and invoke Web service bean objects.  (<b>Currently, it only supports JAXRS, JAXWS(new to camel2.1) annotated service bean.</b>)</p>

<p><b>Note</b>: <tt>CxfBeanEndpoint</tt> is a <tt>ProcessorEndpoint</tt> so it has no consumers.  It works similarly to a Bean component.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxfbean:serviceBeanRef
</pre>
</div></div>
<p>Where <b>serviceBeanRef</b> is a registry key to look up the service bean object. If <tt>serviceBeanRef</tt> references a <tt>List</tt> object, elements of the <tt>List</tt> are the service bean objects accepted by the endpoint.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxfBeanBinding</tt> </td>
<td class='confluenceTd'> CXF bean binding specified by the <tt>&#35;</tt> notation.  The referenced object must be an instance of <tt>org.apache.camel.component.cxf.cxfbean.CxfBeanBinding</tt>. </td>
<td class='confluenceTd'> <tt>cxfBinding=#bindingName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.cxfbean.DefaultCxfBeanBinding</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> CXF bus reference specified by the <tt>&#35;</tt> notation. The referenced object must be an instance of <tt>org.apache.cxf.Bus</tt>. </td>
<td class='confluenceTd'> <tt>bus=#busName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Default bus created by CXF Bus Factory </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> Header filter strategy specified by the <tt>&#35;</tt> notation.  The referenced object must be an instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>. </td>
<td class='confluenceTd'> <tt>headerFilterStrategy=#strategyName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.CxfHeaderFilterStrategy</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> Will set the default bus when CXF endpoint create a bus by itself. </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Headers"></a>Headers</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> In/Out </th>
<th class='confluenceTh'> Examples </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpCharacterEncoding</tt> (before 2.0-m2: <tt>CamelCxfBeanCharacterEncoding</tt>) </td>
<td class='confluenceTd'> Character encoding </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> ISO-8859-1 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelContentType</tt> (before 2.0-m2: <tt>CamelCxfBeanContentType</tt>) </td>
<td class='confluenceTd'> Content type </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> &#42;<b>/</b>&#42; </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>text/xml</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHttpBaseUri <br clear="all" />
(2.0-m3 and before: <tt>CamelCxfBeanRequestBasePath</tt>) </td>
<td class='confluenceTd'> The value of this header will be set in the CXF message as the <tt>Message.BASE_PATH</tt> property.  It is needed by CXF JAX-RS processing.  Basically, it is the scheme, host and port portion of the request URI. </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> The Endpoint URI of the source endpoint in the Camel exchange </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <a href="http://localhost:9000" rel="nofollow">http://localhost:9000</a> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpPath</tt> (before 2.0-m2: <tt>CamelCxfBeanRequestPat</tt>h) </td>
<td class='confluenceTd'> Request URI's path </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>consumer/123</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpMethod</tt> (before 2.0-m2: <tt>CamelCxfBeanVerb</tt>) </td>
<td class='confluenceTd'> RESTful request verb </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>GET</tt>, <tt>PUT</tt>, <tt>POST</tt>, <tt>DELETE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpResponseCode</tt> </td>
<td class='confluenceTd'> HTTP response code </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> No <br clear="all" /> </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> Out <br clear="all" /> </td>
<td class='confluenceTd'> 200 <br clear="all" /> </td>
</tr>
</tbody></table>
<p><b>Note: Currently, CXF Bean component has (only) been tested with Jetty HTTP component it can understand headers from Jetty HTTP component without requiring conversion.</b></p>

<h3><a name="BookComponentAppendix-AWorkingSample"></a>A Working Sample</h3>

<p>This sample shows how to create a route that starts a Jetty HTTP server.  The route sends requests to a CXF Bean and invokes a JAXRS annotated service.</p>

<p>First, create a route as follows.  The <tt>from</tt> endpoint is a Jetty HTTP endpoint that is listening on port 9000.  Notice that the <tt>matchOnUriPrefix</tt> option must be set to <tt>true</tt> because RESTful request URI will not match the endpoint's URI http:­//localhost:9000 exactly.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
	<span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://localhost:9000?matchOnUriPrefix=true"</span> /&gt;</span>
	<span class="code-tag">&lt;to uri=<span class="code-quote">"cxfbean:customerServiceBean"</span> /&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>
<p>The <tt>to</tt> endpoint is a CXF Bean with bean name <tt>customerServiceBean</tt>. The name will be looked up from the registry.  Next, we make sure our service bean is available in Spring registry.  We create a bean definition in the Spring configuration.  In this example, we create a List of service beans (of one element).  We could have created just a single bean without a List.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;util:list id=<span class="code-quote">"customerServiceBean"</span>&gt;</span>
	<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span> /&gt;</span>
<span class="code-tag">&lt;/util:list&gt;</span>

<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.wsdl_first.PersonImpl"</span> id=<span class="code-quote">"jaxwsBean"</span> /&gt;</span>

</pre>
</div></div>
<p>That's it.  Once the route is started, the web service is ready for business.  A HTTP client can make a request and receive response.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">url = <span class="code-keyword">new</span> URL(<span class="code-quote">"http:<span class="code-comment">//localhost:9000/customerservice/orders/223/products/323"</span>);
</span>in = url.openStream();
assertEquals(<span class="code-quote">"{\"</span>Product\<span class="code-quote">":{\"</span>description\<span class="code-quote">":\"</span>product 323\<span class="code-quote">",\"</span>id\<span class="code-quote">":323}}"</span>, CxfUtils.getStringFromInputStream(in));
</pre>
</div></div>
<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-CXFRSComponent"></a>CXFRS Component</h2>

<p>The <b>cxfrs:</b> component provides integration with <a href="http://incubator.apache.org/cxf/" rel="nofollow">Apache CXF</a> for connecting to JAX-RS services hosted in CXF.</p>

<p>Maven users will need to add the following dependency to their pom.xml for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
   &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
   &lt;artifactId&gt;camel-cxf&lt;/artifactId&gt;
   &lt;version&gt;x.x.x&lt;/version&gt;  &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxfrs:<span class="code-comment">//address?options</span>
</pre>
</div></div>
<p>Where <b>address</b> represents the CXF endpoint's address</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxfrs:bean:rsEndpoint
</pre>
</div></div>
<p>Where <b>rsEndpoint</b> represents the spring bean's name which presents the CXFRS client or server</p>

<p>For either style above, you can append options to the URI as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxfrs:bean:cxfEndpoint?resourceClass=org.apache.camel.rs.Example
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> default value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>resourcesClass</tt> </td>
<td class='confluenceTd'> The resource classes which you want to export as REST service </td>
<td class='confluenceTd'> <tt>resourcesClass=org.apache.camel.rs.Example1,org.apache.camel.rs.Exchange2</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientAPI</tt> </td>
<td class='confluenceTd'> <b>new to Camel 2.1</b> If it is true, the CxfRsProducer will use the HttpClientAPI to invoke the service <br/>
If it is false, the CxfRsProducer will use the ProxyClientAPI to invoke the service</td>
<td class='confluenceTd'> httpClientAPI=true  </td>
<td class='confluenceTd'>No </td>
<td class='confluenceTd'> <em>true</em> </td>
</tr>
</tbody></table>

<p>You can also configure the CXF REST endpoint through the spring configuration. Since there are lots of difference between the CXF REST client and CXF REST Server, we provides different configuration for them.<br/>
Please check out the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd" rel="nofollow">schema file</a> and <a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" rel="nofollow">CXF REST user guide</a> for more information.</p>

<h3><a name="BookComponentAppendix-HowtoconfiguretheRESTendpointinCamel%3F"></a>How to configure the REST endpoint in Camel ?</h3>
<p>In <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd" rel="nofollow">camel-cxf schema file</a>, there are two elements for the REST endpoint definition. <b>cxf:rsServer</b> for REST consumer, <b>cxf:rsClient</b> for REST producer.<br/>
You can find an camel REST service route configuration example here.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:cxf</span>=<span class="code-quote">"http://camel.apache.org/schema/cxf"</span>
       <span class="code-keyword">xmlns:jaxrs</span>=<span class="code-quote">"http://cxf.apache.org/jaxrs"</span>
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    "&gt;
  <span class="code-tag"><span class="code-comment">&lt;!-- Defined the real JAXRS back end service  --&gt;</span></span>
  &lt;jaxrs:server id=<span class="code-quote">"restService"</span>
		        address=<span class="code-quote">"http://localhost:9002"</span> 
		        staticSubresourceResolution=<span class="code-quote">"true"</span>&gt;
    <span class="code-tag">&lt;jaxrs:serviceBeans&gt;</span>
      <span class="code-tag">&lt;ref bean=<span class="code-quote">"customerService"</span>/&gt;</span>
    <span class="code-tag">&lt;/jaxrs:serviceBeans&gt;</span>       
  <span class="code-tag">&lt;/jaxrs:server&gt;</span>
  
  <span class="code-tag">&lt;bean id=<span class="code-quote">"jsonProvider"</span> class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.JSONProvider"</span>/&gt;</span>

  <span class="code-tag">&lt;bean id=<span class="code-quote">"customerService"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span> /&gt;</span>
   
  <span class="code-tag"><span class="code-comment">&lt;!-- Defined the server endpoint to create the cxf-rs consumer --&gt;</span></span> 
  &lt;cxf:rsServer id=<span class="code-quote">"rsServer"</span> address=<span class="code-quote">"http://localhost:9000"</span>
    serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span> /&gt;

  <span class="code-tag"><span class="code-comment">&lt;!-- Defined the client endpoint to create the cxf-rs consumer --&gt;</span></span>
  &lt;cxf:rsClient id=<span class="code-quote">"rsClient"</span> address=<span class="code-quote">"http://localhost:9002"</span>
    serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span>/&gt;
  
  <span class="code-tag"><span class="code-comment">&lt;!-- The camel route context --&gt;</span></span>
  <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
       <span class="code-tag">&lt;from uri=<span class="code-quote">"cxfrs://bean://rsServer"</span>/&gt;</span>
       <span class="code-tag"><span class="code-comment">&lt;!-- We can remove this configure as the CXFRS producer is using the HttpAPI by default --&gt;</span></span>
       <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelCxfRsUsingHttpAPI"</span>&gt;</span>
         <span class="code-tag">&lt;constant&gt;</span>True<span class="code-tag">&lt;/constant&gt;</span>        
       <span class="code-tag">&lt;/setHeader&gt;</span>
       <span class="code-tag">&lt;to uri=<span class="code-quote">"cxfrs://bean://rsClient"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>
  
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-HowtoconsumertheRESTrequestinCamel%3F"></a>How to consumer the REST request in Camel ?</h3>
<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" rel="nofollow">CXF JAXRS front end</a> implements the <a href="https://jsr311.dev.java.net/" rel="nofollow">JAXRS(JSR311) API</a>, so we can export the resources classes as a REST service. And we leverage the <a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Invokers" rel="nofollow">CXF Invoker API</a> to turn a REST request into a normal Java object method invocation.<br/>
Unlike the <tt>camel-restlet</tt>, you don't need to specify the URI template within your restlet endpoint, CXF take care of the REST request URI to resource class method mapping according to the JSR311 specification. All you need to do in Camel is delegate this method request to a right processor or endpoint.</p>

<p>Here is an example</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            errorHandler(<span class="code-keyword">new</span> NoErrorHandlerBuilder());
            from(CXF_RS_ENDPOINT_URI).process(<span class="code-keyword">new</span> Processor() {

                <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                    Message inMessage = exchange.getIn();                        
                    <span class="code-comment">// Get the operation name from in message
</span>                    <span class="code-object">String</span> operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, <span class="code-object">String</span>.class);
                    <span class="code-comment">// The parameter of the invocation is stored in the body of in message
</span>                    <span class="code-object">String</span> id = (<span class="code-object">String</span>) inMessage.getBody(<span class="code-object">Object</span>[].class)[0];
                    <span class="code-keyword">if</span> (<span class="code-quote">"getCustomer"</span>.equals(operationName)) {
                        <span class="code-object">String</span> httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, <span class="code-object">String</span>.class);
                        assertEquals(<span class="code-quote">"Get a wrong http method"</span>, <span class="code-quote">"GET"</span>, httpMethod);
                        <span class="code-object">String</span> uri = inMessage.getHeader(Exchange.HTTP_URI, <span class="code-object">String</span>.class);
                        <span class="code-keyword">if</span> (<span class="code-quote">"/customerservice/customers/126"</span>.equals(uri)) {                            
                            Customer customer = <span class="code-keyword">new</span> Customer();
                            customer.setId(<span class="code-object">Long</span>.parseLong(id));
                            customer.setName(<span class="code-quote">"Willem"</span>);
                            <span class="code-comment">// We just put the response <span class="code-object">Object</span> into the out message body
</span>                            exchange.getOut().setBody(customer);
                        } <span class="code-keyword">else</span> {
                            Response r = Response.status(404).entity(<span class="code-quote">"Can't found the customer with uri "</span> + uri).build();
                            <span class="code-keyword">throw</span> <span class="code-keyword">new</span> WebApplicationException(r);
                        }
                    }
                }
                
            });
        }
    };
}
</pre>
</div></div>


<h3><a name="BookComponentAppendix-HowtoinvoketheRESTservicethroughcamelcxfrsproducer%3F"></a>How to invoke the REST service through camel-cxfrs producer ?</h3>
<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" rel="nofollow">CXF JAXRS front end</a> implements <a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-ProxybasedAPI" rel="nofollow">a proxy based client API</a>, with this API you can invoke the remote REST service through a proxy. <br/>
<tt>camel-cxfrs</tt> producer is based on this <a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-ProxybasedAPI" rel="nofollow">proxy API</a>. <br/>
So, you just need to specify the operation name in the message header and prepare the parameter in the message body, camel-cxfrs producer will generate right REST request for you.</p>

<p>Here is an example</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Exchange exchange = template.send(<span class="code-quote">"direct:<span class="code-comment">//proxy"</span>, <span class="code-keyword">new</span> Processor() {
</span>
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        exchange.setPattern(ExchangePattern.InOut);
        Message inMessage = exchange.getIn();
        <span class="code-comment">// set the operation name 
</span>        inMessage.setHeader(CxfConstants.OPERATION_NAME, <span class="code-quote">"getCustomer"</span>);
        <span class="code-comment">// using the proxy client API
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, <span class="code-object">Boolean</span>.FALSE);
        <span class="code-comment">// set the parameters , <span class="code-keyword">if</span> you just have one parameter 
</span>        <span class="code-comment">// camel will put <span class="code-keyword">this</span> object into an <span class="code-object">Object</span>[] itself
</span>        inMessage.setBody(<span class="code-quote">"123"</span>);
    }
    
});
     
<span class="code-comment">// get the response message 
</span>Customer response = (Customer) exchange.getOut().getBody();

assertNotNull(<span class="code-quote">"The response should not be <span class="code-keyword">null</span> "</span>, response);
assertEquals(<span class="code-quote">"Get a wrong customer id "</span>, <span class="code-object">String</span>.valueOf(response.getId()), <span class="code-quote">"123"</span>);
assertEquals(<span class="code-quote">"Get a wrong customer name"</span>, response.getName(), <span class="code-quote">"John"</span>);
</pre>
</div></div> 

<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" rel="nofollow">CXF JAXRS front end</a> also provides <a href="http://cxf.apache.org/docs/jax-rs.html#JAX-RS-HTTPcentricclients" rel="nofollow">a http centric client API</a>, You can also invoke this API from <tt>camel-cxfrs</tt> producer. You need to specify the HTTP_PATH and Http method and let the the producer know to use the http centric client by using the URI option <b>httpClientAPI</b> or set the message header with CxfConstants.CAMEL_CXF_RS_USING_HTTP_API. You can turn the response object to the type class that you specify with CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Exchange exchange = template.send(<span class="code-quote">"direct:<span class="code-comment">//http"</span>, <span class="code-keyword">new</span> Processor() {
</span>
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        exchange.setPattern(ExchangePattern.InOut);
        Message inMessage = exchange.getIn();
        <span class="code-comment">// using the http central client API
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, <span class="code-object">Boolean</span>.TRUE);
        <span class="code-comment">// set the Http method
</span>        inMessage.setHeader(Exchange.HTTP_METHOD, <span class="code-quote">"GET"</span>);
        <span class="code-comment">// set the relative path
</span>        inMessage.setHeader(Exchange.HTTP_PATH, <span class="code-quote">"/customerservice/customers/123"</span>);                
        <span class="code-comment">// Specify the response class , cxfrs will use InputStream as the response object type 
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
        <span class="code-comment">// since we use the Get method, so we don't need to set the message body
</span>        inMessage.setBody(<span class="code-keyword">null</span>);                
    }
    
});
     
<span class="code-comment">// get the response message 
</span>Customer response = (Customer) exchange.getOut().getBody();

assertNotNull(<span class="code-quote">"The response should not be <span class="code-keyword">null</span> "</span>, response);
assertEquals(<span class="code-quote">"Get a wrong customer id "</span>, <span class="code-object">String</span>.valueOf(response.getId()), <span class="code-quote">"123"</span>);
assertEquals(<span class="code-quote">"Get a wrong customer name"</span>, response.getName(), <span class="code-quote">"John"</span>);
</pre>
</div></div> 

<p>From Camel 2.1, we also support to specify the query parameters from cxfrs URI for the CXFRS http centric client.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Exchange exchange = template.send(<span class="code-quote">"cxfrs:<span class="code-comment">//http://localhost:9003/testQuery?httpClientAPI=<span class="code-keyword">true</span>&amp;q1=12&amp;q2=13"</span></span>
</pre>
</div></div> 
<p>To support the Dynamical routing, you can override the URI's query parameters by using the CxfConstants.CAMEL_CXF_RS_QUERY_MAP header to set the parameter map for it.To support the Dynamical routing, you can override the URI's query parameters by using the CxfConstants.CAMEL_CXF_RS_QUERY_MAP header to set the parameter map for it.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt; queryMap = <span class="code-keyword">new</span> LinkedHashMap&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;();                    
queryMap.put(<span class="code-quote">"q1"</span>, <span class="code-quote">"<span class="code-keyword">new</span>"</span>);
queryMap.put(<span class="code-quote">"q2"</span>, <span class="code-quote">"world"</span>);                    
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, queryMap);
</pre>
</div></div> 
<h2><a name="BookComponentAppendix-DataSetComponent"></a>DataSet Component</h2>

<a href="/confluence/display/CAMEL/Testing" title="Testing">Testing</a> of distributed and asynchronous processing is notoriously difficult. The <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a>, <a href="/confluence/display/CAMEL/Test" title="Test">Test</a> and <a href="/confluence/display/CAMEL/DataSet" title="DataSet">DataSet</a> endpoints work great with the <a href="/confluence/display/CAMEL/Testing" title="Testing">Camel Testing Framework</a> to simplify your unit and integration testing using <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise Integration Patterns">Enterprise Integration Patterns</a> and Camel's large range of <a href="/confluence/display/CAMEL/Components" title="Components">Components</a> together with the powerful <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a>.

<p>The DataSet component (available since 1.3.0) provides a mechanism to easily perform load &amp; soak testing of your system. It works by allowing you to create <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/dataset/DataSet.html" rel="nofollow">DataSet instances</a> both as a source of messages and as a way to assert that the data set is received.</p>

<p>Camel will use the <a href="/confluence/display/CAMEL/Log" title="Log">throughput logger</a> when sending dataset's. </p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
dataset:name[?options]
</pre>
</div></div>

<p>Where <b>name</b> is used to find the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/dataset/DataSet.html" rel="nofollow">DataSet instance</a> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a></p>

<p>Camel ships with a support implementation of <tt>org.apache.camel.component.dataset.DataSet</tt>, the <tt>org.apache.camel.component.dataset.DataSetSupport</tt> class, that can be used as a base for implementing your own DataSet. Camel also ships with a default implementation, the <tt>org.apache.camel.component.dataset.SimpleDataSet</tt> that can be used for testing.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>produceDelay</tt> </td>
<td class='confluenceTd'> 3 </td>
<td class='confluenceTd'> Allows a delay in ms to be specified, which causes producers to pause in order to simulate slow producers. Uses a minimum of 3 ms delay unless you set this option to -1 to force no delay at all. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeDelay</tt> </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> Allows a delay in ms to be specified, which causes consumers to pause in order to simulate slow consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preloadSize</tt> </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> Sets how many messages should be preloaded (sent) before the route completes its initialization. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> 1000 </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Time period in millis to wait before starting sending messages. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-ConfiguringDataSet"></a>Configuring DataSet</h3>
<p>Camel will lookup in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> for a bean implementing the DataSet interface. So you can register your own DataSet as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myDataSet"</span> class=<span class="code-quote">"com.mycompany.MyDataSet"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"size"</span> value=<span class="code-quote">"100"</span>/&gt;</span>
   <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>

<p>For example, to test that a set of messages are sent to a queue and then consumed from the queue without losing any messages:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// send the dataset to a queue
</span>from(<span class="code-quote">"dataset:foo"</span>).to(<span class="code-quote">"activemq:SomeQueue"</span>);

<span class="code-comment">// now lets test that the messages are consumed correctly
</span>from(<span class="code-quote">"activemq:SomeQueue"</span>).to(<span class="code-quote">"dataset:foo"</span>);
</pre>
</div></div>

<p>The above would look in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> to find the <b>foo</b> DataSet instance which is used to create the messages.</p>

<p>Then you create a DataSet implementation, such as using the <tt>SimpleDataSet</tt> as described below, configuring things like how big the data set is and what the messages look like etc.</p>

<h3><a name="BookComponentAppendix-PropertiesonSimpleDataSet"></a>Properties on SimpleDataSet</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Property</th>
<th class='confluenceTh'>Type</th>
<th class='confluenceTh'>Description</th>
</tr>
<tr>
<td class='confluenceTd'><tt>defaultBody</tt> </td>
<td class='confluenceTd'> <tt>Object</tt> </td>
<td class='confluenceTd'> Specifies the default message body. For SimpleDataSet it is a constant payload; though if you want to create custom payloads per message, create your own derivation of <tt>DataSetSupport</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'><tt>reportGroup</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> Specifies the number of messages to be received before reporting progress. Useful for showing progress of a large load test.</td>
</tr>
<tr>
<td class='confluenceTd'><tt>size</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'>Specifies how many messages to send/consume.</td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-LoadtestingActiveMQwithCamel"></a>Load testing ActiveMQ with Camel</h3>

<p>There is an example of load testing an ActiveMQ queue using Camel in the <a href="http://activemq.apache.org/" rel="nofollow">ActiveMQ</a> source code repository. The code lives at this location:</p>

<ul>
	<li><a href="https://svn.apache.org/repos/asf/activemq/trunk/activemq-camel-loadtest/" rel="nofollow">https://svn.apache.org/repos/asf/activemq/trunk/activemq-camel-loadtest/</a></li>
</ul>


<p>You can grab the code as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
svn co https:<span class="code-comment">//svn.apache.org/repos/asf/activemq/trunk/activemq-camel-loadtest/</span>
</pre>
</div></div>

<p>Then try running the test case:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cd activemq-camel-loadtest
mvn clean install
</pre>
</div></div>

<p>To see how the test is defined, see the <a href="https://svn.apache.org/repos/asf/activemq/trunk/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/LoadTest-context.xml" rel="nofollow">Spring XML file</a></p>

<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Spring+Testing" title="Spring Testing">Spring Testing</a></li>
</ul>

<h2><a name="BookComponentAppendix-DirectComponent"></a>Direct Component</h2>

<p>The <b>direct:</b> component provides direct, synchronous invocation of any consumers when a producer sends a message exchange.<br/>
This endpoint can be used to connect existing routes in the <b>same</b> camel context.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Asynchronous</b><br /><p>The <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> component provides asynchronous invocation of any consumers when a producer sends a message exchange.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Connection to other camel contexts</b><br /><p>The <a href="/confluence/display/CAMEL/VM" title="VM">VM</a> component provides connections between Camel contexts as long they run in the same <b>JVM</b>.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
direct:someName[?options]
</pre>
</div></div>

<p>Where <b>someName</b> can be any string to uniquely identify the endpoint</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowMultipleConsumers</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b> If set to <tt>false</tt>, then when a second consumer is started on the endpoint, an <tt>IllegalStateException</tt> is thrown. <b>Will be removed in Camel 2.1:</b> Direct endpoint does not support multiple consumers. </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>
<p>In the route below we use the direct component to link the two routes together:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:order.in"</span>).to(<span class="code-quote">"bean:orderServer?method=validate"</span>).to(<span class="code-quote">"direct:processOrder"</span>);

from(<span class="code-quote">"direct:processOrder"</span>).to(<span class="code-quote">"bean:orderService?method=process"</span>).to(<span class="code-quote">"activemq:queue:order.out"</span>);
</pre>
</div></div>

<p>And the sample using spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:queue:order.in"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:orderService?method=validate"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:processOrder"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:processOrder"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:orderService?method=process"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:queue:order.out"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>    
</pre>
</div></div>

<p>See also samples from the <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> component, how they can be used together.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a></li>
	<li><a href="/confluence/display/CAMEL/VM" title="VM">VM</a></li>
</ul>

<h2><a name="BookComponentAppendix-Esper"></a>Esper</h2>

<p>The Esper component supports the <a href="http://esper.codehaus.org" rel="nofollow">Esper Library</a> for Event Stream Processing. The <b>camel-esper</b> library is provided by the <a href="http://code.google.com/p/camel-extra/" rel="nofollow">Camel Extra</a> project which hosts all *GPL related components for Camel.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
esper:name[?options]
</pre>
</div></div>

<p>When consuming from an Esper endpoint you must specify a <b>pattern</b> or <b>eql</b> statement to query the event stream.</p>

<p>For example</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"esper:<span class="code-comment">//cheese?pattern=every event=MyEvent(bar=5)"</span>).
</span>	to(<span class="code-quote">"activemq:Foo"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The <a href="http://esper.codehaus.org/esper-1.11.0/doc/reference/en/html/event_patterns.html" rel="nofollow">Esper Pattern expression</a> as a String to filter events </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eql</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The <a href="http://esper.codehaus.org/esper-1.11.0/doc/reference/en/html/eql_clauses.html" rel="nofollow">Esper EQL expression</a> as a String to filter events </td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Demo"></a>Demo</h3>

<p>There is a <a href="http://code.google.com/p/camel-extra/wiki/EsperDemo" rel="nofollow">demo which shows how to work with ActiveMQ, Camel and Esper</a> in the <a href="http://code.google.com/p/camel-extra/" rel="nofollow">Camel Extra</a> project</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="http://code.google.com/p/camel-extra/wiki/EsperDemo" rel="nofollow">Esper Camel Demo</a></li>
</ul>

<h2><a name="BookComponentAppendix-EventComponent"></a>Event Component</h2>

<p>The <b>event:</b> component provides access to the Spring ApplicationEvent objects. This allows you to publish ApplicationEvent objects to a Spring ApplicationContext or to consume them. You can then use <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise Integration Patterns">Enterprise Integration Patterns</a> to process them such as <a href="/confluence/display/CAMEL/Message+Filter" title="Message Filter">Message Filter</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
spring-event:<span class="code-comment">//<span class="code-keyword">default</span></span>
</pre>
</div></div>

<p>If you use Camel 1.x then you may need to remove the // to get it working with the Spring event notification</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
spring-event:<span class="code-keyword">default</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-FileComponentCamel2.0onwards"></a>File Component - <b>Camel 2.0 onwards</b></h2>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using Camel 1.x</b><br /><p>This documentation is only for Camel 2.0 or newer. If you are using Camel 1.x then see this <a href="/confluence/display/CAMEL/File" title="File">link</a> instead.</p></td></tr></table></div>

<p>The File component provides access to file systems, allowing files to be processed by any other Camel <a href="/confluence/display/CAMEL/Components" title="Components">Components</a> or messages from other components to be saved to disk.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
file:directoryName[?options]
</pre>
</div></div>

<p>or</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
file:<span class="code-comment">//directoryName[?options]</span>
</pre>
</div></div>

<p>Where <b>directoryName</b> represents the underlying file directory.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Only directories</b><br /><p>Camel 2.0 only support endpoints configured with a starting directory. So the <b>directoryName</b> must be a directory.<br/>
If you want to consume a single file only, you can use the <b>fileName</b> option, e.g. by setting <tt>fileName=thefilename</tt>.<br/>
Also, the starting directory must not contain dynamic expressions with ${ } placeholders. Again use the <tt>fileName</tt> option to specify the dynamic part of the filename.</p>

<p>In Camel 1.x you could also configure a file and this caused more harm than good as it could lead to confusing situations.</p></td></tr></table></div>  

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Avoid reading files currently being written by another application</b><br /><p>Beware the JDK File IO API is a bit limited in detecting whether another application is currently writing/copying a file. And the implementation can be different depending on OS platform as well. This could lead to that Camel thinks the file is not locked by another process and start consuming it. Therefore you have to do you own investigation what suites your environment. To help with this Camel provides different <tt>readLock</tt> options that you can use. See also the section <em>Consuming files from folders where others drop files directly</em>.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>

<h4><a name="BookComponentAppendix-Common"></a>Common</h4>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>autoCreate</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Automatically create missing directories in the file's pathname. For the file consumer, that means creating the starting directory. For the file producer, it means the directory to where the files should be written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> 128kb </td>
<td class='confluenceTd'> Write buffer sized in bytes. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename. For consumers, it's used as a filename filter. For producers, it's used to evaluate the filename to write. If an expression is set, it take precedence over the <tt>CamelFileName</tt> header. (<b>Note:</b> The header itself can also be an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>). The expression options support both <tt>String</tt> and <tt>Expression</tt> types. If the expression is a <tt>String</tt> type, it is <b>always</b> evaluated using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. If the expression is an <tt>Expression</tt> type, the specified <tt>Expression</tt> type is used - this allows you, for instance, to use <a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a> expressions. For the consumer, you can use it to filter filenames, so you can for instance consume today's file using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> syntax: <tt>mydata-${date:now:yyyyMMdd}.txt</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flatten</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Flatten is used to flatten the file name path to strip any leading paths, so it's just the file name. This allows you to consume recursively into sub-directories, but when you eg write the files to another directory they will be written in a single directory. Setting this to <tt>true</tt> on the producer enforces that any file name recived in <tt>CamelFileName</tt> header will be stripped for any leading paths. </td>
</tr>
</tbody></table></div>

<h4><a name="BookComponentAppendix-Consumeronly"></a>Consumer only</h4>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before polling the file/directory starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> Milliseconds before the next poll of the file/directory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use fixed delay between pools, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>recursive</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If a directory, will look for files in all the sub-directories as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delete</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, the file will be deleted <b>after</b> it is processed </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>noop</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, the file is not moved or deleted in any way. This option is good for readonly data, or for <a href="/confluence/display/CAMEL/ETL" title="ETL">ETL</a> type requirements. If <tt>noop=true</tt>, Camel will set <tt>idempotent=true</tt> as well, to avoid consuming the same files over and over again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preMove</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving it <b>before</b> processing. For example to move in-progress files into the <tt>order</tt> directory set this value to <tt>order</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>move</tt> </td>
<td class='confluenceTd'> <tt>.camel</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving it <b>after</b> processing. To move files into a <tt>.done</tt> subdirectory just enter <tt>.done</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>moveFailed</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'>  Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving <b>failed files after</b> processing. To move files into a <tt>error</tt> subdirectory just enter <tt>error</tt>. <b>Note:</b> When moving the files to another location it can/will <b>handle</b> the error when you move it to another location so Camel cannot pick up the file again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>include</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Is used to include files, if filename matches the regex pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exclude</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Is used to exclude files, if filename matches the regex pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idempotent</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Option to use the <a href="/confluence/display/CAMEL/Idempotent+Consumer" title="Idempotent Consumer">Idempotent Consumer</a> EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If <tt>noop=true</tt> then idempotent will be enabled as well to avoid consuming the same files over and over again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idempotentRepository</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable repository as a <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html" rel="nofollow">org.apache.camel.processor.idempotent.MessageIdRepository</a> class. Will by default use <tt>MemoryMessageIdRepository</tt> if none is specified and <tt>idempotent</tt> is <tt>true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inProgressRepository</tt> </td>
<td class='confluenceTd'> <tt>memory</tt> </td>
<td class='confluenceTd'> Pluggable in-progress repository as a <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html" rel="nofollow">org.apache.camel.processor.idempotent.MessageIdRepository</a> class. The in-progress repository is used to account the current in progress files being consumed. By default a memory based repository is used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable filter as a <tt>org.apache.camel.component.file.GenericFileFilter</tt> class. Will skip files if filter returns <tt>false</tt> in its <tt>accept()</tt> method. Camel also ships with an <b>ANT path matcher</b> filter in the <tt>camel-spring</tt> component. More details in section below. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sorter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable sorter as a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Comparator.html" rel="nofollow">java.util.Comparator&lt;org.apache.camel.component.file.GenericFile&gt;</a> class. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sortBy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Built-in sort using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. Supports nested sorts, so you can have a sort by file name and as a 2nd group sort by modified date. See sorting section below for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLock</tt> </td>
<td class='confluenceTd'> <tt>markerFile</tt> </td>
<td class='confluenceTd'> Used by consumer, to only poll the files if it has exclusive read-lock on the file (i.e. the file is not in-progress or being written). Camel will wait until the file lock is granted. <br/>
This option provides the build in strategies: 
<ul class="alternate" type="square">
	<li><tt>markerFile</tt> is the behaviour from Camel 1.x, where Camel will create a marker file and hold a lock on the marker file.</li>
	<li><tt>changed</tt> is using file length/modification timestamp to detect whether the file is currently being copied or not. Will at least use 1 sec. to determine this, so this option cannot consume files as fast as the others, but can be more reliable as the JDK IO API cannot always determine whether a file is currently being used by another process. This option is <b>not</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component.</li>
	<li><tt>fileLock</tt> is for using <tt>java.nio.channels.FileLock</tt>. This option is <b>not</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component.</li>
	<li><tt>rename</tt> is for using a try to rename the file as a test if we can get exclusive read-lock.</li>
	<li><tt>none</tt> is for no read locks at all.</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLockTimeout</tt> </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Optional timeout in milliseconds for the read-lock, if supported by the read-lock. If the read-lock could not be granted and the timeout triggered, then Camel will skip the file. At next poll Camel, will try the file again, and this time maybe the read-lock could be granted. Use a value of 0 or lower to indicate forever. In <b>Camel 2.0</b> the default value is 0. In <b>Camel 2.1</b> the default value is 10000. Currently <tt>fileLock</tt>, <tt>changed</tt> and <tt>rename</tt> support the timeout. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exclusiveReadLockStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable read-lock as a <tt>org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy</tt> implementation. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>processStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.apache.camel.component.file.GenericFileProcessStrategy</tt> allowing you to implement your own <tt>readLock</tt> option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special <em>ready</em> file exists. If this option is set then the <tt>readLock</tt> option does not apply. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> An integer that defines the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid having the server read thousands of files as it starts up. Set a value of 0 or negative to disabled it. </td>
</tr>
</tbody></table></div>

<h4><a name="BookComponentAppendix-Defaultbehaviorforfileconsumer"></a>Default behavior for file consumer</h4>
<ul>
	<li>By default the file is locked for the duration of the processing.</li>
	<li>After the route has completed, files are moved into the <tt>.camel</tt> subdirectory, so that they appear to be deleted.</li>
	<li>The File Consumer will always skip any file whose name starts with a dot, such as <tt>.</tt>, <tt>.camel</tt>, <tt>.m2</tt> or <tt>.groovy</tt>.</li>
	<li>Only files (not directories) are matched for valid filename, if options such as: <tt>include</tt> or <tt>exclude</tt> are used.</li>
</ul>


<h4><a name="BookComponentAppendix-Produceronly"></a>Producer only</h4>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileExist</tt> </td>
<td class='confluenceTd'> <tt>Override</tt> </td>
<td class='confluenceTd'> What to do if a file already exists with the same name. The following values can be specified: <b>Override</b>, <b>Append</b>, <b>Fail</b> and <b>Ignore</b>. <tt>Override</tt>, which is the default, replaces the existing file. <tt>Append</tt> adds content to the existing file. <tt>Fail</tt> throws a <tt>GenericFileOperationException</tt>, indicating that there is already an existing file. <tt>Ignore</tt> silently ignores the problem and <b>does not</b> override the existing file, but assumes everything is okay. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tempPrefix</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> when uploading big files. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tempFileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The <b>same</b> as <tt>tempPrefix</tt> option but offering a more fine grained control on the naming of the temporary filename as it uses the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. For example you can do <tt>tempFileName=inprogress-${<a href="file:name.noext" rel="nofollow">file:name.noext</a>}.tmp</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keepLastModified</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Will keep the last modified timestamp from the source file (if any). Will use the <tt>Exchange.FILE_LAST_MODIFIED</tt> header to located the timestamp. This header can contain either a <tt>java.util.Date</tt> or <tt>long</tt> with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. <b>Note:</b> This option only applies to the <b>file</b> producer. You <em>cannot</em> use this option with any of the ftp producers. </td>
</tr>
</tbody></table></div>

<h4><a name="BookComponentAppendix-Defaultbehaviorforfileproducer"></a>Default behavior for file producer</h4>
<ul>
	<li>By default it will override any existing file, if one exist with the same name.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Override is now default</b><br /><p>In Camel 1.x the <tt>Append</tt> is the default for the file producer. We have changed this to <tt>Override</tt> in Camel 2.0 as this is also the default file operation using <tt>java.io.File</tt>.<br/>
And also the default for the FTP library we use in the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">camel-ftp</a> component.</p></td></tr></table></div></li>
</ul>


<h3><a name="BookComponentAppendix-MoveandDeleteoperations"></a>Move and Delete operations</h3>
<p>Any move or delete operations is executed after (post command) the routing has completed; so during processing of the <tt>Exchange</tt> the file is still located in the inbox folder. </p>

<p>Lets illustrate this with an example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"file:<span class="code-comment">//inbox?move=.done"</span>).to(<span class="code-quote">"bean:handleOrder"</span>);</span>
</pre>
</div></div>
<p>When a file is dropped in the <tt>inbox</tt> folder, the file consumer notices this and creates a new <tt>FileExchange</tt> that is routed to the <tt>handleOrder</tt> bean. The bean then processes the <tt>File</tt> object. At this point in time the file is still located in the <tt>inbox</tt> folder. After the bean completes, and thus the route is completed, the file consumer will perform the move operation and move the file to the <tt>.done</tt> sub-folder.</p>

<p>The <b>move</b> and <b>preMove</b> options should be a directory name, which can be either relative or absolute. If relative, the directory is created as a sub-folder from within the folder where the file was consumed. </p>

<p>By default, Camel will move consumed files to the <tt>.camel</tt> sub-folder relative to the directory where the file was consumed.</p>

<p>If you want to delete the file after processing, the route should be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"file:<span class="code-comment">//inobox?delete=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"bean:handleOrder"</span>);</span>
</pre>
</div></div>

<p>We have introduced a <b>pre</b> move operation to move files <b>before</b> they are processed. This allows you to mark which files have been scanned as they are moved to this sub folder before being processed.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"file:<span class="code-comment">//inbox?preMove=inprogress"</span>).to(<span class="code-quote">"bean:handleOrder"</span>);</span>
</pre>
</div></div>

<p>You can combine the <b>pre</b> move and the regular move:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"file:<span class="code-comment">//inbox?preMove=inprogress&amp;move=.done"</span>).to(<span class="code-quote">"bean:handleOrder"</span>);</span>
</pre>
</div></div>
<p>So in this situation, the file is in the <tt>inprogress</tt> folder when being processed and after it's processed, it's moved to the <tt>.done</tt> folder.</p>

<h4><a name="BookComponentAppendix-FinegrainedcontroloverMoveandPreMoveoption"></a>Fine grained control over Move and PreMove option</h4>
<p>The <b>move</b> and <b>preMove</b> option is <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>-based, so we have the full power of the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to do advanced configuration of the directory and name pattern.<br/>
Camel will, in fact, internally convert the directory name you enter into a <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> expression. So when we enter <tt>move=.done</tt> Camel will convert this into: <tt>${<a href="file:parent" rel="nofollow">file:parent</a>}/.done/${<a href="file:onlyname" rel="nofollow">file:onlyname</a></tt>}. This is only done if Camel detects that you have not provided a ${ } in the option value yourself. So when you enter a ${ } Camel will <b>not</b> convert it and thus you have the full power.</p>

<p>So if we want to move the file into a backup folder with today's date as the pattern, we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
move=backup/${date:now:yyyyMMdd}/${file:name}
</pre>
</div></div> 

<h4><a name="BookComponentAppendix-AboutmoveFailed"></a>About moveFailed</h4>
<p>The <tt>moveFailed</tt> option allows you to move files that <b>could not</b> be processed succesfully to another location such as a error folder of your choice. For example to move the files in an error folder with a timestamp you can use <tt>moveFailed=/error/${<a href="file:name.noext" rel="nofollow">file:name.noext</a>}-${date:now:yyyyMMddHHmmssSSS}.${<a href="file:name.ext" rel="nofollow">file:name.ext</a></tt>}.</p>

<p>See more examples at <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a></p>


<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>

<p>The following headers are supported by this component:</p>

<h4><a name="BookComponentAppendix-Fileproduceronly"></a>File producer only</h4>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileName</tt> </td>
<td class='confluenceTd'> Specifies the name of the file to write (relative to the endpoint directory). The name can be a <tt>String</tt>; a <tt>String</tt> with a <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> or <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> expression; or an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> object. If it's <tt>null</tt> then Camel will auto-generate a filename based on the message unique ID.  </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-Fileconsumeronly"></a>File consumer only</h4>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileName</tt> </td>
<td class='confluenceTd'> Name of the consumed file as a relative file path with offset from the starting directory configured on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileNameOnly</tt> </td>
<td class='confluenceTd'> Only the file name (the name with no leading paths). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileNameProduced</tt> </td>
<td class='confluenceTd'> The actual absolute filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users with the name of the file that was written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileAbsolute</tt> </td>
<td class='confluenceTd'> A <tt>boolean</tt> option specifying whether the consumed file denotes an absolute path or not. Should normally be <tt>false</tt> for relative paths. Absolute paths should normally not be used but we added to the move option to allow moving files to absolute paths. But can be used elsewhere as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileAbsolutePath</tt> </td>
<td class='confluenceTd'> The absolute path to the file. For relative files this path holds the relative path instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFilePath</tt> </td>
<td class='confluenceTd'> The file path. For relative files this is the starting directory + the relative filename. For absolute files this is the absolute path. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileRelativePath</tt> </td>
<td class='confluenceTd'> The relative path. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileParent</tt> </td>
<td class='confluenceTd'> The parent path. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileLength</tt> </td>
<td class='confluenceTd'> A <tt>long</tt> value containing the file size. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileLastModified</tt> </td>
<td class='confluenceTd'> A <tt>Date</tt> value containing the last modified timestamp of the file. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-BatchConsumer"></a>Batch Consumer</h3>
<p>This component implements the <a href="/confluence/display/CAMEL/Batch+Consumer" title="Batch Consumer">Batch Consumer</a>. </p>

<h4><a name="BookComponentAppendix-ExchangeProperties%2Cfileconsumeronly"></a>Exchange Properties, file consumer only</h4>
<p>As the file consumer is <tt>BatchConsumer</tt> it supports batching the files it polls. By batching it means that Camel will add some properties to the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> so you know the number of files polled the current index in that order.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelBatchSize</tt> </td>
<td class='confluenceTd'> The total number of files that was polled in this batch. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelBatchIndex</tt> </td>
<td class='confluenceTd'> The current index of the batch. Starts from 0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelBatchComplete</tt> </td>
<td class='confluenceTd'> A <tt>boolean</tt> value indicating the last <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> in the batch. Is only <tt>true</tt> for the last entry. </td>
</tr>
</tbody></table>

<p>This allows you for instance to know how many files exists in this batch and for instance let the <a href="/confluence/display/CAMEL/Aggregator" title="Aggregator">Aggregator</a> aggregate this number of files.</p>


<h3><a name="BookComponentAppendix-Commongotchaswithfolderandfilenames"></a>Common gotchas with folder and filenames</h3>

<p>When Camel is producing files (writing files) there are a few gotchas affecting how to set a filename of your choice. By default, Camel will use the message ID as the filename, and since the message ID is normally a unique generated ID, you will end up with filenames such as: <tt>ID-MACHINENAME-2443-1211718892437-1-0</tt>. If such a filename is not desired, then you must provide a filename in the <tt>CamelFileName</tt> message header. The constant, <tt>Exchange.FILE_NAME</tt>, can also be used. </p>

<p>The sample code below produces files using the message ID as the filename:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:report"</span>).to(<span class="code-quote">"file:target/reports"</span>);
</pre>
</div></div>
<p>To use <tt>report.txt</tt> as the filename you have to do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:report"</span>).setHeader(Exchange.FILE_NAME, constant(<span class="code-quote">"report.txt"</span>)).to( <span class="code-quote">"file:target/reports"</span>);
</pre>
</div></div>
<p>... the same as above, but with <tt>CamelFileName</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:report"</span>).setHeader(<span class="code-quote">"CamelFileName"</span>, constant(<span class="code-quote">"report.txt"</span>)).to( <span class="code-quote">"file:target/reports"</span>);
</pre>
</div></div>
<p>And a syntax where we set the filename on the endpoint with the <b>fileName</b> URI option.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:report"</span>).to(<span class="code-quote">"file:target/reports/?fileName=report.txt"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-FilenameExpression"></a>Filename Expression</h3>
<p>Filename can be set either using the <b>expression</b> option or as a string-based <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> expression in the <tt>CamelFileName</tt> header. See the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> for syntax and samples.</p>

<h3><a name="BookComponentAppendix-Consumingfilesfromfolderswhereothersdropfilesdirectly"></a>Consuming files from folders where others drop files directly</h3>
<p>Beware if you consume files from a folder where other applications write files directly. Take a look at the different <tt>readLock</tt> options to see what suits your use cases. The best approach is however to write to another folder and after the write move the file in the drop folder. However if you write files directly to the drop folder then the option <tt>changed</tt> could better detect whether a file is currently being written/copied as it uses a file changed algorithm to see whether the file size / modification changes over a period of time. The other read lock options rely on Java File API that sadly is not always very good at detecting this. </p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<h4><a name="BookComponentAppendix-Readfromadirectoryandwritetoanotherdirectory"></a>Read from a directory and write to another directory</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/?delete=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"file://outputdir"</span>)</span>
</pre>
</div></div>

<p>Listen on a directory and create a message for each file dropped there. Copy the contents to the <tt>outputdir</tt> and delete the file in the <tt>inputdir</tt>.</p>

<h4><a name="BookComponentAppendix-Readingrecursivefromadirectoryandwritetheanother"></a>Reading recursive from a directory and write the another</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/?recursive=<span class="code-keyword">true</span>&amp;delete=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"file://outputdir"</span>)</span>
</pre>
</div></div>

<p>Listen on a directory and create a message for each file dropped there. Copy the contents to the <tt>outputdir</tt> and delete the file in the <tt>inputdir</tt>. Will scan recursively into sub-directories. Will lay out the files in the same directory structure in the <tt>outputdir</tt> as the <tt>inputdir</tt>, including any sub-directories.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
inputdir/foo.txt
inputdir/sub/bar.txt
</pre>
</div></div>
<p>Will result in the following output layout:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
outputdir/foo.txt
outputdir/sub/bar.txt
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Usingflatten"></a>Using flatten</h5>
<p>If you want to store the files in the outputdir directory in the same directory, disregarding the source directory layout (e.g. to flatten out the path), you just add the <tt>flatten=true</tt> option on the file producer side:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/?recursive=<span class="code-keyword">true</span>&amp;delete=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"file://outputdir?flatten=<span class="code-keyword">true</span>"</span>)</span>
</pre>
</div></div>
<p>Will result in the following output layout:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
outputdir/foo.txt
outputdir/bar.txt
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Readingfromadirectoryandthedefaultmoveoperation"></a>Reading from a directory and the default move operation</h4>
<p>Camel will by default move any processed file into a <tt>.camel</tt> subdirectory in the directory the file was consumed from. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/?recursive=<span class="code-keyword">true</span>&amp;delete=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"file://outputdir"</span>)</span>
</pre>
</div></div>
<p>Affects the layout as follows:<br/>
<b>before</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
inputdir/foo.txt
inputdir/sub/bar.txt
</pre>
</div></div>

<p><b>after</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
inputdir/.camel/foo.txt
inputdir/sub/.camel/bar.txt
outputdir/foo.txt
outputdir/sub/bar.txt
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Readfromadirectoryandprocessthemessageinjava"></a>Read from a directory and process the message in java </h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>  <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
    <span class="code-object">Object</span> body = exchange.getIn().getBody();
    <span class="code-comment">// <span class="code-keyword">do</span> some business logic with the input body
</span>  }
});
</pre>
</div></div>

<p>The body will be a <tt>File</tt> object that points to the file that was just dropped into the <tt>inputdir</tt> directory.</p>

<h4><a name="BookComponentAppendix-Readfilesfromadirectoryandsendthecontenttoajmsqueue"></a>Read files from a directory and send the content to a jms queue</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inputdir/"</span>).convertBodyTo(<span class="code-object">String</span>.class).to(<span class="code-quote">"jms:test.queue"</span>)</span>
</pre>
</div></div>

<p>By default the file endpoint sends a <tt>FileMessage</tt> which contains a <tt>File</tt> object as the body. If you send this directly to the JMS component the JMS message will only contain the <tt>File</tt> object but not the content. By converting the <tt>File</tt> to a <tt>String</tt>, the message will contain the file contents what is probably what you want.</p>

<p>The route above using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
      <span class="code-tag">&lt;from uri=<span class="code-quote">"file://inputdir/"</span>/&gt;</span>
      <span class="code-tag">&lt;convertBodyTo type=<span class="code-quote">"java.lang.String"</span>/&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"jms:test.queue"</span>/&gt;</span>
   <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>



<h4><a name="BookComponentAppendix-Writingtofiles"></a>Writing to files</h4>
<p>Camel is of course also able to write files, i.e. produce files. In the sample below we receive some reports on the SEDA queue that we processes before they are written to a directory.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> void testToFile() <span class="code-keyword">throws</span> Exception {
    MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
    mock.expectedMessageCount(1);
    mock.expectedFileExists(<span class="code-quote">"target/test-reports/report.txt"</span>);

    template.sendBody(<span class="code-quote">"direct:reports"</span>, <span class="code-quote">"This is a great report"</span>);

    assertMockEndpointsSatisfied();
}

<span class="code-keyword">protected</span> JndiRegistry createRegistry() <span class="code-keyword">throws</span> Exception {
    <span class="code-comment">// bind our processor in the registry with the given id
</span>    JndiRegistry reg = <span class="code-keyword">super</span>.createRegistry();
    reg.bind(<span class="code-quote">"processReport"</span>, <span class="code-keyword">new</span> ProcessReport());
    <span class="code-keyword">return</span> reg;
}

<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// the reports from the seda queue is processed by our processor
</span>            <span class="code-comment">// before they are written to files in the target/reports directory
</span>            from(<span class="code-quote">"direct:reports"</span>).processRef(<span class="code-quote">"processReport"</span>).to(<span class="code-quote">"file:<span class="code-comment">//target/test-reports"</span>, <span class="code-quote">"mock:result"</span>);
</span>        }
    };
}

<span class="code-keyword">private</span> class ProcessReport <span class="code-keyword">implements</span> Processor {

    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
        <span class="code-comment">// <span class="code-keyword">do</span> some business logic here
</span>
        <span class="code-comment">// set the output to the file
</span>        exchange.getOut().setBody(body);

        <span class="code-comment">// set the output filename using java code logic, notice that <span class="code-keyword">this</span> is done by setting
</span>        <span class="code-comment">// a special header property of the out exchange
</span>        exchange.getOut().setHeader(Exchange.FILE_NAME, <span class="code-quote">"report.txt"</span>);
    }

}
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Writetosubdirectoryusing%7B%7BExchange.FILENAME%7D%7D"></a>Write to subdirectory using <tt>Exchange.FILE_NAME</tt></h4>
<p>Using a single route, it is possible to write a file to any number of subdirectories. If you have a route setup as such:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  &lt;route&gt;
    &lt;from uri=<span class="code-quote">"bean:myBean"</span>/&gt;
    &lt;to uri=<span class="code-quote">"file:/rootDirectory"</span>/&gt;
  &lt;/route&gt; 
</pre>
</div></div>

<p>You can have <tt>myBean</tt> set the header <tt>Exchange.FILE_NAME</tt> to values such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Exchange.FILE_NAME = hello.txt =&gt; /rootDirectory/hello.txt
Exchange.FILE_NAME = foo/bye.txt =&gt; /rootDirectory/foo/bye.txt 
</pre>
</div></div>

<p>This allows you to have a single route to write files to multiple destinations.</p>

<h4><a name="BookComponentAppendix-Usingexpressionforfilenames"></a>Using expression for filenames</h4>

<p>In this sample we want to move consumed files to a backup folder using today's date as a sub-folder name:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inbox?move=backup/${date:now:yyyyMMdd}/${file:name}"</span>).to(<span class="code-quote">"..."</span>);</span>
</pre>
</div></div>

<p>See <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> for more samples.</p>

<h3><a name="BookComponentAppendix-Avoidingreadingthesamefilemorethanonce%28idempotentconsumer%29"></a>Avoiding reading the same file more than once (idempotent consumer)</h3>
<p>Camel supports <a href="/confluence/display/CAMEL/Idempotent+Consumer" title="Idempotent Consumer">Idempotent Consumer</a> directly within the component so it will skip already processed files. This feature can be enabled by setting the <tt>idempotent=true</tt> option.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inbox?idempotent=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"..."</span>);</span>
</pre>
</div></div>

<p>By default Camel uses a in memory based store for keeping track of consumed files, it uses a least recently used cache storing holding up to 1000 entries. You can plugin your own implementation of this store by using the <tt>idempotentRepository</tt> option using the <tt>&#35;</tt> sign in the value to indicate it's a referring to a bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> with the specified <tt>id</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag"><span class="code-comment">&lt;!-- define our store as a plain spring bean --&gt;</span></span>
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myStore"</span> class=<span class="code-quote">"com.mycompany.MyIdempotentStore"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"file://inbox?idempotent=true&amp;amp;idempotentRepository=#myStore"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>Camel will log at <tt>DEBUG</tt> level if it skips a file because it has been consumed before:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
DEBUG FileConsumer is idempotent and the file has been consumed before. Will skip <span class="code-keyword">this</span> file: target\idempotent\report.txt
</pre>
</div></div>


<h4><a name="BookComponentAppendix-Usingafilebasedidempotentrepository"></a>Using a file based idempotent repository</h4>
<p>In this section we will use the file based idempotent repository <tt>org.apache.camel.processor.idempotent.FileIdempotentRepository</tt> instead of the in-memory based that is used as default. <br/>
This repository uses a 1st level cache to avoid reading the file repository. It will only use the file repository to store the content of the 1st level cache. Thereby the repository can survive server restarts. It will load the content of the file into the 1st level cache upon startup. The file structure is very simple as it store the key in separate lines in the file. By default, the file store has a size limit of 1mb when the file grew larger Camel will truncate the file store be rebuilding the content by flushing the 1st level cache in a fresh empty file.</p>

<p>We configure our repository using Spring XML creating our file idempotent repository and define our file consumer to use our repository with the <tt>idempotentRepository</tt> using <tt>&#35;</tt> sign to indicate <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> lookup:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- this is our file based idempotent store configured to use the .filestore.dat as file --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"fileStore"</span> class=<span class="code-quote">"org.apache.camel.processor.idempotent.FileIdempotentRepository"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- the filename for the store --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"fileStore"</span> value=<span class="code-quote">"target/fileidempotent/.filestore.dat"</span>/&gt;</span>
    &lt;!-- the max filesize in bytes for the file. Camel will trunk and flush the cache
         if the file gets bigger --&gt;
    <span class="code-tag">&lt;property name=<span class="code-quote">"maxFileStoreSize"</span> value=<span class="code-quote">"512000"</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- the number of elements in our store --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"cacheSize"</span> value=<span class="code-quote">"250"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"file://target/fileidempotent/?idempotent=true&amp;amp;idempotentRepository=#fileStore&amp;amp;move=done/${file:name}"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>


<h4><a name="BookComponentAppendix-UsingaJPAbasedidempotentrepository"></a>Using a JPA based idempotent repository</h4>
<p>In this section we will use the JPA based idempotent repository instead of the in-memory based that is used as default. </p>

<p>First we need a persistence-unit in <tt>META-INF/persistence.xml</tt> where we need to use the class <tt>org.apache.camel.processor.idempotent.jpa.MessageProcessed</tt> as model.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;persistence-unit name=<span class="code-quote">"idempotentDb"</span> transaction-type=<span class="code-quote">"RESOURCE_LOCAL"</span>&gt;</span>
  <span class="code-tag">&lt;class&gt;</span>org.apache.camel.processor.idempotent.jpa.MessageProcessed<span class="code-tag">&lt;/class&gt;</span>

  <span class="code-tag">&lt;properties&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"openjpa.ConnectionURL"</span> value=<span class="code-quote">"jdbc:derby:target/idempotentTest;create=true"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"openjpa.ConnectionDriverName"</span> value=<span class="code-quote">"org.apache.derby.jdbc.EmbeddedDriver"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"openjpa.jdbc.SynchronizeMappings"</span> value=<span class="code-quote">"buildSchema"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"openjpa.Log"</span> value=<span class="code-quote">"DefaultLevel=WARN, Tool=INFO"</span>/&gt;</span>
  <span class="code-tag">&lt;/properties&gt;</span>
<span class="code-tag">&lt;/persistence-unit&gt;</span>
</pre>
</div></div>

<p>Then we need to setup a Spring <tt>jpaTemplate</tt> in the spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- this is standard spring JPA configuration --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpaTemplate"</span> class=<span class="code-quote">"org.springframework.orm.jpa.JpaTemplate"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"entityManagerFactory"</span> ref=<span class="code-quote">"entityManagerFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"entityManagerFactory"</span> class=<span class="code-quote">"org.springframework.orm.jpa.LocalEntityManagerFactoryBean"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- we use idempotentDB as the persitence unit name defined in the persistence.xml file --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"persistenceUnitName"</span> value=<span class="code-quote">"idempotentDb"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>And finally we can create our JPA idempotent repository in the spring XML file as well:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- we define our jpa based idempotent repository we want to use in the file consumer --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpaStore"</span> class=<span class="code-quote">"org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- Here we refer to the spring jpaTemplate --&gt;</span></span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"jpaTemplate"</span>/&gt;</span>
    &lt;!-- This 2nd parameter is the name  (= a cateogry name).
         You can have different repositories with different names --&gt;
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"1"</span> value=<span class="code-quote">"FileConsumer"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>And yes then we just need to refer to the <b>jpaStore</b> bean in the file consumer endpoint using the [[idempotentRepository}} using the <tt>&#35;</tt> syntax option:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"file://inbox?idempotent=true&amp;amp;idempotentRepository=#jpaStore"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Filterusingorg.apache.camel.component.file.GenericFileFilter"></a>Filter using org.apache.camel.component.file.GenericFileFilter</h3>
<p>Camel supports pluggable filtering strategies. You can then configure the endpoint with such a filter to skip certain files being processed.</p>

<p>In the sample we have build our own filter that skips files starting with <tt>skip</tt> in the filename:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyFileFilter <span class="code-keyword">implements</span> GenericFileFilter {
    <span class="code-keyword">public</span> <span class="code-object">boolean</span> accept(GenericFile pathname) {
        <span class="code-comment">// we dont accept any files starting with skip in the name
</span>        <span class="code-keyword">return</span> !pathname.getFileName().startsWith(<span class="code-quote">"skip"</span>);
    }
}
</pre>
</div></div>

<p>And then we can configure our route using the <b>filter</b> attribute to reference our filter (using <tt>&#35;</tt> notation) that we have defines in the spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag"><span class="code-comment">&lt;!-- define our sorter as a plain spring bean --&gt;</span></span>
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myFilter"</span> class=<span class="code-quote">"com.mycompany.MyFileSorter"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"file://inbox?filter=#myFilter"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-FilteringusingANTpathmatcher"></a>Filtering using ANT path matcher</h4>
<p>The ANT path matcher is shipped out-of-the-box in the <b>camel-spring</b> jar. So you need to depend on <b>camel-spring</b> if you are using Maven.<br/>
The reasons is that we leverage Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html" rel="nofollow">AntPathMatcher</a> to do the actual matching.</p>

<p>The file paths is matched with the following rules:</p>
<ul class="alternate" type="square">
	<li><tt>?</tt> matches one character</li>
	<li><tt>*</tt> matches zero or more characters</li>
	<li><tt>**</tt> matches zero or more directories in a path</li>
</ul>


<p>The sample below demonstrates how to use it:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- use myFilter as filter to allow setting ANT paths for which files to scan for --&gt;</span></span>
    <span class="code-tag">&lt;endpoint id=<span class="code-quote">"myFileEndpoint"</span> uri=<span class="code-quote">"file://target/antpathmatcher?recursive=true&amp;amp;filter=#myAntFilter"</span>/&gt;</span>

    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from ref=<span class="code-quote">"myFileEndpoint"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- we use the antpath file filter to use ant paths for includes and exlucde --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"myAntFilter"</span> class=<span class="code-quote">"org.apache.camel.component.file.AntPathMatcherGenericFileFilter"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- include and file in the subfolder that has day in the name --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"includes"</span> value=<span class="code-quote">"**/subfolder/**/*day*"</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple excludes --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"excludes"</span> value=<span class="code-quote">"**/*bad*,**/*.xml"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SortingusingComparator"></a>Sorting using Comparator</h3>
<p>Camel supports pluggable sorting strategies. This strategy it to use the build in <tt>java.util.Comparator</tt> in Java. You can then configure the endpoint with such a comparator and have Camel sort the files before being processed.</p>

<p>In the sample we have built our own comparator that just sorts by file name:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyFileSorter <span class="code-keyword">implements</span> Comparator&lt;GenericFile&gt; {
    <span class="code-keyword">public</span> <span class="code-object">int</span> compare(GenericFile o1, GenericFile o2) {
        <span class="code-keyword">return</span> o1.getFileName().compareToIgnoreCase(o2.getFileName());
    }
}
</pre>
</div></div>

<p>And then we can configure our route using the <b>sorter</b> option to reference to our sorter (<tt>mySorter</tt>) we have defined in the spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag"><span class="code-comment">&lt;!-- define our sorter as a plain spring bean --&gt;</span></span>
   <span class="code-tag">&lt;bean id=<span class="code-quote">"mySorter"</span> class=<span class="code-quote">"com.mycompany.MyFileSorter"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"file://inbox?sorter=#mySorter"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>URI options can reference beans using the # syntax</b><br /><p>In the Spring DSL route about notice that we can refer to beans in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> by prefixing the id with <tt>&#35;</tt>. So writing <tt>sorter=#mySorter</tt>, will instruct Camel to go look in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> for a bean with the ID, <tt>mySorter</tt>.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-SortingusingsortBy"></a>Sorting using sortBy</h3>
<p>Camel supports pluggable sorting strategies. This strategy it to use the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to configure the sorting. The <tt>sortBy</tt> option is configured as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=group 1;group 2;group 3;...
</pre>
</div></div>
<p>Where each group is separated with semi colon. In the simple situations you just use one group, so a simple example could be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=file:name
</pre>
</div></div>
<p>This will sort by file name, you can reverse the order by prefixing <tt>reverse:</tt> to the group, so the sorting is now Z..A:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=reverse:file:name
</pre>
</div></div>
<p>As we have the full power of <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> we can use some of the other parameters, so if we want to sort by file size we do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=file:size
</pre>
</div></div>

<p>You can configure to ignore the case, using <tt>ignoreCase:</tt> for string comparison, so if you want to use file name sorting but to ignore the case then we do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=ignoreCase:file:name
</pre>
</div></div>
<p>You can combine ignore case and reverse, however reverse must be specified first:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=reverse:ignoreCase:file:name
</pre>
</div></div>

<p>In the sample below we want to sort by last modified file, so we do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=file:modifed
</pre>
</div></div>
<p>And then we want to group by name as a 2nd option so files with same modifcation is sorted by name:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=file:modifed;file:name
</pre>
</div></div>
<p>Now there is an issue here, can you spot it? Well the modified timestamp of the file is too fine as it will be in milliseconds, but what if we want to sort by date only and then subgroup by name?<br/>
Well as we have the true power of <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> we can use the its date command that supports patterns. So this can be solved as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=date:file:yyyyMMdd;file:name
</pre>
</div></div>
<p>Yeah, that is pretty powerful, oh by the way you can also use reverse per group, so we could reverse the file names:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sortBy=date:file:yyyyMMdd;reverse:file:name
</pre>
</div></div>

<h3><a name="BookComponentAppendix-UsingGenericFileProcessStrategy"></a>Using GenericFileProcessStrategy</h3>
<p>The option <tt>processStrategy</tt> can be used to use a custom <tt>GenericFileProcessStrategy</tt> that allows you to implement your own <em>begin</em>, <em>commit</em> and <em>rollback</em> logic.<br/>
For instance lets assume a system writes a file in a folder you should consume. But you should not start consuming the file before another <em>ready</em> file have been written as well.</p>

<p>So by implementing our own <tt>GenericFileProcessStrategy</tt> we can implement this as:</p>
<ul class="alternate" type="square">
	<li>In the <tt>begin()</tt> method we can test whether the special <em>ready</em> file exists. The begin method returns a <tt>boolean</tt> to indicate if we can consume the file or not.</li>
	<li>in the <tt>commit()</tt> method we can move the actual file and also delete the <em>ready</em> file.</li>
</ul>


<h3><a name="BookComponentAppendix-Debuglogging"></a>Debug logging</h3>
<p>This component has log level <b>TRACE</b> that can be helpful if you have problems.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a></li>
	<li><a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP2</a></li>
</ul>

<h2><a name="BookComponentAppendix-FlatpackComponent"></a>Flatpack Component</h2>

<p>The Flatpack component supports fixed width and delimited file parsing via the <a href="http://flatpack.sourceforge.net" rel="nofollow">FlatPack library</a>.<br/>
<b>Notice:</b> This component only supports consuming from flatpack files to Object model. You can not (yet) write from Object model to flatpack format.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
flatpack:[delim|fixed]:flatPackConfig.pzmap.xml[?options]
</pre>
</div></div>

<p>Or for a delimited file handler with no configuration file just use</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
flatpack:someName[?options]
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>delimiter</tt> </td>
<td class='confluenceTd'> <tt>,</tt> </td>
<td class='confluenceTd'> The default character delimiter for delimited files.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textQualifier</tt> </td>
<td class='confluenceTd'> <tt>"</tt> </td>
<td class='confluenceTd'> The text qualifier for delimited files.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreFirstRecord</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the first line is ignored for delimited files (for the column headers).</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitRows</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> As of Camel 1.5, the component can either process each row one by one or the entire content at once. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Examples"></a>Examples</h3>

<ul>
	<li><tt>flatpack:fixed:foo.pzmap.xml</tt> creates a fixed-width endpoint using the <tt>foo.pzmap.xml</tt> file configuration.</li>
	<li><tt>flatpack:delim:bar.pzmap.xml</tt> creates a delimited endpoint using the <tt>bar.pzmap.xml</tt> file configuration.</li>
	<li><tt>flatpack:foo</tt> creates a delimited endpoint called <tt>foo</tt> with no file configuration.</li>
</ul>


<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel will store the following headers on the IN message:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelFlatpackCounter</tt> </td>
<td class='confluenceTd'> The current row index. For <tt>splitRows=false</tt> the counter is the total number of rows. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageBody"></a>Message Body</h3>
<p>The component delivers the data in the IN message as a <tt>org.apache.camel.component.flatpack.DataSetList</tt> object that has converters for <tt>java.util.Map</tt> or <tt>java.util.List</tt>.<br/>
Usually you want the <tt>Map</tt> if you process one row at a time (<tt>splitRows=true</tt>). Use <tt>List</tt> for the entire content (<tt>splitRows=false</tt>), where each element in the list is a <tt>Map</tt>.<br/>
Each <tt>Map</tt> contains the key for the column name and its corresponding value.</p>

<p>For example to get the firstname from the sample below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  Map row = exchange.getIn().getBody(Map.class);
  <span class="code-object">String</span> firstName = row.get(<span class="code-quote">"FIRSTNAME"</span>);
</pre>
</div></div>

<p>However, you can also always get it as a <tt>List</tt> (even for <tt>splitRows=true</tt>). The same example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  List data = exchange.getIn().getBody(List.class);
  Map row = (Map)data.get(0);
  <span class="code-object">String</span> firstName = row.get(<span class="code-quote">"FIRSTNAME"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HeaderandTrailerrecords"></a>Header and Trailer records</h3>
<p>In Camel 1.5 onwards the header and trailer notions in Flatpack are supported. However, you <b>must</b> use fixed record IDs:</p>
<ul>
	<li><tt>header</tt> for the header record (must be lowercase)</li>
	<li><tt>trailer</tt> for the trailer record (must be lowercase)</li>
</ul>


<p>The example below illustrates this fact that we have a header and a trailer. You can omit one or both of them if not needed. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;RECORD id=<span class="code-quote">"header"</span> startPosition=<span class="code-quote">"1"</span> endPosition=<span class="code-quote">"3"</span> indicator=<span class="code-quote">"HBT"</span>&gt;</span>
        <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"INDICATOR"</span> length=<span class="code-quote">"3"</span>/&gt;</span>
        <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"DATE"</span> length=<span class="code-quote">"8"</span>/&gt;</span>
    <span class="code-tag">&lt;/RECORD&gt;</span>

    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"FIRSTNAME"</span> length=<span class="code-quote">"35"</span> /&gt;</span>
    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"LASTNAME"</span> length=<span class="code-quote">"35"</span> /&gt;</span>
    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"ADDRESS"</span> length=<span class="code-quote">"100"</span> /&gt;</span>
    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"CITY"</span> length=<span class="code-quote">"100"</span> /&gt;</span>
    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"STATE"</span> length=<span class="code-quote">"2"</span> /&gt;</span>
    <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"ZIP"</span> length=<span class="code-quote">"5"</span> /&gt;</span>

    <span class="code-tag">&lt;RECORD id=<span class="code-quote">"trailer"</span> startPosition=<span class="code-quote">"1"</span> endPosition=<span class="code-quote">"3"</span> indicator=<span class="code-quote">"FBT"</span>&gt;</span>
        <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"INDICATOR"</span> length=<span class="code-quote">"3"</span>/&gt;</span>
        <span class="code-tag">&lt;COLUMN name=<span class="code-quote">"STATUS"</span> length=<span class="code-quote">"7"</span>/&gt;</span>
    <span class="code-tag">&lt;/RECORD&gt;</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Usingtheendpoint"></a>Using the endpoint</h3>

<p>A common use case is sending a file to this endpoint for further processing in a separate route. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  &lt;camelContext xmlns=<span class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span>&gt;
</span>    &lt;route&gt;
      &lt;from uri=<span class="code-quote">"file:<span class="code-comment">//someDirectory"</span>/&gt;
</span>      &lt;to uri=<span class="code-quote">"flatpack:foo"</span>/&gt;
    &lt;/route&gt;

    &lt;route&gt;
      &lt;from uri=<span class="code-quote">"flatpack:foo"</span>/&gt;
      ...
    &lt;/route&gt;
  &lt;/camelContext&gt;
</pre>
</div></div>

<p>You can also convert the payload of each message created to a <tt>Map</tt> for easy <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a></p>

<h2><a name="BookComponentAppendix-FlatpackDataFormat"></a>Flatpack DataFormat</h2>
<p>The <a href="/confluence/display/CAMEL/Flatpack" title="Flatpack">Flatpack</a> component ships with the Flatpack data format that can be used to format between fixed width or delimited text messages to a <tt>List</tt> of rows as <tt>Map</tt>. </p>
<ul class="alternate" type="square">
	<li>marshal = from <tt>List&lt;Map&lt;String, Object&gt;&gt;</tt> to <tt>OutputStream</tt> (can be converted to <tt>String</tt>)</li>
	<li>unmarshal = from <tt>java.io.InputStream</tt> (such as a <tt>File</tt> or <tt>String</tt>) to a <tt>java.util.List</tt> as an <tt>org.apache.camel.component.flatpack.DataSetList</tt> instance.<br/>
The result of the operation will contain all the data. If you need to process each row one by one you can split the exchange, using <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a>.</li>
</ul>


<p><b>Notice:</b> The Flatpack library does currently not support header and trailers for the marshal operation.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<p>The data format has the following options:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>definition</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The flatpack pzmap configuration file. Can be omitted in simpler situations, but its preferred to use the pzmap. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fixed</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Delimited or fixed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreFirstRecord</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the first line is ignored for delimited files (for the column headers). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textQualifier</tt> </td>
<td class='confluenceTd'> <tt>"</tt> </td>
<td class='confluenceTd'> If the text is qualified with a char such as <tt>"</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delimiter</tt> </td>
<td class='confluenceTd'> <tt>,</tt> </td>
<td class='confluenceTd'> The delimiter char (could be <tt>;</tt> <tt>,</tt> or similar) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>parserFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Uses the default Flatpack parser factory. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>To use the data format, simply instantiate an instance and invoke the marhsal or unmarshal operation in the route builder:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  FlatpackDataFormat fp = <span class="code-keyword">new</span> FlatpackDataFormat();
  fp.setDefinition(<span class="code-keyword">new</span> ClassPathResource(<span class="code-quote">"INVENTORY-Delimited.pzmap.xml"</span>));
  ...
  from(<span class="code-quote">"file:order/in"</span>).unmarshal(df).to(<span class="code-quote">"seda:queue:neworder"</span>);
</pre>
</div></div>
<p>The sample above will read files from the <tt>order/in</tt> folder and unmarshal the input using the Flatpack configuration file <tt>INVENTORY-Delimited.pzmap.xml</tt> that configures the structure of the files. The result is a <tt>DataSetList</tt> object we store on the SEDA queue.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
FlatpackDataFormat df = <span class="code-keyword">new</span> FlatpackDataFormat();
df.setDefinition(<span class="code-keyword">new</span> ClassPathResource(<span class="code-quote">"PEOPLE-FixedLength.pzmap.xml"</span>));
df.setFixed(<span class="code-keyword">true</span>);
df.setIgnoreFirstRecord(<span class="code-keyword">false</span>);

from(<span class="code-quote">"seda:people"</span>).marshal(df).convertBodyTo(<span class="code-object">String</span>.class).to(<span class="code-quote">"jms:queue:people"</span>);
</pre>
</div></div>
<p>In the code above we marshal the data from a Object representation as a <tt>List</tt> of rows as <tt>Maps</tt>. The rows as <tt>Map</tt> contains the column name as the key, and the the corresponding value. This structure can be created in Java code from e.g. a processor. We marshal the data according to the Flatpack format and convert the result as a <tt>String</tt> object and store it on a JMS queue.</p>

<h3><a name="BookComponentAppendix-Dependencies"></a>Dependencies</h3>

<p>To use Flatpack in your camel routes you need to add the a dependency on <b>camel-flatpack</b> which implements this data format. </p>

<p>If you use maven you could just add the following to your pom.xml, substituting the version number for the latest &amp; greatest release (see <a href="/confluence/display/CAMEL/Download" title="Download">the download page for the latest versions</a>).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-flatpack&lt;/artifactId&gt;
  &lt;version&gt;1.5.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-Freemarker"></a>Freemarker</h2>
<p><b>Available as of Camel 1.6</b></p>

<p>The <b>freemarker:</b> component allows you to process a message using a <a href="http://freemarker.org/" rel="nofollow">Freemarker</a> template. This can be ideal when using <a href="/confluence/display/CAMEL/Templating" title="Templating">Templating</a> to generate responses for requests.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
freemarker:templateName[?options]
</pre>
</div></div>

<p>Where <b>templateName</b> is the classpath-local URI of the template to invoke; or the complete URL of the remote template (eg: <a href="file://folder/myfile.ftl" rel="nofollow">file://folder/myfile.ftl</a>).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentCache</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Cache for the resource content when its loaded. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Character encoding of the resource content. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Headers"></a>Headers</h3>
<p>Camel will store a reference to the resource in the message header in the key <tt>org.apache.camel.freemarker.resource</tt>. The Resource is an <tt>org.springframework.core.io.Resource</tt> object. And the key <tt>org.apache.camel.freemarker.resourceUri</tt> holds the <b>templateName</b> as a String object. </p>

<p><b>Note</b> From Camel 2.1 and Camel 1.6.2, freemarker endpoint will not store these headers into to message, as these header will cause some side effect on the dynamic templates feature. </p>

<p>Headers set during the Freemarker evaluation are returned to the message and added as headers. Then its kinda possible to return values from Freemarker to the Message.</p>

<p>An example: Set the header value of <tt>fruit</tt> in the Freemarker template:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
${request.setHeader('fruit', 'Apple')}
</pre>
</div></div>

<p>The header, <tt>fruit</tt>, is now accessible from the <tt>message.out.headers</tt>.</p>

<h3><a name="BookComponentAppendix-FreemarkerContext"></a>Freemarker Context</h3>
<p>Camel will provide exchange information in the Freemarker context (just a <tt>Map</tt>). The <tt>Exchange</tt> is transfered as:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> key </th>
<th class='confluenceTh'> value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>exchange</tt> </td>
<td class='confluenceTd'> The Exchange itself. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headers</tt> </td>
<td class='confluenceTd'> The headers of the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelContext</tt> </td>
<td class='confluenceTd'> The Camel Context. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>body</tt> </td>
<td class='confluenceTd'> The In message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>response</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Hotreloading"></a>Hot reloading</h3>
<p>The Freemarker template resource is by default <b>not</b> hot reloadable for both file and classpath resources (expanded jar). If you set <tt>contentCache=false</tt>, then Camel will not cache the resource and hot reloading is thus enabled. This scenario can be used in development.</p>

<h3><a name="BookComponentAppendix-Dynamictemplates"></a>Dynamic templates</h3>
<p><b>Available as of Camel 2.1</b><br/>
Camel provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> CamelFreemarkerResourceUri </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> A URI for the template resource to use instead of the endpoint configured. </td>
</tr>
<tr>
<td class='confluenceTd'> CamelFreemarkerTemplate </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The template to use instead of the endpoint configured. </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>For example you could use something like:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"freemarker:com/acme/MyResponse.ftl"</span>);
</pre>
</div></div>

<p>To use a Freemarker template to formulate a response for a message for InOut message exchanges (where there is a <tt>JMSReplyTo</tt> header).</p>

<p>If you want to use InOnly and consume the message and send it to another destination you could use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"freemarker:com/acme/MyResponse.ftl"</span>).
  to(<span class="code-quote">"activemq:Another.Queue"</span>);
</pre>
</div></div>

<p>And to disable the content cache, e.g. for development usage where the <tt>.ftl</tt> template should be hot reloaded:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"freemarker:com/acme/MyResponse.ftl?contentCache=<span class="code-keyword">false</span>"</span>).
  to(<span class="code-quote">"activemq:Another.Queue"</span>);
</pre>
</div></div>

<p>And a file-based resource:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"freemarker:file:<span class="code-comment">//myfolder/MyResponse.ftl?contentCache=<span class="code-keyword">false</span>"</span>).
</span>  to(<span class="code-quote">"activemq:Another.Queue"</span>);
</pre>
</div></div>

<p>In <b>Camel 2.1</b> it's possible to specify what template the component should use dynamically via a header, so for example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:in"</span>).
  setHeader(<span class="code-quote">"CamelFreemarkerResourceUri"</span>).constant(<span class="code-quote">"path/to/my/template.ftl"</span>).
  to(<span class="code-quote">"freemarker:dummy"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-TheEmailSample"></a>The Email Sample</h3>
<p>In this sample we want to use Freemarker templating for an order confirmation email. The email template is laid out in Freemarker as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Dear ${headers.lastName}, ${headers.firstName}

Thanks <span class="code-keyword">for</span> the order of ${headers.item}.

Regards Camel Riders Bookstore
${body}
</pre>
</div></div>

<p>And the java code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">private</span> Exchange createLetter() {
    Exchange exchange = context.getEndpoint(<span class="code-quote">"direct:a"</span>).createExchange();
    Message msg = exchange.getIn();
    msg.setHeader(<span class="code-quote">"firstName"</span>, <span class="code-quote">"Claus"</span>);
    msg.setHeader(<span class="code-quote">"lastName"</span>, <span class="code-quote">"Ibsen"</span>);
    msg.setHeader(<span class="code-quote">"item"</span>, <span class="code-quote">"Camel in Action"</span>);
    msg.setBody(<span class="code-quote">"PS: Next beer is on me, James"</span>);
    <span class="code-keyword">return</span> exchange;
}

@Test
<span class="code-keyword">public</span> void testFreemarkerLetter() <span class="code-keyword">throws</span> Exception {
    MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived(<span class="code-quote">"Dear Ibsen, Claus\n\nThanks <span class="code-keyword">for</span> the order of Camel in Action.\n\nRegards Camel Riders Bookstore\nPS: Next beer is on me, James"</span>);

    template.send(<span class="code-quote">"direct:a"</span>, createLetter());

    mock.assertIsSatisfied();
}

<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            from(<span class="code-quote">"direct:a"</span>).to(<span class="code-quote">"freemarker:org/apache/camel/component/freemarker/letter.ftl"</span>).to(<span class="code-quote">"mock:result"</span>);
        }
    };
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-FTP%2FSFTP%2FFTPSComponentCamel2.0onwards"></a>FTP/SFTP/FTPS Component - <b>Camel 2.0 onwards</b></h2>

<p>This component provides access to remote file systems over the FTP and SFTP protocols.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using Camel 1.x</b><br /><p>If you are using Camel 1.x then see this <a href="/confluence/display/CAMEL/FTP" title="FTP">link</a> for documentation.<br/>
This page is only for Camel 2.0 or newer.</p></td></tr></table></div>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using FTPS</b><br /><p>The FTPS component is only available in Camel 2.2 or newer.<br/>
FTPS (also known as FTP Secure) is an extension to FTP that adds support for the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ftp:<span class="code-comment">//[username@]hostname[:port]/directoryname[?options]
</span>sftp:<span class="code-comment">//[username@]hostname[:port]/directoryname[?options]
</span>ftps:<span class="code-comment">//[username@]hostname[:port]/directoryname[?options]</span>
</pre>
</div></div>

<p>Where <b>directoryname</b> represents the underlying directory. Can contain nested folders.<br/>
The <b>username</b> is currently only possible to provide in the hostname parameter.</p>

<p>If no <b>username</b> is provided, then <tt>anonymous</tt> login is attempted using no password.<br/>
If no <b>port</b> number is provided, Camel will provide default values according to the protocol (ftp = 21, sftp = 22, ftps = 2222).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>
<p>The options below are exclusive for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP2</a> component. </p>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the password to use to log in to the remote file system. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>binary</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies the file transfer mode, BINARY or ASCII. Default is ASCII (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Whether or not to disconnect from remote FTP server right after use. Can be used for both consumer and producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>localWorkDirectory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial, if you consume a very big remote file and thus can conserve memory. See below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>passiveMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS only</b>: Specifies whether to use passive mode connections. Default is active mode (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityProtocol</tt> </td>
<td class='confluenceTd'> <tt>TLS</tt> </td>
<td class='confluenceTd'> <b>FTPS only:</b> Sets the underlying security protocol. The following values are defined:<br clear="all" />
<tt>TLS</tt>: Transport Layer Security<br clear="all" />
<tt>SSL</tt>: Secure Sockets Layer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>isImplicit</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>FTPS only:</b> Sets the security mode(implicit/explicit). Default is explicit (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>knownHostsFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Sets the <tt>known_hosts</tt> file, so that the SFTP endpoint can do host key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>privateKeyFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Set the private key file to that the SFTP endpoint can do private key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>privateKeyFilePassphrase</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> Set the private key file passphrase to that the SFTP endpoint can do private key verification. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>strictHostKeyChecking</tt> </td>
<td class='confluenceTd'> <tt>no</tt> </td>
<td class='confluenceTd'> <b>SFTP only:</b> <b>Camel 2.2:</b> Sets whether to use strict host key checking. Possible values are: <tt>no</tt>, <tt>yes</tt> and <tt>ask</tt>. <tt>ask</tt> does not make sense to use as Camel cannot answer the question for you as its meant for human intervention. <b>Note:</b> The default in Camel 2.1 and below was <tt>ask</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maximumReconnectAttempts</tt> </td>
<td class='confluenceTd'> 3 </td>
<td class='confluenceTd'> Specifies the maximum reconnect attempts Camel performs when it tries to connect to the remote FTP server. Use 0 to disable this behavior. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectDelay</tt> </td>
<td class='confluenceTd'> 1000 </td>
<td class='confluenceTd'> Delay in millis Camel will wait before performing a reconnect attempt. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.1:</b> Allows you to use a custom <tt>org.apache.commons.net.ftp.FTPClient</tt> instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClientConfig</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.1:</b> Allows you to use a custom <tt>org.apache.commons.net.ftp.FTPClientConfig</tt> instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.file</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store file, so that the FTPS client can look up for trusted certificates. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.type</tt> </td>
<td class='confluenceTd'> <tt>JKS</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.algorithm</tt> </td>
<td class='confluenceTd'> <tt>SunX509</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store algorithm. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store password. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.file</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store file, so that the FTPS client can look up for the private certificate. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.type</tt> </td>
<td class='confluenceTd'> <tt>JKS</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.algorithm</tt> </td>
<td class='confluenceTd'> <tt>SunX509</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store algorithm. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store password. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.keyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the private key password. </td>
</tr>
</tbody></table>
</div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>FTPS component default trust store</b><br /><p>By default, the FTPS component trust store accept all certificates. If you only want trust selective certificates, you have to configure the trust store with the <tt>ftpClient.trustStore.xxx</tt> options or by configuring a custom <tt>ftpClient</tt>.</p></td></tr></table></div>

<p>You can configure additional options on the <tt>ftpClient</tt> and <tt>ftpClientConfig</tt> from the URI directly by using the <tt>ftpClient.</tt> or <tt>ftpClientConfig.</tt> prefix.</p>

<p>For example to set the <tt>setDataTimeout</tt> on the <tt>FTPClient</tt> to 30 seconds you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftp:<span class="code-comment">//foo@myserver?password=secret&amp;ftpClient.dataTimeout=30000"</span>).to(<span class="code-quote">"bean:foo"</span>);</span>
</pre>
</div></div>

<p>You can mix and match and have use both prefixes, for example to configure date format or timezones.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftp:<span class="code-comment">//foo@myserver?password=secret&amp;ftpClient.dataTimeout=30000&amp;ftpClientConfig.serverLanguageCode=fr"</span>).to(<span class="code-quote">"bean:foo"</span>);</span>
</pre>
</div></div>

<p>You can have as many of these options as you like.</p>

<p>See the documentation of the <a href="http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClientConfig.html" rel="nofollow">Apache Commons FTP FTPClientConfig</a> for possible options and more details.<br/>
And as well for <a href="http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html" rel="nofollow">Apache Commons FTP FTPClient</a>.</p>

<p>If you do not like having many and long configuration in the url you can refer to the <tt>ftpClient</tt> or <tt>ftpClientConfig</tt> to use by letting Camel lookup in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> for it.</p>

<p>For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   &lt;bean id=<span class="code-quote">"myConfig"</span> class=<span class="code-quote">"org.apache.commons.net.ftp.FTPClientConfig"</span>&gt;
       &lt;property name=<span class="code-quote">"lenientFutureDates"</span> value=<span class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
       &lt;property name=<span class="code-quote">"serverLanguageCode"</span> value=<span class="code-quote">"fr"</span>/&gt;
   &lt;/bean&gt;
</pre>
</div></div>

<p>And then let Camel lookup this bean when you use the # notation in the url.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftp:<span class="code-comment">//foo@myserver?password=secret&amp;ftpClientConfig=#myConfig"</span>).to(<span class="code-quote">"bean:foo"</span>);</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-MoreURIoptions"></a>More URI options</h3>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>See <a href="/confluence/display/CAMEL/File2" title="File2">File2</a> as all the options there also applies for this component.</p></td></tr></table></div>

<h4><a name="BookComponentAppendix-Examples"></a>Examples</h4>
<p><tt><a href="ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true" rel="nofollow">ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true</a></tt><br/>
<tt><a href="ftp://someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&amp;binary=false" rel="nofollow">ftp://someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&amp;binary=false</a></tt><br/>
<tt><a href="ftp://publicftpserver.com/download" rel="nofollow">ftp://publicftpserver.com/download</a></tt></p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>FTP Consumer does not support concurrency</b><br /><p>The FTP consumer (with the same endpoint) does not support concurrency (the backing FTP client is not thread safe).<br/>
You can use multiple FTP consumers to poll from different endpoints. It is only a single endpoint that does not support concurrent consumers.</p>

<p>The FTP producer does <b>not</b> have this issue, it supports concurrency.</p>

<p>In the future we will <a href="https://issues.apache.org/activemq/browse/CAMEL-1682" rel="nofollow">add consumer pooling to Camel</a> to allow this consumer to support concurrency as well.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>More information</b><br /><p>This component is an extension of the <a href="/confluence/display/CAMEL/File2" title="File2">File2</a> component. So there are more samples and details on the <a href="/confluence/display/CAMEL/File2" title="File2">File2</a> component page.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Defaultwhenconsumingfiles"></a>Default when consuming files</h3>
<p>The <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> consumer will by default leave the consumed files untouched on the remote FTP server. You have to configure it explicit if you want it to delete the files or move them to another location. For example you can use <tt>delete=true</tt> to delete the files, or use <tt>move=.done</tt> to move the files into a hidden done sub directory.</p>

<p>The regular <a href="/confluence/display/CAMEL/File2" title="File2">File</a> consumer is different as it will by default move files to a <tt>.camel</tt> sub directory. The reason Camel does <b>not</b> do this by default for the FTP consumer is that it may lack permissions by default to be able to move or delete files.</p>

<h4><a name="BookComponentAppendix-limitations"></a>limitations</h4>
<p>The option <b>readLock</b> can be used to force Camel <b>not</b> to consume files that is currently in the progress of being written. However, this option is turned off by default, as it requires that the user has write access. There are other solutions to avoid consuming files that are currently being written over FTP; for instance, you can write to a temporary destination and move the file after it has been written. </p>

<p>When moving files using <tt>move</tt> or <tt>preMove</tt> option the files are restricted to the FTP_ROOT folder. That prevents you from moving files outside the FTP area. If you want to move files to another area you can use soft links and move files into a soft linked folder.</p>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>

<p>The following message headers can be used to affect the behavior of the component</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileName</tt> </td>
<td class='confluenceTd'> Specifies the output file name (relative to the endpoint directory) to be used for the output message when sending to the endpoint. If this is not present and no expression either, then a generated message ID is used as the filename instead.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileNameProduced</tt> </td>
<td class='confluenceTd'> The actual absolute filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users the name of the file that was written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileBatchIndex</tt> </td>
<td class='confluenceTd'> Current index out of total number of files being consumed in this batch. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileBatchSize</tt> </td>
<td class='confluenceTd'> Total number of files being consumed in this batch. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileHost</tt> </td>
<td class='confluenceTd'> The remote hostname. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileLocalWorkPath</tt> </td>
<td class='confluenceTd'> Path to the local work file, if local work directory is used. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-UsingLocalWorkDirectory"></a>Using Local Work Directory</h3>
<p>Camel supports consuming from remote FTP servers and downloading the files directly into a local work directory. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using <tt>FileOutputStream</tt>. </p>

<p>Camel will store to a local file with the same name as the remote file, though with <tt>.inprogress</tt> as extension while the file is being downloaded. Afterwards, the file is renamed to remove the <tt>.inprogress</tt> suffix. And finally, when the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is complete the local file is deleted. </p>

<p>So if you want to download files from a remote FTP server and store it as files then you need to route to a file endpoint such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftp:<span class="code-comment">//someone@someserver.com?password=secret&amp;localWorkDirectory=/tmp"</span>).to(<span class="code-quote">"file://inbox"</span>);</span>
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Optimization by renaming work file</b><br /><p>The route above is ultra efficient as it avoids reading the entire file content into memory. It will download the remote file directly to a local file stream. The <tt>java.io.File</tt> handle is then used as the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> body. The file producer leverages this fact and can work directly on the work file <tt>java.io.File</tt> handle and perform a <tt>java.io.File.rename</tt> to the target filename. As Camel knows it's a local work file, it can optimize and use a rename instead of a file copy, as the work file is meant to be deleted anyway.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>In the sample below we set up Camel to download all the reports from the FTP server once every hour (60 min) as BINARY content and store it as files on the local file system.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// we use a delay of 60 minutes (eg. once pr. hour we poll the FTP server
</span>            <span class="code-object">long</span> delay = 60 * 60 * 1000L;

            <span class="code-comment">// from the given FTP server we poll (= download) all the files
</span>            <span class="code-comment">// from the <span class="code-keyword">public</span>/reports folder as BINARY types and store <span class="code-keyword">this</span> as files
</span>            <span class="code-comment">// in a local directory. Camel will use the filenames from the FTPServer
</span>
            <span class="code-comment">// notice that the FTPConsumer properties must be prefixed with <span class="code-quote">"consumer."</span> in the URL
</span>            <span class="code-comment">// the delay parameter is from the FileConsumer component so we should use consumer.delay as
</span>            <span class="code-comment">// the URI parameter name. The FTP Component is an extension of the File Component.
</span>            from(<span class="code-quote">"ftp:<span class="code-comment">//scott@localhost/<span class="code-keyword">public</span>/reports?password=tiger&amp;binary=<span class="code-keyword">true</span>&amp;consumer.delay="</span> + delay).
</span>                    to(<span class="code-quote">"file:<span class="code-comment">//target/test-reports"</span>);
</span>        }
    };
}
</pre>
</div></div>

<p>And the route using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"ftp://scott@localhost/public/reports?password=tiger&amp;amp;binary=true&amp;amp;delay=60000"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"file://target/test-reports"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ConsumingaremoteFTPservertriggeredbyaroute"></a>Consuming a remote FTP server triggered by a route</h4>
<p>The FTP consumer is built as a scheduled consumer to be used in the <b>from</b> route. However, if you want to start consuming from an FTP server triggered within a route. </p>

<p>Notice we use the <a href="/confluence/display/CAMEL/Content+Enricher" title="Content Enricher">Content Enricher</a> EIP with the <tt>pollEnrich</tt> DSL to consume the FTP file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"seda:start"</span>)
   <span class="code-comment">// set the filename in FILE_NAME header so Camel know the name of the remote file to poll
</span>   .setHeader(Exchange.FILE_NAME, header(<span class="code-quote">"myfile"</span>))
   .pollEnrich(<span class="code-quote">"ftp:<span class="code-comment">//admin@localhost:21/getme?password=admin&amp;binary=<span class="code-keyword">false</span>"</span>)
</span>   .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ConsumingaremoteFTPSserver%28implicitSSL%29andclientauthentication"></a>Consuming a remote FTPS server (implicit SSL) and client authentication</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftps:<span class="code-comment">//admin@localhost:2222/<span class="code-keyword">public</span>/camel?password=admin&amp;securityProtocol=SSL&amp;isImplicit=<span class="code-keyword">true</span>&amp;ftpClient.keyStore.file=./src/test/resources/server.jks&amp;ftpClient.keyStore.password=password&amp;ftpClient.keyStore.keyPassword=password"</span>)
</span>  .to(<span class="code-quote">"bean:foo"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ConsumingaremoteFTPSserver%28explicitTLS%29andacustomtruststoreconfiguration"></a>Consuming a remote FTPS server (explicit TLS) and a custom trust store configuration</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ftps:<span class="code-comment">//admin@localhost:2222/<span class="code-keyword">public</span>/camel?password=admin&amp;ftpClient.trustStore.file=./src/test/resources/server.jks&amp;ftpClient.trustStore.password=password"</span>)
</span>  .to(<span class="code-quote">"bean:foo"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Filterusing%7B%7Borg.apache.camel.component.file.GenericFileFilter%7D%7D"></a>Filter using <tt>org.apache.camel.component.file.GenericFileFilter</tt></h3>
<p>Camel supports pluggable filtering strategies. This strategy it to use the build in <tt>org.apache.camel.component.file.GenericFileFilter</tt> in Java. You can then configure the endpoint with such a filter to skip certain filters before being processed.</p>

<p>In the sample we have build our own filter that only accepts files starting with report in the filename.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyFileFilter <span class="code-keyword">implements</span> GenericFileFilter {

    <span class="code-keyword">public</span> <span class="code-object">boolean</span> accept(GenericFile file) {
        <span class="code-comment">// we only want report files 
</span>        <span class="code-keyword">return</span> file.getFileName().startsWith(<span class="code-quote">"report"</span>);
    }
}
</pre>
</div></div>

<p>And then we can configure our route using the <b>filter</b> attribute to reference our filter (using <tt>&#35;</tt> notation) that we have defines in the spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag"><span class="code-comment">&lt;!-- define our sorter as a plain spring bean --&gt;</span></span>
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myFilter"</span> class=<span class="code-quote">"com.mycompany.MyFileFilter"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"ftp://someuser@someftpserver.com?password=secret&amp;amp;filter=#myFilter"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processInbox"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-FilteringusingANTpathmatcher"></a>Filtering using ANT path matcher</h3>
<p>The ANT path matcher is a filter that is shipped out-of-the-box in the <b>camel-spring</b> jar. So you need to depend on <b>camel-spring</b> if you are using Maven.<br/>
The reason is that we leverage Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html" rel="nofollow">AntPathMatcher</a> to do the actual matching.</p>

<p>The file paths are matched with the following rules:</p>
<ul class="alternate" type="square">
	<li><tt>?</tt> matches one character</li>
	<li><tt>*</tt> matches zero or more characters</li>
	<li><tt>**</tt> matches zero or more directories in a path</li>
</ul>


<p>The sample below demonstrates how to use it:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- use myFilter as filter to allow setting ANT paths for which files to scan for --&gt;</span></span>
    <span class="code-tag">&lt;endpoint id=<span class="code-quote">"myFTPEndpoint"</span> uri=<span class="code-quote">"ftp://admin@localhost:20123/antpath?password=admin&amp;amp;recursive=true&amp;amp;delay=10000&amp;amp;initialDelay=2000&amp;amp;filter=#myAntFilter"</span>/&gt;</span>

    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from ref=<span class="code-quote">"myFTPEndpoint"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for includes and exlucde --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"myAntFilter"</span> class=<span class="code-quote">"org.apache.camel.component.file.AntPathMatcherGenericFileFilter"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- include and file in the subfolder that has day in the name --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"includes"</span> value=<span class="code-quote">"**/subfolder/**/*day*"</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple excludes --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"excludes"</span> value=<span class="code-quote">"**/*bad*,**/*.xml"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Debuglogging"></a>Debug logging</h3>
<p>This component has log level <b>TRACE</b> that can be helpful if you have problems.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/File2" title="File2">File2</a></li>
</ul>

<h2><a name="BookComponentAppendix-CamelComponentsforGoogleAppEngine"></a>Camel Components for Google App Engine</h2>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tutorial</b><br /><p>A good starting point for using Camel on GAE is the <a href="/confluence/display/CAMEL/Tutorial+for+Camel+on+Google+App+Engine" title="Tutorial for Camel on Google App Engine">Tutorial for Camel on Google App Engine</a></p></td></tr></table></div>

<p>The Camel components for <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a> (GAE) are part of the <tt>camel-gae</tt> project and provide connectivity to GAE's <a href="http://code.google.com/appengine/docs/java/apis.html" rel="nofollow">cloud computing services</a>. They make the GAE cloud computing environment accessible to applications via Camel interfaces. Following this pattern for other cloud computing environments could make it easier to port Camel applications from one cloud computing provider to another. The following table lists the cloud computing services provided by Google and the supporting Camel components. The documentation of each component can be found by following the link in the <em>Camel Component</em> column.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>GAE service</th>
<th class='confluenceTh'>Camel component</th>
<th class='confluenceTh'>Component description</th>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/urlfetch/" rel="nofollow">URL fetch service</a></td>
<td class='confluenceTd'><a href="/confluence/display/CAMEL/ghttp" title="ghttp">ghttp</a></td>
<td class='confluenceTd'>Provides connectivity to the GAE URL fetch service but can also be used to receive messages from servlets.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/taskqueue/" rel="nofollow">Task queueing service</a></td>
<td class='confluenceTd'><a href="/confluence/display/CAMEL/gtask" title="gtask">gtask</a></td>
<td class='confluenceTd'>Supports asynchronous message processing on GAE by using the task queueing service as message queue.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/mail/" rel="nofollow">Mail service</a></td>
<td class='confluenceTd'><a href="/confluence/display/CAMEL/gmail" title="gmail">gmail</a></td>
<td class='confluenceTd'>Supports sending of emails via the GAE mail service. Receiving mails is not supported yet but will be added later.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/memcache/" rel="nofollow">Memcache service</a></td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>Not supported yet.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/xmpp/" rel="nofollow">XMPP service</a></td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>Not supported yet.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/images/" rel="nofollow">Images service</a></td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>Not supported yet.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/appengine/docs/java/datastore/" rel="nofollow">Datastore service</a></td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>Not supported yet.</td>
</tr>
<tr>
<td class='confluenceTd'><a href="http://code.google.com/apis/accounts/" rel="nofollow">Accounts service</a></td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>Not supported yet. The Google Accounts service is not specific to Google App Engine but used by GAE applications for authentication and authorization.</td>
</tr>
</tbody></table>

<p>Not supported yet. See also <a href="#BookComponentAppendix-Security">Security</a> section.|</p>

<h3><a name="BookComponentAppendix-Camelcontext"></a>Camel context</h3>

<p>Setting up a <tt>SpringCamelContext</tt> on Google App Engine differs between Camel 2.1 and Camel 2.2. The problem is that usage of the Camel-specific Spring configuration XML schema from the <tt><a href="http://camel.apache.org/schema/spring" rel="nofollow">http://camel.apache.org/schema/spring</a></tt> namespace requires JAXB and Camel 2.1 depends on a Google App Engine SDK version that doesn't support JAXB yet.</p>

<ul>
	<li>Camel 2.1 depends on the Google App Engine SDK 1.2.6 which doesn't support JAXB. Refer to the <a href="#BookComponentAppendix-Camel2.1">Camel 2.1</a> subsection for instructions how to set up a <tt>SpringCamelContext</tt> with Camel 2.1 on GAE.</li>
	<li>Camel 2.2 depends on the Google App Engine SDK 1.2.8, the first version that introduces support for JAXB. Refer to the <a href="#BookComponentAppendix-Camel2.2">Camel 2.2</a> subsection for instructions how to set up a <tt>SpringCamelContext</tt> with Camel 2.2 on GAE.</li>
</ul>


<p>With both versions, JMX must be disabled because the <tt>javax.management</tt> package isn't on the App Engine JRE whitelist.</p>

<h4><a name="BookComponentAppendix-Camel2.1"></a>Camel 2.1</h4>

<p><tt>camel-gae</tt> 2.1 comes with the following <tt>CamelContext</tt> implementations.</p>

<ul>
	<li><tt>org.apache.camel.component.gae.context.GaeDefaultCamelContext</tt> (extends <tt>org.apache.camel.impl.DefaultCamelContext</tt>)</li>
	<li><tt>org.apache.camel.component.gae.context.GaeSpringCamelContext</tt> (extends <tt>org.apache.camel.spring.SpringCamelContext</tt>)</li>
</ul>


<p>Both disable JMX before startup. The <tt>GaeSpringCamelContext</tt> additionally provides setter methods adding route builders as shown in the next example.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>appctx.xml</b></div><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;
    
    &lt;bean id=<span class="code-quote">"camelContext"</span> 
        class=<span class="code-quote">"org.apache.camel.component.gae.context.GaeSpringCamelContext"</span>&gt;
        <span class="code-tag">&lt;property name=<span class="code-quote">"routeBuilder"</span> ref=<span class="code-quote">"myRouteBuilder"</span> /&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
    
    &lt;bean id=<span class="code-quote">"myRouteBuilder"</span>
        class=<span class="code-quote">"org.example.MyRouteBuilder"</span>&gt;
    <span class="code-tag">&lt;/bean&gt;</span>
    
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div> 

<p>Alternatively, use the <tt>routeBuilders</tt> property of the <tt>GaeSpringCamelContext</tt> for setting a list of route builders. Using this approach, a <tt>SpringCamelContext</tt> can be configured on GAE without the need for JAXB.</p>

<h4><a name="BookComponentAppendix-Camel2.2"></a>Camel 2.2</h4>

<p>With Camel 2.2, applications can use the <tt><a href="http://camel.apache.org/schema/spring" rel="nofollow">http://camel.apache.org/schema/spring</a></tt> namespace for configuring a <tt>SpringCamelContext</tt> but still need to disable JMX. Here's an example.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>appctx.xml</b></div><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel</span>=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>
       xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
    
    <span class="code-tag">&lt;camel:camelContext id=<span class="code-quote">"camelContext"</span>&gt;</span>
        <span class="code-tag">&lt;camel:jmxAgent id=<span class="code-quote">"agent"</span> disabled=<span class="code-quote">"true"</span> /&gt;</span>
        <span class="code-tag">&lt;camel:routeBuilder ref=<span class="code-quote">"myRouteBuilder"</span>/&gt;</span>
    <span class="code-tag">&lt;/camel:camelContext&gt;</span>
    
    &lt;bean id=<span class="code-quote">"myRouteBuilder"</span>
        class=<span class="code-quote">"org.example.MyRouteBuilder"</span>&gt;
    <span class="code-tag">&lt;/bean&gt;</span>
    
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div> 

<p><a name="BookComponentAppendix-webxml"></a></p>
<h3><a name="BookComponentAppendix-Theweb.xml"></a>The web.xml</h3>

<p>Running Camel on GAE requires usage of the <tt>CamelHttpTransportServlet</tt> from <tt>camel-servlet</tt>. The following example shows how to configure this servlet together with a Spring application context XML file. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent panelContent">
<pre class="code-xml">
&lt;web-app 
xmlns=<span class="code-quote">"http://java.sun.com/xml/ns/javaee"</span>
<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
<span class="code-keyword">xmlns:web</span>=<span class="code-quote">"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span>
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd<span class="code-quote">" version="</span>2.5"&gt;
    
    <span class="code-tag">&lt;servlet&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;servlet-class&gt;</span>org.apache.camel.component.servlet.CamelHttpTransportServlet<span class="code-tag">&lt;/servlet-class&gt;</span>
        <span class="code-tag">&lt;init-param&gt;</span>
            <span class="code-tag">&lt;param-name&gt;</span>contextConfigLocation<span class="code-tag">&lt;/param-name&gt;</span>
            <span class="code-tag">&lt;param-value&gt;</span>appctx.xml<span class="code-tag">&lt;/param-value&gt;</span>
        <span class="code-tag">&lt;/init-param&gt;</span>
    <span class="code-tag">&lt;/servlet&gt;</span>

    &lt;!--
        Mapping used for external requests
     --&gt;
    <span class="code-tag">&lt;servlet-mapping&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;url-pattern&gt;</span>/camel/*<span class="code-tag">&lt;/url-pattern&gt;</span>
    <span class="code-tag">&lt;/servlet-mapping&gt;</span>
    
    &lt;!--
        Mapping used for web hooks accessed by task queueing service.
     --&gt;
    <span class="code-tag">&lt;servlet-mapping&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;url-pattern&gt;</span>/worker/*<span class="code-tag">&lt;/url-pattern&gt;</span>
    <span class="code-tag">&lt;/servlet-mapping&gt;</span>

<span class="code-tag">&lt;/web-app&gt;</span>
</pre>
</div></div>

<p>The location of the Spring application context XML file is given by the <tt>contextConfigLocation</tt> init parameter. The <tt>appctx.xml</tt> file must be on the classpath. The servlet mapping makes the Camel application accessible under <tt>http://&lt;appname&gt;.appspot.com/camel/...</tt> when deployed to Google App Engine where <tt>&lt;appname&gt;</tt> must be replaced by a real GAE application name. The second servlet mapping is used internally by the task queueing service for background processing via <a href="http://www.webhooks.org/" rel="nofollow">web hooks</a>. This mapping is relevant for the <a href="/confluence/display/CAMEL/gtask" title="gtask">gtask</a> component and is explained there in more detail. </p>

<h3><a name="BookComponentAppendix-Security"></a>Security</h3>

<ul>
	<li>For instructions how to protect Camel applications on GAE refer to <a href="/confluence/display/CAMEL/gsec" title="gsec">Security for Camel GAE applications</a> page.</li>
</ul>

<h2><a name="BookComponentAppendix-HDFSComponent"></a>HDFS Component</h2>

<p>The <b>hdfs</b> component enables you to read and write messages from/to an HDFS file system. HDFS is the distributed file system at the heart of <a href="http://hadoop.apache.org" rel="nofollow">Hadoop</a>.<br/>
It can only be built using JDK1.6 or later because  this is a strict requirement for Hadoop itself.<br/>
This component is hosted at <a href="http://github.com/dgreco/camel-hdfs" rel="nofollow">http://github.com/dgreco/camel-hdfs</a>. We decided to put it temporarily on this <a href="http://www.github.com" rel="nofollow">github</a> because currently Camel is being built and tested using JDK1.5 and for this reason we couldn't put that component into the Camel official distribution. Hopefully, as soon Camel will allow to use JDK1.6 for building and testing we will put it into the trunk.<br/>
This component is developed and tested using the latest Camel snapshot, but it should work seamlessly with the latest Camel GA version (at the time of writing 2.1.0)</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hdfs:<span class="code-comment">//hostname[:port][/path][?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt><br/>
The path is treated in the following way:</p>
<ol>
	<li>as a consumer, if it's a file, it just reads the file, otherwise if it represents a directory it scans all the file under the path satisfying the configured pattern. All the files under that directory must be of the same type.</li>
	<li>as a producer, if at least one split strategy is defined, the path is considered a directory and under that directory the producer creates a different file per split named seg0, seg1, seg2, etc.</li>
</ol>


<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>overwrite</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> The file can be overwritten </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> The buffer size used by HDFS  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replication</tt> </td>
<td class='confluenceTd'> <tt>3</tt> </td>
<td class='confluenceTd'> The HDFS replication factor  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>blockSize</tt> </td>
<td class='confluenceTd'> <tt>67108864</tt> </td>
<td class='confluenceTd'> The size of the HDFS blocks  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileType</tt> </td>
<td class='confluenceTd'> <tt>NORMAL_FILE</tt> </td>
<td class='confluenceTd'> It can be SEQUENCE_FILE,<br/>
                                   MAP_FILE, ARRAY_FILE, or<br/>
                                   BLOOMMAP_FILE, see Hadoop </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileSystemType</tt> </td>
<td class='confluenceTd'> <tt>HDFS</tt> </td>
<td class='confluenceTd'> It can be LOCAL for local filesystem  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyType</tt> </td>
<td class='confluenceTd'> <tt>NULL</tt> </td>
<td class='confluenceTd'> The type for the key in case of<br/>
                           sequence or map files. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>valueType</tt> </td>
<td class='confluenceTd'> <tt>TEXT</tt> </td>
<td class='confluenceTd'> The type for the key in case of<br/>
                             sequence or map files. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitStrategy</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> A string describing the strategy on <br/>
                        how to split the file based on different<br/>
                        criteria. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>openedSuffix</tt> </td>
<td class='confluenceTd'> <tt>opened</tt> </td>
<td class='confluenceTd'> When a file is opened for reading/<br/>
                                  writing the file is renamed with this<br/>
                                  suffix to avoid to read it during the<br/>
                                  writing phase. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readSuffix</tt> </td>
<td class='confluenceTd'> <tt>read</tt> </td>
<td class='confluenceTd'> Once the file has been read is<br/>
                              renamed with this suffix to avoid to<br/>
                              read it again.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> For the consumer, how much to wait (milliseconds)<br/>
                             before to start scanning the directory.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> The interval (milliseconds) between the directory<br/>
                      scans. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'> <tt>*</tt> </td>
<td class='confluenceTd'> The pattern used for scanning the<br/>
                        directory  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunkSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> When reading a normal file, this is split   <br/>
                             into chunks producing a message per<br/>
                             chunk   </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-KeyTypeandValueType"></a>KeyType and ValueType</h4>
<ul>
	<li>NULL it means that the key or the value is absent</li>
	<li>BYTE for writing a byte, the java Byte class is mapped into a BYTE</li>
	<li>BYTES for writing a sequence of bytes. It maps the java ByteBuffer class</li>
	<li>INT for writing java integer</li>
	<li>FLOAT for writing java float</li>
	<li>LONG for writing java long</li>
	<li>DOUBLE for writing java double</li>
	<li>TEXT for writing java strings</li>
</ul>


<p>BYTES is also used with everything else, for example, in Camel a file is sent around as an InputStream, int this case is written in a sequence file or a map file as a sequence of bytes.</p>

<h3><a name="BookComponentAppendix-SplittingStrategy"></a>Splitting Strategy</h3>
<p>In the current version of Hadoop (0.20.1) opening a file in append mode is disabled since it's not enough reliable. So, for the moment, it's only possible to create new files. The Camel HDFS endpoint tries to solve this problem in this way:</p>
<ul>
	<li>If the split strategy option has been defined, the actual file name will become a directory name and a &lt;file name&gt;/seg0 will be initially created.</li>
	<li>Every time a splitting condition is met a new file is created with name &lt;original file name&gt;/segN where N is 1, 2, 3, etc.<br/>
The splitStrategy option  is defined as a string with the following syntax:<br/>
splitStrategy=&lt;ST&gt;:&lt;value&gt;,&lt;ST&gt;:&lt;value&gt;,*</li>
</ul>


<p>where &lt;ST&gt; can be:<br/>
BYTES a new file is created, and the old is closed when the number of written bytes is more than &lt;value&gt;<br/>
MESSAGES a new file is created, and the old is closed when the number of written messages is more than  &lt;value&gt;<br/>
IDLE a new file is created, and the old is closed when no writing happened in the last &lt;value&gt; milliseconds</p>

<p>for example:<br/>
hdfs://localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5<br/>
it means: a new file is created either when it has been idle for more than 1 second or if more than 5 bytes have been written. So, running hadoop fs -ls /tmp/simple-file you'll find the following files seg0, seg1, seg2, etc</p>
<h2><a name="BookComponentAppendix-HibernateComponent"></a>Hibernate Component</h2>

<p>The <b>hibernate:</b> component allows you to work with databases using Hibernate as the object relational mapping technology to map POJOs to database tables. The <b>camel-hibernate</b> library is provided by the <a href="http://code.google.com/p/camel-extra/" rel="nofollow">Camel Extra</a> project which hosts all *GPL related components for Camel.</p>

<h3><a name="BookComponentAppendix-Sendingtotheendpoint"></a>Sending to the endpoint</h3>

<p>Sending POJOs to the hibernate endpoint inserts entities into the database. The body of the message is assumed to be an entity bean that you have mapped to a relational table using the hibernate <tt>.hbm.xml</tt> files.</p>

<p>If the body does not contain an entity bean, use a <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> in front of the endpoint to perform the necessary conversion first.</p>

<h3><a name="BookComponentAppendix-Consumingfromtheendpoint"></a>Consuming from the endpoint</h3>

<p>Consuming messages removes (or updates) entities in the database. This allows you to use a database table as a logical queue; consumers take messages from the queue and then delete/update them to logically remove them from the queue.</p>

<p>If you do not wish to delete the entity when it has been processed, you can specify <tt>consumeDelete=false</tt> on the URI. This will result in the entity being processed each poll.</p>

<p>If you would rather perform some update on the entity to mark it as processed (such as to exclude it from a future query) then you can annotate a method with <a href="http://activemq.apache.org/camel/maven/camel-hibernate/apidocs/org/apache/camel/component/hibernate/Consumed.html" rel="nofollow">@Consumed</a> which will be invoked on your entity bean when the entity bean is consumed.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hibernate:[entityClassName][?options]
</pre>
</div></div>

<p>For sending to the endpoint, the <b>entityClassName</b> is optional. If specified it is used to help use the <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Type+Conversion&amp;linkCreation=true&amp;fromPageId=90525" class="createlink">Type Conversion</a> to ensure the body is of the correct type.</p>

<p>For consuming the <b>entityClassName</b> is mandatory.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>entityType</tt> </td>
<td class='confluenceTd'> <em>entityClassName</em> </td>
<td class='confluenceTd'> Is the provided <em>entityClassName</em> from the URI. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeDelete</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Option for HibernateConsumer only. Specifies whether or not the entity is deleted after it is consumed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeLockEntity</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Option for HibernateConsumer only. Specifies whether or not to use exclusive locking of each entity while processing the results from the pooling. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flushOnSend</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Option for HibernateProducer only. Flushes the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html" rel="nofollow">EntityManager</a> after the entity bean has been persisted. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maximumResults</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'>  Option for HibernateConsumer only. Set the maximum number of results to retrieve on the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html" rel="nofollow">Query</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> Option for HibernateConsumer only. Delay in millis between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Option for HibernateConsumer only. Millis before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Option for HibernateConsumer only. Set to <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-HL7Component"></a>HL7 Component</h2>

<p>The <b>hl7</b> component is used for working with the HL7 MLLP protocol and the <a href="http://www.hl7.org/" rel="nofollow">HL7 model</a> using the <a href="http://hl7api.sourceforge.net" rel="nofollow">HAPI library</a>.</p>

<p>This component supports the following:</p>
<ul class="alternate" type="square">
	<li>HL7 MLLP codec for <a href="http://mina.apache.org/" rel="nofollow">Mina</a></li>
	<li>Agnostic data format using either plain String objects or HAPI HL7 model objects.</li>
	<li><a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> from/to HAPI and String</li>
	<li>HL7 DataFormat using HAPI library</li>
	<li>Even more easy-of-use as its integrated well with the <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> component.</li>
</ul>


<h3><a name="BookComponentAppendix-HL7MLLPprotocol"></a>HL7 MLLP protocol</h3>
<p>HL7 is often used with the HL7 MLLP protocol that is a text based TCP socket based protocol. This component ships with a Mina Codec that conforms to the MLLP protocol so you can easily expose a HL7 listener that accepts HL7 requests over the TCP transport. </p>

<p>To expose a HL7 listener service we reuse the existing <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> component where we just use the <tt>HL7MLLPCodec</tt> as codec.</p>

<p>The HL7 MLLP codec has the following options:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>startByte</tt> </td>
<td class='confluenceTd'> <tt>0x0b</tt> </td>
<td class='confluenceTd'> The start byte spanning the HL7 payload. Is the HL7 default value of <tt>0x0b</tt> (11 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>endByte1</tt> </td>
<td class='confluenceTd'> <tt>0x1c</tt> </td>
<td class='confluenceTd'> The first end byte spanning the HL7 payload. Is the HL7 default value of <tt>0x1c</tt> (28 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>endByte2</tt> </td>
<td class='confluenceTd'> <tt>0x0d</tt> </td>
<td class='confluenceTd'> The 2nd end byte spanning the HL7 payload. Is the HL7 default value of <tt>0x0d</tt> (13 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>charset</tt> </td>
<td class='confluenceTd'> JVM Default </td>
<td class='confluenceTd'> The encoding (is a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" rel="nofollow">charset name</a>) to use for the codec. If not provided, Camel will use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()" rel="nofollow">JVM default Charset</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>convertLFtoCR</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Will convert <tt>\n</tt> to <tt>\r</tt> (<tt>0x0d</tt>, 13 decimal) as HL7 usually uses <tt>\r</tt> as segment terminators. The HAPI library requires the use of <tt>\r</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>validate</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether HAPI Parser should validate or not. </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-ExposingaHL7listener"></a>Exposing a HL7 listener</h4>
<p>In our Spring XML file, we configure an endpoint to listen for HL7 requests using TCP:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;endpoint id=<span class="code-quote">"hl7listener"</span> uri=<span class="code-quote">"mina:tcp://localhost:8888?sync=true&amp;amp;codec=hl7codec"</span>/&gt;</span>
</pre>
</div></div>
<p>Notice we configure it to use <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> with TCP on the <tt>localhost</tt> on port <tt>8888</tt>. We use <b>sync=true</b> to indicate that this listener is synchronous and therefore will return a HL7 response to the caller. Then we setup mina to use our HL7 codec with <b>codec=hl7codec</b>. Notice that <tt>hl7codec</tt> is just a Spring bean ID, so we could have named it <tt>mygreatcodecforhl7</tt> or whatever. The codec is also set up in the Spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"hl7codec"</span> class=<span class="code-quote">"org.apache.camel.component.hl7.HL7MLLPCodec"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"charset"</span> value=<span class="code-quote">"iso-8859-1"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<p>And here we configure the charset encoding to use, and <tt>iso-8859-1</tt> is commonly used.</p>

<p>The endpoint <b>hl7listener</b> can then be used in a route as a consumer, as this java DSL example illustrates:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"hl7socket"</span>).to(<span class="code-quote">"patientLookupService"</span>);
</pre>
</div></div>
<p>This is a very simple route that will listen for HL7 and route it to a service named <b>patientLookupService</b> that is also a Spring bean ID we have configured in the Spring XML as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"patientLookupService"</span> class=<span class="code-quote">"com.mycompany.healtcare.service.PatientLookupService"</span>/&gt;</span>
</pre>
</div></div>
<p>And another powerful feature of Camel is that we can have our busines logic in POJO classes that is not at all tied to Camel as shown here:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class PatientLookupService {
    <span class="code-keyword">public</span> Message lookupPatient(Message input) <span class="code-keyword">throws</span> HL7Exception {
        QRD qrd = (QRD)input.get(<span class="code-quote">"QRD"</span>);
        <span class="code-object">String</span> patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();

        <span class="code-comment">// find patient data based on the patient id and create a HL7 model object with the response
</span>        Message response = ... create and set response data
        <span class="code-keyword">return</span> response
    }
</pre>
</div></div>
<p>Notice that this class is just using imports from the HAPI library and <b>none</b> from Camel.</p>

<h3><a name="BookComponentAppendix-HL7Modelusingjava.lang.String"></a>HL7 Model using java.lang.String</h3>
<p>The HL7MLLP codec uses plain <tt>String</tt> as data format. And Camel uses <a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> to convert from/to strings to the HAPI HL7 model objects. However, you can use the plain <tt>String</tt> objects if you prefer, for instance if you need to parse the data yourself.</p>

<p>See samples for such an example.</p>

<h3><a name="BookComponentAppendix-HL7ModelusingHAPI"></a>HL7 Model using HAPI</h3>
<p>The HL7 model is Java objects from the HAPI library. Using this library, we can encode and decode from the EDI format (ER7) that is mostly used with HL7.<br/>
With this model you can code with Java objects instead of the EDI based HL7 format that can be hard for humans to read and understand.</p>

<p>The ER7 sample below is a request to lookup a patient with the patient ID, <tt>0101701234</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
MSH|^~\\&amp;|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4
QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||
</pre>
</div></div>

<p>Using the HL7 model we can work with the data as a <tt>ca.uhn.hl7v2.model.Message.Message</tt> object.<br/>
To retrieve the patient ID for the patient in the ER7 above, you can do this in java code:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Message msg = exchange.getIn().getBody(Message.class);
QRD qrd = (QRD)msg.get(<span class="code-quote">"QRD"</span>);
<span class="code-object">String</span> patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();
</pre>
</div></div>

<p>Camel has built-in type converters, so when this operation is invoked:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Message msg = exchange.getIn().getBody(Message.class);
</pre>
</div></div>
<p>Camel will convert the received HL7 data from <tt>String</tt> to <tt>Message</tt>. This is powerful when combined with the HL7 listener, then you as the end-user don't have to work with <tt>byte[]</tt>, <tt>String</tt> or any other simple object formats. You can just use the HAPI HL7 model objects.</p>

<h2><a name="BookComponentAppendix-HL7DataFormat"></a>HL7 DataFormat</h2>
<p>The <a href="/confluence/display/CAMEL/HL7" title="HL7">HL7</a> component ships with a HL7 data format that can be used to format between <tt>String</tt> and HL7 model objects. </p>
<ul class="alternate" type="square">
	<li><tt>marshal</tt> = from Message to byte stream (can be used when returning as response using the HL7 MLLP codec)</li>
	<li><tt>unmarshal</tt> = from byte stream to Message (can be used when receiving streamed data from the HL7 MLLP</li>
</ul>


<p>To use the data format, simply instantiate an instance and invoke the marhsal or unmarshl operation in the route builder:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  DataFormat hl7 = <span class="code-keyword">new</span> HL7DataFormat();
  ...
  from(<span class="code-quote">"direct:hl7in"</span>).marshal(hl7).to(<span class="code-quote">"jms:queue:hl7out"</span>);
</pre>
</div></div>
<p>In the sample above, the HL7 is marshalled from a HAPI Message object to a byte stream and put on a JMS queue.<br/>
The next example is the opposite:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  DataFormat hl7 = <span class="code-keyword">new</span> HL7DataFormat();
  ...
  from(<span class="code-quote">"jms:queue:hl7out"</span>).unmarshal(hl7).to(<span class="code-quote">"patientLookupService"</span>);
</pre>
</div></div>
<p>Here we unmarshal the byte stream into a HAPI Message object that is passed to our patient lookup service.</p>

<p>Notice there is a shorthand syntax in Camel for well-known data formats that is commonly used.<br/>
Then you don't need to create an instance of the <tt>HL7DataFormat</tt> object:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"direct:hl7in"</span>).marshal().hl7().to(<span class="code-quote">"jms:queue:hl7out"</span>);
  from(<span class="code-quote">"jms:queue:hl7out"</span>).unmarshal().hl7().to(<span class="code-quote">"patientLookupService"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>The <b>unmarshal</b> operation adds these MSH fields as headers on the Camel message:</p>

<h4><a name="BookComponentAppendix-Camel1.x"></a>Camel 1.x</h4>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Key </th>
<th class='confluenceTh'> MSH field </th>
<th class='confluenceTh'> Example </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.sendingApplication</tt> </td>
<td class='confluenceTd'> <tt>MSH-3</tt> </td>
<td class='confluenceTd'> <tt>MYSERVER</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.sendingFacility</tt> </td>
<td class='confluenceTd'> <tt>MSH-4</tt> </td>
<td class='confluenceTd'> <tt>MYSERVERAPP</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.receivingApplication</tt> </td>
<td class='confluenceTd'> <tt>MSH-5</tt> </td>
<td class='confluenceTd'> <tt>MYCLIENT</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.receivingFacility</tt> </td>
<td class='confluenceTd'> <tt>MSH-6</tt> </td>
<td class='confluenceTd'> <tt>MYCLIENTAPP</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.timestamp</tt> </td>
<td class='confluenceTd'> <tt>MSH-7</tt> </td>
<td class='confluenceTd'> <tt>20071231235900</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.security</tt> </td>
<td class='confluenceTd'> <tt>MSH-8</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.messageType</tt> </td>
<td class='confluenceTd'> <tt>MSH-9-1</tt> </td>
<td class='confluenceTd'> <tt>ADT</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.triggerEvent</tt> </td>
<td class='confluenceTd'> <tt>MSH-9-2</tt> </td>
<td class='confluenceTd'> <tt>A01</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.messageControl</tt> </td>
<td class='confluenceTd'> <tt>MSH-10</tt> </td>
<td class='confluenceTd'> <tt>1234</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.processingId</tt> </td>
<td class='confluenceTd'> <tt>MSH-11</tt> </td>
<td class='confluenceTd'> <tt>P</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hl7.msh.versionId</tt> </td>
<td class='confluenceTd'> <tt>MSH-12</tt> </td>
<td class='confluenceTd'> <tt>2.4</tt> </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-Camel2.0"></a>Camel 2.0</h4>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Key </th>
<th class='confluenceTh'> MSH field </th>
<th class='confluenceTh'> Example </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7SendingApplication</tt> </td>
<td class='confluenceTd'> <tt>MSH-3</tt> </td>
<td class='confluenceTd'> <tt>MYSERVER</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7SendingFacility</tt> </td>
<td class='confluenceTd'> <tt>MSH-4</tt> </td>
<td class='confluenceTd'> <tt>MYSERVERAPP</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7ReceivingApplication</tt> </td>
<td class='confluenceTd'> <tt>MSH-5</tt> </td>
<td class='confluenceTd'> <tt>MYCLIENT</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7ReceivingFacility</tt> </td>
<td class='confluenceTd'> <tt>MSH-6</tt> </td>
<td class='confluenceTd'> <tt>MYCLIENTAPP</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7Timestamp</tt> </td>
<td class='confluenceTd'> <tt>MSH-7</tt> </td>
<td class='confluenceTd'> <tt>20071231235900</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7Security</tt> </td>
<td class='confluenceTd'> <tt>MSH-8</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7MessageType</tt> </td>
<td class='confluenceTd'> <tt>MSH-9-1</tt> </td>
<td class='confluenceTd'> <tt>ADT</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7TriggerEvent</tt> </td>
<td class='confluenceTd'> <tt>MSH-9-2</tt> </td>
<td class='confluenceTd'> <tt>A01</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7MessageControl</tt> </td>
<td class='confluenceTd'> <tt>MSH-10</tt> </td>
<td class='confluenceTd'> <tt>1234</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7ProcessingId</tt> </td>
<td class='confluenceTd'> <tt>MSH-11</tt> </td>
<td class='confluenceTd'> <tt>P</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHL7VersionId</tt> </td>
<td class='confluenceTd'> <tt>MSH-12</tt> </td>
<td class='confluenceTd'> <tt>2.4</tt> </td>
</tr>
</tbody></table>

<p>All headers are <tt>String</tt> types. If a header value is missing, its value is <tt>null</tt>.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<p>The HL7 Data Format supports the following options:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> validate </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Whether the HAPI Parser should validate. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Dependencies"></a>Dependencies</h3>

<p>To use HL7 in your camel routes you need to add a dependency on <b>camel-hl7</b>, which implements this data format. </p>

<p>If you use Maven, you could just add the following to your <tt>pom.xml</tt>, substituting the version number for the latest &amp; greatest release (see <a href="/confluence/display/CAMEL/Download" title="Download">the download page for the latest versions</a>).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-hl7&lt;/artifactId&gt;
  &lt;version&gt;1.6.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>


<h2><a name="BookComponentAppendix-Samples"></a>Samples</h2>
<p>In the following example we send a HL7 request to a HL7 listener and retrieves a response. We use plain <tt>String</tt> types in this example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-object">String</span> line1 = <span class="code-quote">"MSH|^~\\&amp;|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4"</span>;
<span class="code-object">String</span> line2 = <span class="code-quote">"QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||"</span>;

<span class="code-object">StringBuffer</span> in = <span class="code-keyword">new</span> <span class="code-object">StringBuffer</span>();
in.append(line1);
in.append(<span class="code-quote">"\n"</span>);
in.append(line2);

<span class="code-object">String</span> out = (<span class="code-object">String</span>)template.requestBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>, in.toString());</span>
</pre>
</div></div>

<p>In the next sample, we want to route HL7 requests from our HL7 listener to our business logic. We have our business logic in a plain POJO that we have registered in the registry as <tt>hl7service</tt> = for instance using Spring and letting the bean id = <tt>hl7service</tt>.</p>

<p>Our business logic is a plain POJO only using the HAPI library so we have these operations defined:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyHL7BusinessLogic {

    <span class="code-comment">// This is a plain POJO that has NO imports whatsoever on Apache Camel.
</span>    <span class="code-comment">// its a plain POJO only importing the HAPI library so we can much easier work with the HL7 format.
</span>
    <span class="code-keyword">public</span> Message handleA19(Message msg) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// here you can have your business logic <span class="code-keyword">for</span> A19 messages
</span>        assertTrue(msg <span class="code-keyword">instanceof</span> QRY_A19);
        <span class="code-comment">// just <span class="code-keyword">return</span> the same dummy response
</span>        <span class="code-keyword">return</span> createADR19Message();
    }

    <span class="code-keyword">public</span> Message handleA01(Message msg) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// here you can have your business logic <span class="code-keyword">for</span> A01 messages
</span>        assertTrue(msg <span class="code-keyword">instanceof</span> ADT_A01);
        <span class="code-comment">// just <span class="code-keyword">return</span> the same dummy response
</span>        <span class="code-keyword">return</span> createADT01Message();
    }
}
</pre>
</div></div>

<p>Then we set up the Camel routes using the <tt>RouteBuilder</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">DataFormat hl7 = <span class="code-keyword">new</span> HL7DataFormat();
<span class="code-comment">// we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can <span class="code-keyword">return</span> a response
</span>from(<span class="code-quote">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>)
</span>    <span class="code-comment">// we use the HL7 data format to unmarshal from HL7 stream to the HAPI Message model
</span>    <span class="code-comment">// <span class="code-keyword">this</span> ensures that the camel message has been enriched with hl7 specific headers to
</span>    <span class="code-comment">// make the routing much easier (see below)
</span>    .unmarshal(hl7)
    <span class="code-comment">// using choice as the content base router
</span>    .choice()
        <span class="code-comment">// where we choose that A19 queries invoke the handleA19 method on our hl7service bean
</span>        .when(header(<span class="code-quote">"CamelHL7TriggerEvent"</span>).isEqualTo(<span class="code-quote">"A19"</span>))
            .beanRef(<span class="code-quote">"hl7service"</span>, <span class="code-quote">"handleA19"</span>)
            .to(<span class="code-quote">"mock:a19"</span>)
        <span class="code-comment">// and A01 should invoke the handleA01 method on our hl7service bean
</span>        .when(header(<span class="code-quote">"CamelHL7TriggerEvent"</span>).isEqualTo(<span class="code-quote">"A01"</span>)).to(<span class="code-quote">"mock:a01"</span>)
            .beanRef(<span class="code-quote">"hl7service"</span>, <span class="code-quote">"handleA01"</span>)
            .to(<span class="code-quote">"mock:a19"</span>)
        <span class="code-comment">// other types should go to mock:unknown
</span>        .otherwise()
            .to(<span class="code-quote">"mock:unknown"</span>)
    <span class="code-comment">// end choice block
</span>    .end()
    <span class="code-comment">// marhsal response back
</span>    .marshal(hl7);
</pre>
</div></div>

<p>Notice that we use the HL7 DataFormat to enrich our Camel Message with the MSH fields preconfigued on the Camel Message. This lets us much more easily define our routes using the fluent builders.<br/>
If we do not use the HL7 DataFormat, then we do not gains these headers and we must resort to a different technique for computing the MSH trigger event (= what kind of HL7 message it is). This is a big advantage of the HL7 DataFormat over the plain HL7 type converters.</p>

<h3><a name="BookComponentAppendix-SampleusingplainStringobjects"></a>Sample using plain String objects</h3>
<p>In this sample we use plain <tt>String</tt> objects as the data format, that we send, process and receive. As the sample is part of a unit test, there is some code for assertions, but you should be able to understand what happens. First we send the plain string, <tt>Hello World</tt>, to the <tt>HL7MLLPCodec</tt> and receive the response as a plain string, <tt>Bye World</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
mock.expectedBodiesReceived(<span class="code-quote">"Bye World"</span>);

<span class="code-comment">// send plain hello world as <span class="code-object">String</span>
</span><span class="code-object">Object</span> out = template.requestBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>, <span class="code-quote">"Hello World"</span>);
</span>
assertMockEndpointsSatisfied();

<span class="code-comment">// and the response is also just plain <span class="code-object">String</span>
</span>assertEquals(<span class="code-quote">"Bye World"</span>, out);
</pre>
</div></div>

<p>Here we process the incoming data as plain String and send the response also as plain String:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>)
</span>    .process(<span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// use plain <span class="code-object">String</span> as message format
</span>            <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
            assertEquals(<span class="code-quote">"Hello World"</span>, body);

            <span class="code-comment">// <span class="code-keyword">return</span> the response as plain string
</span>            exchange.getOut().setBody(<span class="code-quote">"Bye World"</span>);
        }
    })
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-HTTPComponent"></a>HTTP Component</h2>

<p>The <b>http:</b> component provides HTTP based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming external HTTP resources (as a client to call external servers using HTTP).</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
http:hostname[:port][/resourceUri][?options]
</pre>
</div></div>
<p>Will by default use port 80 for HTTP and 443 for HTTPS.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>camel-http vs camel-jetty</b><br /><p>You can only produce to endpoints generated by the HTTP component. Therefore it should never be used as input into your camel Routes. To bind/expose an HTTP endpoint via a HTTP server as input to a camel route, you can use the <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty Component</a></p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnFailure</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Option to disable throwing the <tt>HttpOperationFailedException</tt> in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'><b>Camel 2.1:</b> If the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the <b>throwExcpetionOnFailure</b> to be false to let the HttpProducer send all the fault response back.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Reference to a <tt>org.apache.camel.component.http.HttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username for Basic HTTP/NTML Authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password for Basic HTTP/NTML Authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>domain</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Domain for NTML Authentication. This option must be used to force NTML authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyHost</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The proxy host name * only for &gt;= Camel 1.6.2 *. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyPort</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The proxy port number * only for &gt;= Camel 1.6.2 *. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyUsername</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username for proxy authentication * only for &gt;= Camel 1.6.2 *. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password for proxy authentication * only for &gt;= Camel 1.6.2 *. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientConfigurerRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Reference to a <tt>org.apache.camel.component.http.HttpClientConfigurer</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Setting options on the <a href="http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/params/HttpClientParams.html" rel="nofollow">HttpClientParams</a>. For instance <tt>httpClient.soTimeout=5000</tt> will set the <tt>SO_TIMEOUT</tt> to 5 seconds. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>


<h4><a name="BookComponentAppendix-Camel1.x"></a>Camel 1.x</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>HttpProducer.HTTP_URI</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5.1</b>: URI to call. Will override existing URI set directly on the endpoint. Is set on the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>HttpProducer.HTTP_RESPONSE_CODE</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The HTTP response code from the external server. Is 200 for OK. Is set on the Out message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>HttpProducer.QUERY</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> URI parameters. Will override existing URI parameters set directly on the endpoint. Is set on the In message. </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-Camel2.0"></a>Camel 2.0</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_URI</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> URI to call. Will override existing URI set directly on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_PATH</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Request URI's path. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_QUERY</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> URI parameters. Will override existing URI parameters set directly on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_RESPONSE_CODE</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The HTTP response code from the external server. Is 200 for OK.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_CHARACTER_ENCODING</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Character encoding. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.CONTENT_TYPE</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The HTTP content type. Is set on both the IN and OUT message to provide a content type, such as <tt>text/html</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.CONTENT_ENCODING</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The HTTP content encoding. Is set on both the IN and OUT message to provide a content encoding, such as <tt>gzip</tt>. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageBody"></a>Message Body</h3>

<p>Camel will store the HTTP response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message, so headers are preserved during routing. Additionally Camel will add the HTTP response headers as well to the OUT message headers.</p>

<h3><a name="BookComponentAppendix-Responsecode"></a>Response code</h3>

<p>Camel will handle according to the HTTP response code:</p>
<ul class="alternate" type="square">
	<li>Response code is in the range 100..299, Camel regards it as a success response.</li>
	<li>Response code is in the range 300..399, Camel regards it as a redirection response and will throw a <tt>HttpOperationFailedException</tt> with the information.</li>
	<li>Response code is 400&#43;, Camel regards it as an external server failure and will throw a <tt>HttpOperationFailedException</tt> with the information.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>throwExceptionOnFailure</b><br /><p>The option, <tt>throwExceptionOnFailure</tt>, can be set to <tt>false</tt> to prevent the <tt>HttpOperationFailedException</tt> from being thrown for failed response codes. This allows you to get any response from the remote server.<br/>
There is a sample below demonstrating this.</p></td></tr></table></div></li>
</ul>


<h3><a name="BookComponentAppendix-HttpOperationFailedException"></a>HttpOperationFailedException</h3>

<p>This exception contains the following information:</p>
<ul class="alternate" type="square">
	<li>The HTTP status code</li>
	<li>The HTTP status line (text of the status code)</li>
	<li>Redirect location, if server returned a redirect</li>
	<li>Response body as a <tt>java.io.InputStream</tt>, if server provided a body as response</li>
</ul>


<h3><a name="BookComponentAppendix-CallingusingGETorPOST"></a>Calling using GET or POST</h3>

<p>In <b>Camel 1.5</b> the following algorithm is used to determine if either <tt>GET</tt> or <tt>POST</tt> HTTP method should be used:<br/>
1. Use method provided in header.<br/>
2. <tt>GET</tt> if query string is provided in header.<br/>
3. <tt>GET</tt> if endpoint is configured with a query string.<br/>
4. <tt>POST</tt> if there is data to send (body is not null).<br/>
5. <tt>GET</tt> otherwise.</p>

<h3><a name="BookComponentAppendix-HowtogetaccesstoHttpServletRequestandHttpServletResponse"></a>How to get access to HttpServletRequest and HttpServletResponse</h3>
<p><b>Available as of Camel 2.0</b></p>

<p>You can get access to these two using the Camel type converter system using</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
HttpServletRequest response = exchange.getIn().getBody(HttpServletResponse.class);
</pre>
</div></div>

<p>Or you can get access to them from <tt>HttpMessage</tt> directly using a type cast:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HttpMessage msg = (HttpMessage) exchange.getIn();
HttpServletRequest request = msg.getRequest();
HttpServletRequest response = msg.getResponse();
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfiguringURItocall"></a>Configuring URI to call</h3>

<p>You can set the HTTP producer's URI directly form the endpoint URI. In the route below, Camel will call out to the external server, <tt>oldhost</tt>, using HTTP.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost"</span>);</span>
</pre>
</div></div>
<p>And the equivalent Spring sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://activemq.apache.org/camel/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"http://oldhost"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>
<p>In <b>Camel 1.5.1</b> you can override the HTTP endpoint URI by adding a header with the key, <tt>HttpProducer.HTTP_URI</tt>, on the message.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
            .setHeader(org.apache.camel.component.http.HttpProducer.HTTP_URI, constant(<span class="code-quote">"http:<span class="code-comment">//newhost"</span>))
</span>	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost"</span>);</span>
</pre>
</div></div>
<p>In the sample above Camel will call the <a href="http://newhost" rel="nofollow">http://newhost</a> despite the endpoint is configured with <a href="http://oldhost" rel="nofollow">http://oldhost</a>.</p>

<p>And the same code in Camel 2.0:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
            .setHeader(HttpConstants.HTTP_URI, constant(<span class="code-quote">"http:<span class="code-comment">//newhost"</span>))
</span>	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost"</span>);</span>
</pre>
</div></div>
<p>Where Constants is the class, <tt>org.apache.camel.component.http.Constants</tt>.</p>

<h3><a name="BookComponentAppendix-ConfiguringURIParameters"></a>Configuring URI Parameters</h3>

<p>The <b>http</b> producer supports URI parameters to be sent to the HTTP server. The URI parameters can either be set directly on the endpoint URI or as a header with the key <tt>HttpProducer.QUERY</tt> on the message.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost?order=123&amp;detail=<span class="code-object">short</span>"</span>);</span>
</pre>
</div></div>
<p>Or options provided in a header:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
            .setHeader(HttpConstants.HTTP_QUERY, constant(<span class="code-quote">"order=123&amp;detail=<span class="code-object">short</span>"</span>))
	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost"</span>);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Howtosetthehttpmethod%28GET%2FPOST%2FPUT%2FDELETE%2FHEAD%2FOPTIONS%2FTRACE%29totheHTTPproducer"></a>How to set the http method (GET/POST/PUT/DELETE/HEAD/OPTIONS/TRACE) to the HTTP producer</h3>

<p>The HTTP component provides a way to set the HTTP request method by setting the message header. Here is an example;</p>

<p><b>Camel 1.x</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
            .setHeader(HttpConstants.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST))
	    .to(<span class="code-quote">"http:<span class="code-comment">//www.google.com"</span>)
</span>            .to(<span class="code-quote">"mock:results"</span>);
</pre>
</div></div>

<p><b>Camel 2.x</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
            .setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST))
	    .to(<span class="code-quote">"http:<span class="code-comment">//www.google.com"</span>)
</span>            .to(<span class="code-quote">"mock:results"</span>);
</pre>
</div></div>

<p>The method can be written a bit shorter using the string constants:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.setHeader(<span class="code-quote">"CamelHttpMethod"</span>, constant(<span class="code-quote">"POST"</span>))
</pre>
</div></div>

<p>And the equivalent Spring sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://activemq.apache.org/camel/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
    <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHttpMethod"</span>&gt;</span>
        <span class="code-tag">&lt;constant&gt;</span>POST<span class="code-tag">&lt;/constant&gt;</span>
    <span class="code-tag">&lt;/setHeader&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"http://www.google.com"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:results"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-UsingclienttineoutSOTIMEOUT"></a>Using client tineout - SO_TIMEOUT</h3>
<p>See the unit test in <a href="http://svn.apache.org/viewvc?view=rev&amp;revision=781775" rel="nofollow">this link</a></p>


<h3><a name="BookComponentAppendix-ConfiguringaProxy"></a>Configuring a Proxy</h3>
<p><b>Only for &gt;= Camel 1.6.2</b><br/>
The HTTP component provides a way to configure a proxy.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
	    .to(<span class="code-quote">"http:<span class="code-comment">//oldhost?proxyHost=www.myproxy.com&amp;proxyPort=80"</span>);</span>
</pre>
</div></div>

<p>There is also support for proxy authentication via the <tt>proxyUsername</tt> and <tt>proxyPassword</tt> options.</p>

<h4><a name="BookComponentAppendix-UsingproxysettingsoutsideofURI"></a>Using proxy settings outside of URI</h4>
<p>*Only for &gt;= Camel 1.6.2 and &lt; Camel 2.2.0 *<br/>
The HTTP component will detect Java System Properties for <tt>http.proxyHost</tt> and <tt>http.proxyPort</tt> and use them if provided.<br/>
See more at <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html" rel="nofollow">SUN http proxy documentation</a>.</p>

<p>To avoid the System properties conflicts, from Camel 2.2.0 you can only set the proxy configure from CameContext or URI.<br/>
Java DSL :</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
 context.getProperties().put(<span class="code-quote">"http.proxyHost"</span>, <span class="code-quote">"172.168.18.9"</span>);
 context.getProperties().put(<span class="code-quote">"http.proxyPort"</span> <span class="code-quote">"8080"</span>);
</pre>
</div></div>
<p>Spring XML</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   &lt;camelContext&gt;
       &lt;properties&gt;
           &lt;property key=<span class="code-quote">"http.proxyHost"</span> value=<span class="code-quote">"172.168.18.9"</span>/&gt;
           &lt;property key=<span class="code-quote">"http.proxyPort"</span> value=<span class="code-quote">"8080"</span>/&gt;
      &lt;/properties&gt;
   &lt;/camelContext&gt;
</pre>
</div></div>
<p>Camel will first set the settings from Java System or CamelContext Properties and then the endpoint proxy options if provided.<br/>
So you can override the system properties with the endpoint options.</p>

<h3><a name="BookComponentAppendix-Configuringcharset"></a>Configuring charset</h3>

<p>If you are using <tt>POST</tt> to send data you can configure the <tt>charset</tt> using the <tt>Exchange</tt> property:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
exchange.setProperty(Exchange.CHARSET_NAME, <span class="code-quote">"iso-8859-1"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Samplewithscheduledpoll"></a>Sample with scheduled poll</h4>

<p>The sample polls the Google homepage every 10 seconds and write the page to the file <tt>message.html</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"timer:<span class="code-comment">//foo?fixedRate=<span class="code-keyword">true</span>&amp;delay=0&amp;period=10000"</span>)
</span>    .to(<span class="code-quote">"http:<span class="code-comment">//www.google.com"</span>)
</span>    .setHeader(FileComponent.HEADER_FILE_NAME, <span class="code-quote">"message.html"</span>).to(<span class="code-quote">"file:target/google"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-URIParametersfromtheendpointURI"></a>URI Parameters from the endpoint URI</h4>

<p>In this sample we have the complete URI endpoint that is just what you would have typed in a web browser. Multiple URI parameters can of course be set using the <tt>&amp;</tt> character as separator, just as you would in the web browser. Camel does no tricks here.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// we query <span class="code-keyword">for</span> Camel at the Google page
</span>template.sendBody(<span class="code-quote">"http:<span class="code-comment">//www.google.com/search?q=Camel"</span>, <span class="code-keyword">null</span>);</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-URIParametersfromtheMessage"></a>URI Parameters from the Message</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Map headers = <span class="code-keyword">new</span> HashMap();
headers.put(HttpProducer.QUERY, <span class="code-quote">"q=Camel&amp;lr=lang_en"</span>);
<span class="code-comment">// we query <span class="code-keyword">for</span> Camel and English language at Google
</span>template.sendBody(<span class="code-quote">"http:<span class="code-comment">//www.google.com/search"</span>, <span class="code-keyword">null</span>, headers);</span>
</pre>
</div></div>
<p>In the header value above notice that it should <b>not</b> be prefixed with <tt>?</tt> and you can separate parameters as usual with the <tt>&amp;</tt> char.</p>

<h4><a name="BookComponentAppendix-GettingtheResponseCode"></a>Getting the Response Code</h4>

<p>You can get the HTTP response code from the HTTP component by getting the value from the Out message header with <tt>HttpProducer.HTTP_RESPONSE_CODE</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Exchange exchange = template.send(<span class="code-quote">"http:<span class="code-comment">//www.google.com/search"</span>, <span class="code-keyword">new</span> Processor() {
</span>            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                exchange.getIn().setHeader(HttpProducer.QUERY, constant(<span class="code-quote">"hl=en&amp;q=activemq"</span>));
            }
   });
   Message out = exchange.getOut();
   <span class="code-object">int</span> responseCode = out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, <span class="code-object">Integer</span>.class);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Using%7B%7BthrowExceptionOnFailure%3Dfalse%7D%7Dtogetanyresponseback"></a>Using <tt>throwExceptionOnFailure=false</tt> to get any response back</h3>

<p><b>Available as of Camel 2.0</b><br/>
In the route below we want to route a message that we <a href="/confluence/display/CAMEL/Content+Enricher" title="Content Enricher">enrich</a> with data returned from a remote HTTP call. As we want any response from the remote server, we set the <tt>throwExceptionOnFailure</tt> option to <tt>false</tt> so we get any response in the <tt>AggregationStrategy</tt>. As the code is based on a unit test that simulates a HTTP status code 404, there is some assertion code etc.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// We set throwExceptionOnFailure to <span class="code-keyword">false</span> to let Camel <span class="code-keyword">return</span> any response from the remove HTTP server without thrown
</span><span class="code-comment">// HttpOperationFailedException in <span class="code-keyword">case</span> of failures.
</span><span class="code-comment">// This allows us to handle all responses in the aggregation strategy where we can check the HTTP response code
</span><span class="code-comment">// and decide what to <span class="code-keyword">do</span>. As <span class="code-keyword">this</span> is based on an unit test we <span class="code-keyword">assert</span> the code is 404
</span>from(<span class="code-quote">"direct:start"</span>).enrich(<span class="code-quote">"http:<span class="code-comment">//localhost:8222/myserver?throwExceptionOnFailure=<span class="code-keyword">false</span>&amp;user=Camel"</span>, <span class="code-keyword">new</span> AggregationStrategy() {
</span>    <span class="code-keyword">public</span> Exchange aggregate(Exchange original, Exchange resource) {
        <span class="code-comment">// get the response code
</span>        <span class="code-object">Integer</span> code = resource.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, <span class="code-object">Integer</span>.class);
        assertEquals(404, code.intValue());
        <span class="code-keyword">return</span> resource;
    }
}).to(<span class="code-quote">"mock:result"</span>);

<span class="code-comment">// <span class="code-keyword">this</span> is our jetty server where we simulate the 404
</span>from(<span class="code-quote">"jetty:<span class="code-comment">//http://localhost:8222/myserver"</span>)
</span>        .process(<span class="code-keyword">new</span> Processor() {
            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                exchange.getOut().setBody(<span class="code-quote">"Page not found"</span>);
                exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
            }
        });
</pre>
</div></div>

<h3><a name="BookComponentAppendix-DisablingCookies"></a>Disabling Cookies</h3>
<p>To disable cookies you can set the HTTP Client to ignore cookies by adding this URI option:<br/>
<tt>httpClient.cookiePolicy=ignoreCookies</tt></p>

<h3><a name="BookComponentAppendix-AdvancedUsage"></a>Advanced Usage</h3>

<p>If you need more control over the HTTP producer you should use the <tt>HttpComponent</tt> where you can set various classes to give you custom behavior.</p>

<h4><a name="BookComponentAppendix-SettingMaxConnectionsPerHost"></a>Setting MaxConnectionsPerHost</h4>

<p>The <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a> Component has a <tt>org.apache.commons.httpclient.HttpConnectionManager</tt> where you can configure various global configuration for the given component.<br/>
By global, we mean that any endpoint the component creates has the same shared <tt>HttpConnectionManager</tt>. So, if we want to set a different value for the max connection per host, we need to define it on the HTTP component and <b>not</b> on the endpoint URI that we usually use. So here comes:</p>

<p>First, we define the <tt>http</tt> component in Spring XML. Yes, we use the same scheme name, <tt>http</tt>, because otherwise Camel will auto-discover and create the component with default settings. What we need is to overrule this so we can set our options. In the sample below we set the max connection to 5 instead of the default of 2.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"http"</span> class=<span class="code-quote">"org.apache.camel.component.http.HttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"camelContext"</span> ref=<span class="code-quote">"camel"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"httpConnectionManager"</span> ref=<span class="code-quote">"myHttpConnectionManager"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myHttpConnectionManager"</span> class=<span class="code-quote">"org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"params"</span> ref=<span class="code-quote">"myHttpConnectionManagerParams"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myHttpConnectionManagerParams"</span> class=<span class="code-quote">"org.apache.commons.httpclient.params.HttpConnectionManagerParams"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"defaultMaxConnectionsPerHost"</span> value=<span class="code-quote">"5"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

</pre>
</div></div>
<p>And then we can just use it as we normally do in our routes:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span> trace=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"http://www.google.com"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingHTTPStoauthenticategotchas"></a>Using HTTPS to authenticate gotchas</h4>
<p>An end user reported that he had problem with authenticating with HTTPS. The problem was eventually resolved when he discovered the HTTPS server did not return a HTTP code 401 Authorization Required. The solution was to set the following URI option: <tt>httpClient.authenticationPreemptive=true</tt></p>

<h4><a name="BookComponentAppendix-Acceptingselfsignedcertificationsfromremoteserver"></a>Accepting self signed certifications from remote server</h4>
<p>See this <a href="http://www.nabble.com/Using-HTTPS-in-camel-http-when-remote-side-has-self-signed-cert-td25916878.html" rel="nofollow">link</a> from a mailing list discussion with some code to outline how to do this with the Apache Commons HTTP API.</p>

<h4><a name="BookComponentAppendix-SettingupSSLforHTTPClient"></a>Setting up SSL for HTTP Client</h4>
<p>Basically camel-http component is built on the top of Apache HTTP client, and you can implement a custom <tt>org.apache.camel.component.http.HttpClientConfigurer</tt> to do some configuration on the http client if you need full control of it.</p>

<p>However if you <em>just</em> want to specify the keystore and truststore you can do this with Apache HTTP <tt>HttpClientConfigurer</tt>, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Protocol authhttps = <span class="code-keyword">new</span> Protocol(<span class="code-quote">"https"</span>, <span class="code-keyword">new</span> AuthSSLProtocolSocketFactory(
  <span class="code-keyword">new</span> URL(<span class="code-quote">"file:my.keystore"</span>), <span class="code-quote">"mypassword"</span>,
  <span class="code-keyword">new</span> URL(<span class="code-quote">"file:my.truststore"</span>), <span class="code-quote">"mypassword"</span>), 443);

Protocol.registerProtocol(<span class="code-quote">"https"</span>, authhttps);
</pre>
</div></div>

<p>And then you need to create a class that implements <tt>HttpClientConfigurer</tt>, and registers https protocol providing a keystore or truststore per example above. Then, from your camel route builder class you can hook it up like so:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HttpComponent httpComponent = getContext().getComponent(<span class="code-quote">"http"</span>, HttpComponent.class);
httpComponent.setHttpClientConfigurer(<span class="code-keyword">new</span> MyHttpClientConfigurer());
</pre>
</div></div>

<p>If you are doing this using the Spring DSL, you can specify your <tt>HttpClientConfigurer</tt> using the URI.  For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"myHttpClientConfigurer"</span>
 class=<span class="code-quote">"my.https.HttpClientConfigurer"</span>&gt;
&lt;/bean&gt;

&lt;to uri=<span class="code-quote">"https:<span class="code-comment">//myhostname.com:443/myURL?httpClientConfigurerRef=myHttpClientConfigurer"</span>/&gt; </span>
</pre>
</div></div>

<p>As long as you implement the HttpClientConfigurer and configure your keystore and truststore as described above, it will work fine.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a></li>
</ul>

<h2><a name="BookComponentAppendix-iBATIS"></a>iBATIS</h2>

<p>The <b>ibatis:</b> component allows you to query, poll, insert, update and delete data in a relational database using <a href="http://ibatis.apache.org/" rel="nofollow">Apache iBATIS</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ibatis:statementName[?options]
</pre>
</div></div>

<p>Where <b>statementName</b> is the name in the iBATIS XML configuration file which maps to the query, insert, update or delete operation you wish to evaluate.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<p>This component will by default load the iBatis SqlMapConfig file from the root of the classpath and expected named as <tt>SqlMapConfig.xml</tt>.<br/>
It uses Spring resource loading so you can define it using <tt>classpath</tt>, <tt>file</tt> or <tt>http</tt> as prefix to load resources with those schemes.<br/>
In Camel 2.2 you can configure this on the iBatisComponent with the <tt>setSqlMapConfig(String)</tt> method.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.onConsume</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Statements to run after consuming. Can be used, for example, to update rows after they have been consumed and processed in Camel. See sample later. Multiple statements can be separated with comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.useIterator</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If <tt>true</tt> each row returned when polling will be processed individually. If <tt>false</tt> the entire <tt>List</tt> of data is set as the IN body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.routeEmptyResultSet</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Sets whether empty result set should be routed or not. By default, empty result sets are not routed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>statementType</tt> </td>
<td class='confluenceTd'> <tt>StatementType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Mandatory to specify for IbatisProducer to control which iBatis <tt>SqlMapClient</tt> method to invoke. The enum values are: <tt>QueryForObject</tt>, <tt>QueryForList</tt>, <tt>Insert</tt>, <tt>Update</tt>, <tt>Delete</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> An integer to define a maximum messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disabled it. </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel will populate the result message, either IN or OUT with a header with the operationName used:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.ibatis.queryName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Camel 1.x: The <b>statementName</b> used (for example: insertAccount). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelIBatisStatementName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Camel 2.0: The <b>statementName</b> used (for example: insertAccount). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelIBatisResult</tt> </td>
<td class='confluenceTd'> <tt>Object</tt> </td>
<td class='confluenceTd'> Camel 1.6.2/2.0: The <b>response</b> returned from iBatis in any of the operations. For instance an <tt>INSERT</tt> could return the auto-generated key, or number of rows etc. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageBody"></a>Message Body</h3>
<p><b>Camel 1.6.1</b>: The response from iBatis will be set as OUT body <br/>
<b>Camel 1.6.2/2.0</b>: The response from iBatis will only be set as body if it's a <tt>SELECT</tt> statement. That means, for example, for <tt>INSERT</tt> statements Camel will not replace the body. This allows you to continue routing and keep the original body. The response from iBatis is always stored in the header with the key <tt>CamelIBatisResult</tt>.</p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>For example if you wish to consume beans from a JMS queue and insert them into a database you could do the following:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:newAccount"</span>).
  to(<span class="code-quote">"ibatis:insertAccount?statementType=Insert"</span>);
</pre>
</div></div>

<p>Notice we have to specify the <tt>statementType</tt>, as we need to instruct Camel which <tt>SqlMapClient</tt> operation to invoke.</p>

<p>Where <b>insertAccount</b> is the iBatis ID in the SQL map file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag"><span class="code-comment">&lt;!-- Insert example, using the Account parameter class --&gt;</span></span>
  <span class="code-tag">&lt;insert id=<span class="code-quote">"insertAccount"</span> parameterClass=<span class="code-quote">"Account"</span>&gt;</span>
    insert into ACCOUNT (
      ACC_ID,
      ACC_FIRST_NAME,
      ACC_LAST_NAME,
      ACC_EMAIL
    )
    values (
      #id#, #firstName#, #lastName#, #emailAddress#
    )
  <span class="code-tag">&lt;/insert&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-UsingStatementTypeforbettercontrolofIBatis"></a>Using StatementType for better control of IBatis</h3>
<p><b>Available as of Camel 1.6.1/2.0</b><br/>
When routing to an iBatis endpoint you want more fine grained control so you can control whether the SQL statement to be executed is a <tt>SELEECT</tt>, <tt>UPDATE</tt>, <tt>DELETE</tt> or <tt>INSERT</tt> etc. This is now possible in Camel 1.6.1/2.0. So for instance if we want to route to an iBatis endpoint in which the IN body contains parameters to a <tt>SELECT</tt> statement we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:selectAccountById?statementType=QueryForObject"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>In the code above we can invoke the iBatis statement <tt>selectAccountById</tt> and the IN body should contain the account id we want to retrieve, such as an <tt>Integer</tt> type.</p>

<p>We can do the same for some of the other operations, such as <tt>QueryForList</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:selectAllAccounts?statementType=QueryForList"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>And the same for <tt>UPDATE</tt>, where we can send an <tt>Account</tt> object as IN body to iBatis:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:updateAccount?statementType=Update"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>


<h4><a name="BookComponentAppendix-Scheduledpollingexample"></a>Scheduled polling example</h4>
<p>Since this component does not support scheduled polling, you need to use another mechanism for triggering the scheduled polls, such as the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> or <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a> components.</p>

<p>In the sample below we poll the database, every 30 seconds using the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> component and send the data to the JMS queue:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"timer:<span class="code-comment">//pollTheDatabase?delay=30000"</span>).to(<span class="code-quote">"ibatis:selectAllAccounts?statementType=QueryForList"</span>).to(<span class="code-quote">"activemq:queue:allAccounts"</span>);</span>
</pre>
</div></div>

<p>And the iBatis SQL map file used:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag"><span class="code-comment">&lt;!-- Select with no parameters using the result map for Account class. --&gt;</span></span>
  <span class="code-tag">&lt;select id=<span class="code-quote">"selectAllAccounts"</span> resultMap=<span class="code-quote">"AccountResult"</span>&gt;</span>
    select * from ACCOUNT
  <span class="code-tag">&lt;/select&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingonConsume"></a>Using onConsume</h4>
<p>This component supports executing statements <b>after</b> data have been consumed and processed by Camel. This allows you to do post updates in the database. Notice all statements must be <tt>UPDATE</tt> statements. Camel supports executing multiple statements whose name should be separated by comma.</p>

<p>The route below illustrates we execute the <b>consumeAccount</b> statement data is processed. This allows us to change the status of the row in the database to processed, so we avoid consuming it twice or more.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"ibatis:selectUnprocessedAccounts?consumer.onConsume=consumeAccount"</span>).to(<span class="code-quote">"mock:results"</span>);
</pre>
</div></div>

<p>And the statements in the sqlmap file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;select id=<span class="code-quote">"selectUnprocessedAccounts"</span> resultMap=<span class="code-quote">"AccountResult"</span>&gt;</span>
     select * from ACCOUNT where PROCESSED = false
<span class="code-tag">&lt;/select&gt;</span>
</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;update id=<span class="code-quote">"consumeAccount"</span> parameterClass=<span class="code-quote">"Account"</span>&gt;</span>
     update ACCOUNT set PROCESSED = true where ACC_ID = #id#
<span class="code-tag">&lt;/update&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-IRCComponent"></a>IRC Component</h2>

<p>The <b>irc</b> component implements an <a href="http://en.wikipedia.org/wiki/Internet_Relay_Chat" rel="nofollow">IRC</a> (Internet Relay Chat) transport.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
irc:nick@host[:port]/#room[?options]
</pre>
</div></div>

<p>In Camel 2.0, you can also use the following format:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
irc:nick@host[:port]?channels=#channel1,#channel2,#channel3[?options]
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>channels</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Comma separated list of IRC channels to join. </td>
<td class='confluenceTd'> <tt>channels=#channel1,#channel2</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nickname</tt> </td>
<td class='confluenceTd'> The nickname used in chat. </td>
<td class='confluenceTd'> <tt>irc:MyNick@irc.server.org#channel</tt> or <tt>irc:irc.server.org#channel?nickname=MyUser</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> The IRC server user name. </td>
<td class='confluenceTd'> <tt>irc:MyUser@irc.server.org#channel</tt> or <tt>irc:irc.server.org#channel?username=MyUser</tt> </td>
<td class='confluenceTd'> Same as nickname. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> The IRC server password. </td>
<td class='confluenceTd'> <tt>password=somepass</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>realname</tt> </td>
<td class='confluenceTd'> The IRC user's actual name. </td>
<td class='confluenceTd'> <tt>realname=MyName</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>colors</tt> </td>
<td class='confluenceTd'> Whether or not the server supports color codes. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onReply</tt> </td>
<td class='confluenceTd'> Whether or not to handle general responses to commands or informational messages. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onNick</tt> </td>
<td class='confluenceTd'> Handle nickname change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onQuit</tt> </td>
<td class='confluenceTd'> Handle user quit events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onJoin</tt> </td>
<td class='confluenceTd'> Handle user join events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onKick</tt> </td>
<td class='confluenceTd'> Handle kick events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onMode</tt> </td>
<td class='confluenceTd'> Handle mode change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onPart</tt> </td>
<td class='confluenceTd'> Handle user part events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onTopic</tt> </td>
<td class='confluenceTd'> Handle topic change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onPrivmsg</tt> </td>
<td class='confluenceTd'> Handle message events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trustManager</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> The trust manager used to verify the SSL server's certificate. </td>
<td class='confluenceTd'> <tt>trustManager=#referenceToTrustManagerBean</tt> </td>
<td class='confluenceTd'> The default trust manager, which accepts <em>all</em> certificates, will be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keys</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Comma separated list of IRC channel keys. Important to be listed in same order as channels. When joining multiple channels with only some needing keys just insert an empty value for that channel. </td>
<td class='confluenceTd'> <tt>irc:MyNick@irc.server.org/#channel?keys=chankey</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-SSLSupport"></a>SSL Support</h3>

<p>As of Camel 2.0, you can also connect to an SSL enabled IRC server, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ircs:host[:port]/#room?username=user&amp;password=pass
</pre>
</div></div>

<p>By default, the IRC transport uses <a href="http://moepii.sourceforge.net/irclib/javadoc/org/schwering/irc/lib/ssl/SSLDefaultTrustManager.html" rel="nofollow">SSLDefaultTrustManager</a>. If you need to provide your own custom trust manager, use the <tt>trustManager</tt> parameter as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ircs:host[:port]/#room?username=user&amp;password=pass&amp;trustManager=#referenceToMyTrustManagerBean
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Usingkeys"></a>Using keys</h3>
<p><b>Available as of Camel 2.2</b></p>

<p>Some irc rooms requires you to provide a key to be able to join that channel. The key is just a secret word. </p>

<p>For example we join 3 channels where as only channel 1 and 3 uses a key.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
irc:nick@irc.server.org?channels=#chan1,#chan2,#chan3&amp;keys=chan1Key,,chan3key
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-JavaSpaceComponent"></a>JavaSpace Component</h2>
<p><b>Available as of Camel 2.1</b></p>

<p>The <b>javaspace</b> component is a transport for working with any JavaSpace compliant implementation and this component has been tested with both the <a href="http://www.dancres.org/blitz/" rel="nofollow">Blitz implementation </a> and the <a href="http://www.gigaspaces.com/" rel="nofollow">GigaSpace implementation </a>.<br/>
This component can be used for sending and receiving any object inheriting from the Jini <tt>net.jini.core.entry.Entry</tt> class. It is also possible to pass the bean ID of a template that can be used for reading/taking the entries from the space.<br/>
This component can be used for sending/receiving any serializable object acting as a sort of generic transport. The JavaSpace component contains a special optimization for dealing with the <tt>BeanExchange</tt>. It can be used to invoke a POJO remotely, using a JavaSpace as a transport.<br/>
This latter feature can provide a simple implementation of the master/worker pattern, where a POJO provides the business logic for the worker.<br/>
Look at the test cases for examples of various use cases for this component.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
javaspace:jini:<span class="code-comment">//host[?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Examples"></a>Examples</h3>

<h4><a name="BookComponentAppendix-SendingandReceivingEntries"></a>Sending and Receiving Entries</h4>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>//Sending route
from("direct:input").to("javaspace:jini://localhost?spaceName=mySpace");

//Receiving Route
from("javaspace:jini://localhost?spaceName=mySpace&amp;templateId=template&amp;verb=take&amp;concurrentConsumers=1")
</pre>
</div></div>

<p>In this case the payload can be any object that inherits from the Jini <tt>Entry</tt> type.</p>

<h4><a name="BookComponentAppendix-Sendingandreceivingserializableobjects"></a>Sending and receiving serializable objects</h4>
<p>Using the preceding routes, it is also possible to send and receive any serializable object. The JavaSpace component detects that the payload is not a Jini <tt>Entry</tt> and then it automatically wraps the payload with a Camel Jini <tt>Entry</tt>. In this way, a JavaSpace can be used as a generic transport mechanism.</p>

<h4><a name="BookComponentAppendix-UsingJavaSpaceasaremoteinvocationtransport"></a>Using JavaSpace as a remote invocation transport</h4>
<p>The JavaSpace component has been tailored to work in combination with the Camel bean component. It is therefore possible to call a remote POJO using JavaSpace as the transport:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>from("direct:input").to("javaspace:jini://localhost?spaceName=mySpace"); //Client side

from("javaspace:jini://localhost?concurrentConsumers=10&amp;spaceName=mySpace").to("pojo:pojo"); //Server side
</pre>
</div></div>

<p>In the code there are two test cases showing how to use a POJO to realize the master/worker pattern. The idea is to use the POJO to provide the business logic and rely on Camel for sending/receiving requests/replies with the proper correlation.  </p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>spaceName</tt>  </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the JavaSpace name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>verb</tt>  </td>
<td class='confluenceTd'> <tt>take</tt> </td>
<td class='confluenceTd'> Specifies the verb for getting JavaSpace entries. The values can be: <tt>take</tt> or <tt>read</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactional</tt>  </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, sending and receiving entries is performed within a transaction. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionalTimeout</tt>  </td>
<td class='confluenceTd'> <tt>Long.MAX_VALUE</tt> </td>
<td class='confluenceTd'> Specifies the transaction timeout.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>concurrentConsumers</tt>  </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the number of concurrent consumers getting entries from the JavaSpace. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>templateId</tt>  </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> If present, this option specifies the Spring bean ID of the template to use for reading/taking entries. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-JBIComponent"></a>JBI Component</h2>

<p>The <b>jbi</b> component is implemented by the <a href="http://servicemix.apache.org/servicemix-camel.html" rel="nofollow">ServiceMix Camel module</a> and provides integration with a JBI Normalized Message Router, such as the one provided by <a href="http://servicemix.apache.org/" rel="nofollow">Apache ServiceMix</a>.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>See below for information about how to use <tt>StreamSource</tt> types from <a href="http://servicemix.apache.org/" rel="nofollow">ServiceMix</a> in Camel.</p></td></tr></table></div>

<p>The following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jbi:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>)</span>
</pre>
</div></div>

<p>Automatically exposes a new endpoint to the bus, where the service QName is {<tt><a href="http://foo.bar.org" rel="nofollow">http://foo.bar.org</a>}MyService</tt> and the endpoint name is <tt>MyEndpoint</tt> (see <a href="#BookComponentAppendix-URIformat">URI&#45;format</a>).</p>

<p>When a JBI endpoint appears at the end of a route, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
to(<span class="code-quote">"jbi:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>)</span>
</pre>
</div></div>

<p>The messages sent by this producer endpoint are sent to the already deployed JBI endpoint.</p>

<p><a name="BookComponentAppendix-URIformat"></a></p>
<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jbi:service:serviceNamespace[sep]serviceName[?options]
jbi:endpoint:serviceNamespace[sep]serviceName[sep]endpointName[?options]
jbi:name:endpointName[?options]
</pre>
</div></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>, or</li>
	<li><tt>:</tt> (colon), if <tt>serviceNamespace</tt> starts with <tt>urn:foo:bar</tt>.</li>
</ul>


<p>For more details of valid JBI URIs see the <a href="http://servicemix.apache.org/uris.html" rel="nofollow">ServiceMix URI Guide</a>. </p>

<p>Using the <tt>jbi:service:</tt> or <tt>jbi:endpoint:</tt> URI formats sets the service QName on the JBI endpoint to the one specified. Otherwise, the default Camel JBI Service QName is used, which is:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
{http:<span class="code-comment">//activemq.apache.org/camel/schema/jbi}endpoint</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h4><a name="BookComponentAppendix-Examples"></a>Examples</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jbi:service:http:<span class="code-comment">//foo.bar.org/MyService
</span>jbi:endpoint:urn:foo:bar:MyService:MyEndpoint
jbi:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint
</span>jbi:name:cheese
</pre>
</div></div>

<h3><a name="BookComponentAppendix-URIoptions"></a>URI options</h3>
<table class='confluenceTable'><tbody>
<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> 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 </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 exceptions thrown from the Camel route back unmodified <br clear="all" /> <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>
</tbody></table>

<h4><a name="BookComponentAppendix-Examples"></a>Examples</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jbi:service:http:<span class="code-comment">//foo.bar.org/MyService?mep=in-out       (override the MEP, use InOut JBI MessageExchanges)
</span>jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?mep=in      (override the MEP, use InOnly JBI MessageExchanges)  
jbi:endpoint:urn:foo:bar:MyService:MyEndpoint?operation={http:<span class="code-comment">//www.mycompany.org}AddNumbers 
</span> (overide the operation <span class="code-keyword">for</span> the JBI Exchange to {http:<span class="code-comment">//www.mycompany.org}AddNumbers)</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-UsingStreambodies"></a>Using Stream bodies</h3>
<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="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jbi:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>).streamCaching().to(<span class="code-quote">"xslt:transform.xsl"</span>, <span class="code-quote">"bean:doSomething"</span>);</span>
</pre>
</div></div>

<p>From <b>Camel 1.5</b> onwards, the stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt> option.<br/>
In <b>Camel 2.0</b> we store big 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>

<h3><a name="BookComponentAppendix-CreatingaJBIServiceUnit"></a>Creating a JBI Service Unit</h3>

<p>If you have some Camel routes that you want to deploy inside JBI as a Service Unit, you can use the <a href="/confluence/display/CAMEL/JBI+Service+Unit+Archetype" title="JBI Service Unit Archetype">JBI Service Unit Archetype</a> to create a new Maven project for the Service Unit.</p>

<p>If you have an existing Maven project that you need to convert into a JBI Service Unit, you may want to consult <a href="http://servicemix.apache.org/maven-jbi-plugin.html" rel="nofollow">ServiceMix Maven JBI Plugins</a> for further help. The key steps are as follows:</p>

<ul>
	<li>Create a Spring XML file at <tt>src/main/resources/camel-context.xml</tt> to bootstrap your routes inside the JBI Service Unit.</li>
	<li>Change the POM file's packaging to <tt>jbi-service-unit</tt>.</li>
</ul>


<p>Your <tt>pom.xml</tt> should look something like this to enable the <tt>jbi-service-unit</tt> packaging: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;project xmlns=<span class="code-quote">"http:<span class="code-comment">//maven.apache.org/POM/4.0.0"</span> xmlns:xsi=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
</span>         xsi:schemaLocation=<span class="code-quote">"http:<span class="code-comment">//maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"</span>&gt;
</span>
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

  &lt;groupId&gt;myGroupId&lt;/groupId&gt;
  &lt;artifactId&gt;myArtifactId&lt;/artifactId&gt;
  &lt;packaging&gt;jbi-service-unit&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

  &lt;name&gt;A Camel based JBI Service Unit&lt;/name&gt;

  &lt;url&gt;http:<span class="code-comment">//www.myorganization.org&lt;/url&gt;
</span>
  &lt;properties&gt;
    &lt;camel-version&gt;1.0.0&lt;/camel-version&gt;
    &lt;servicemix-version&gt;3.3&lt;/servicemix-version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.servicemix&lt;/groupId&gt;
      &lt;artifactId&gt;servicemix-camel&lt;/artifactId&gt;
      &lt;version&gt;${servicemix-version}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.servicemix&lt;/groupId&gt;
      &lt;artifactId&gt;servicemix-core&lt;/artifactId&gt;
      &lt;version&gt;${servicemix-version}&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;defaultGoal&gt;install&lt;/defaultGoal&gt;

    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.5&lt;/source&gt;
          &lt;target&gt;1.5&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

      &lt;!-- creates the JBI deployment unit --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.servicemix.tooling&lt;/groupId&gt;
        &lt;artifactId&gt;jbi-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;${servicemix-version}&lt;/version&gt;
        &lt;extensions&gt;<span class="code-keyword">true</span>&lt;/extensions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="http://servicemix.apache.org/servicemix-camel.html" rel="nofollow">ServiceMix Camel module</a></li>
	<li><a href="http://servicemix.apache.org/3-beginner-using-apache-camel-inside-servicemix.html" rel="nofollow">Using Camel with ServiceMix</a></li>
	<li><a href="http://servicemix.apache.org/order-file-processing.html" rel="nofollow">Cookbook on using Camel with ServiceMix</a></li>
</ul>

<h2><a name="BookComponentAppendix-JCRComponent"></a>JCR Component</h2>

<p>The <b><tt>jcr</tt></b> component allows you to add nodes to a JCR (JSR-170) compliant content repository (for example, <a href="http://jackrabbit.apache.org/" rel="nofollow">Apache Jackrabbit </a>).</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jcr:<span class="code-comment">//user:password@repository/path/to/node</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>The <tt>repository</tt> element of the URI is used to look up the JCR <tt>Repository</tt> object in the Camel context registry.</p>

<p>If a message is sent to a JCR producer endpoint:</p>
<ul>
	<li>A new node is created in the content repository,</li>
	<li>All the message properties of the IN message are transformed to JCR <tt>Value</tt> instances and added to the new node,</li>
	<li>The node's UUID is returned in the OUT message.</li>
</ul>


<h3><a name="BookComponentAppendix-Messageproperties"></a>Message properties</h3>
<p>All message properties are converted to node properties, except for the <tt>CamelJcrNodeName</tt> property (you can refer to <tt>JcrConstants.NODE_NAME</tt> in your code), which is used to determine the node name.</p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>The snippet below creates a node named <tt>node</tt> under the <tt>/home/test</tt> node in the content repository.  One additional attribute is added to the node as well: <tt>my.contents.property</tt> which will contain the body of the message being sent.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:a"</span>).setProperty(JcrConstants.JCR_NODE_NAME, constant(<span class="code-quote">"node"</span>))
    .setProperty(<span class="code-quote">"my.contents.property"</span>, body()).to(<span class="code-quote">"jcr:<span class="code-comment">//user:pass@repository/home/test"</span>);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-JDBCComponent"></a>JDBC Component</h2>

<p>The <b>jdbc</b> component enables you to access databases through JDBC, where SQL queries and operations are sent in the message body. This component uses the standard JDBC API, unlike the <a href="/confluence/display/CAMEL/SQL+Component" title="SQL Component">SQL Component</a> component, which uses spring-jdbc. </p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>This component can only be used to define producer endpoints, which means that you cannot use the JDBC component in a <tt>from()</tt> statement.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jdbc:dataSourceName[?options]
</pre>
</div></div>

<p>This component only supports producer endpoints.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>readSize</tt> </td>
<td class='confluenceTd'> <tt>0</tt> / <tt>2000</tt> </td>
<td class='confluenceTd'> The default maximum number of rows that can be read by a polling query. The default value is 2000 for Camel 1.5.0 or older. In newer releases the default value is 0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>statement.&lt;xxx&gt;</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Sets additional options on the <tt>java.sql.Statement</tt> that is used behind the scenes to execute the queries. For instance, <tt>statement.maxRows=10</tt>. For detailed documentation, see the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html" rel="nofollow"><tt>java.sql.Statement</tt> javadoc</a> documentation. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useJDBC4ColumnNameAndLabelSemantics</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.3/2.2:</b> Sets whether to use JDBC 4/3 column label/name semantics. You can use this option to turn it <tt>false</tt> in case you have issues with your JDBC driver to select data. This only applies when using <tt>SQL SELECT</tt> using aliases (e.g. <tt>SQL SELECT id as identifier, name as given_name from persons</tt>). </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Result"></a>Result</h3>
<p>The result is returned in the OUT body as an <tt>ArrayList&lt;HashMap&lt;String, Object&gt;&gt;</tt>. The <tt>List</tt> object contains the list of rows and the <tt>Map</tt> objects contain each row with the <tt>String</tt> key as the column name.</p>

<p><b>Note:</b> This component fetches <tt>ResultSetMetaData</tt> to be able to return the column name as the key in the <tt>Map</tt>.</p>

<h4><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h4>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJdbcRowCount</tt> </td>
<td class='confluenceTd'> If the query is a <tt>SELECT</tt>, query the row count is returned in this OUT header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJdbcUpdateCount</tt> </td>
<td class='confluenceTd'> If the query is an <tt>UPDATE</tt>, query the update count is returned in this OUT header. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>In the following example, we fetch the rows from the customer table.</p>

<p>First we register our datasource in the Camel registry as <tt>testdb</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">JndiRegistry reg = <span class="code-keyword">super</span>.createRegistry();
reg.bind(<span class="code-quote">"testdb"</span>, ds);
<span class="code-keyword">return</span> reg;
</pre>
</div></div>

<p>Then we configure a route that routes to the JDBC component, so the SQL will be executed. Note how we refer to the <tt>testdb</tt> datasource that was bound in the previous step:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// lets add simple route
</span><span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
    from(<span class="code-quote">"direct:hello"</span>).to(<span class="code-quote">"jdbc:testdb?readSize=100"</span>);
}
</pre>
</div></div>

<p>Or you can create a <tt>DataSource</tt> in Spring like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;route&gt;
     &lt;from uri=<span class="code-quote">"timer:<span class="code-comment">//kickoff?period=10000"</span>/&gt;
</span>     &lt;setBody&gt;
       &lt;constant&gt;select * from customer&lt;/constant&gt;
     &lt;/setBody&gt;
     &lt;to uri=<span class="code-quote">"jdbc:testdb"</span>/&gt;
     &lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;
&lt;!-- Just add a demo to show how to bind a date source <span class="code-keyword">for</span> camel in Spring--&gt;
&lt;bean id=<span class="code-quote">"testdb"</span> class=<span class="code-quote">"org.springframework.jdbc.datasource.DriverManagerDataSource"</span>&gt;
	&lt;property name=<span class="code-quote">"driverClassName"</span> value=<span class="code-quote">"org.hsqldb.jdbcDriver"</span>/&gt;
	&lt;property name=<span class="code-quote">"url"</span> value=<span class="code-quote">"jdbc:hsqldb:mem:camel_jdbc"</span> /&gt;
	&lt;property name=<span class="code-quote">"username"</span> value=<span class="code-quote">"sa"</span> /&gt;
  &lt;property name=<span class="code-quote">"password"</span> value="" /&gt;
&lt;/bean&gt;	

</pre>
</div></div>

<p>We create an endpoint, add the SQL query to the body of the IN message, and then send the exchange. The result of the query is returned in the OUT body:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// first we create our exchange using the endpoint
</span>Endpoint endpoint = context.getEndpoint(<span class="code-quote">"direct:hello"</span>);
Exchange exchange = endpoint.createExchange();
<span class="code-comment">// then we set the SQL on the in body
</span>exchange.getIn().setBody(<span class="code-quote">"select * from customer order by ID"</span>);

<span class="code-comment">// now we send the exchange to the endpoint, and receives the response from Camel
</span>Exchange out = template.send(endpoint, exchange);

<span class="code-comment">// assertions of the response
</span>assertNotNull(out);
assertNotNull(out.getOut());
ArrayList&lt;HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;&gt; data = out.getOut().getBody(ArrayList.class);
assertNotNull(<span class="code-quote">"out body could not be converted to an ArrayList - was: "</span>
    + out.getOut().getBody(), data);
assertEquals(2, data.size());
HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; row = data.get(0);
assertEquals(<span class="code-quote">"cust1"</span>, row.get(<span class="code-quote">"ID"</span>));
assertEquals(<span class="code-quote">"jstrachan"</span>, row.get(<span class="code-quote">"NAME"</span>));
row = data.get(1);
assertEquals(<span class="code-quote">"cust2"</span>, row.get(<span class="code-quote">"ID"</span>));
assertEquals(<span class="code-quote">"nsandhu"</span>, row.get(<span class="code-quote">"NAME"</span>));
</pre>
</div></div>

<p>If you want to work on the rows one by one instead of the entire ResultSet at once you need to use the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> EIP such as:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:hello"</span>)
        <span class="code-comment">// here we split the data from the testdb into <span class="code-keyword">new</span> messages one by one
</span>        <span class="code-comment">// so the mock endpoint will receive a message per row in the table
</span>    .to(<span class="code-quote">"jdbc:testdb"</span>).split(body()).to(<span class="code-quote">"mock:result"</span>);

</pre>
</div></div>

<h3><a name="BookComponentAppendix-SamplePollingthedatabaseeveryminute"></a>Sample - Polling the database every minute</h3>
<p>If we want to poll a database using the JDBC component, we need to combine it with a polling scheduler such as the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> or <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a> etc. In the following example, we retrieve data from the database every 60 seconds:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"timer:<span class="code-comment">//foo?period=60000"</span>).setBody(constant(<span class="code-quote">"select * from customer"</span>)).to(<span class="code-quote">"jdbc:testdb"</span>).to(<span class="code-quote">"activemq:queue:customers"</span>);</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/SQL" title="SQL">SQL</a></li>
</ul>

<h2><a name="BookComponentAppendix-JettyComponent"></a>Jetty Component</h2>
<p><b>Supports non blocking <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> producer in Camel 2.1 onwards</b></p>

<p>The <b>jetty</b> component provides HTTP-based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming HTTP requests. That is, the Jetty component behaves as a simple Web server.</p>

<p>In <b>Camel 2.1</b> the <b>jetty</b> component also provides non blocking <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> for producing HTTP requests. That is it can also acts as HTTP client sending to a remote HTTP server and use non blocking in this process. See more at <a href="/confluence/display/CAMEL/ToAsync" title="ToAsync">ToAsync</a> and the <a href="/confluence/display/CAMEL/HTTP+Async+Example" title="HTTP Async Example">HTTP Async Example</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jetty:http:<span class="code-comment">//hostname[:port][/resourceUri][?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>sessionSupport</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to enable the session manager on the server side of Jetty. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5.1/2.0:</b> Configuration of Jetty's <a href="http://wiki.eclipse.org/Jetty/Tutorial/HttpClient" rel="nofollow">HttpClient</a>. For example, setting <tt>httpClient.idleTimeout=30000</tt> sets the idle timeout to 30 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5.1/2.0:</b> Reference to an <tt>org.apache.camel.component.http.HttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. <tt>HttpBinding</tt> can be used to customize how a response should be written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>matchOnUriPrefix</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b>  Whether or not the <tt>CamelServlet</tt> should try to find a target consumer by matching the URI prefix if no exact match is found. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>handlers</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Specifies a comma-delimited set of <tt>org.mortbay.jetty.Handler</tt> instances in your <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> (such as your Spring <tt>ApplicationContext</tt>). These handlers are added to the Jetty servlet context (for example, to add security). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunked</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>From Camel 2.2:</b> If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel uses the same message headers as the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a> component.<br/>
>From Camel 2.2, it also uses (Exchange.HTTP_CHUNKED,CamelHttpChunked) header to turn on or turn off the chuched encoding on the camel-jetty consumer.</p>

<p>Camel also populates <b>all</b> request.parameter and request.headers. For example, given a client request with the URL, <tt><a href="http://myserver/myserver?orderid=123" rel="nofollow">http://myserver/myserver?orderid=123</a></tt>, the exchange will contain a header named <tt>orderid</tt> with the value 123. This feature was introduced in Camel 1.5.</p>

<p>From Camel 1.6.3 and Camel 2.2.0, you can get the request.parameter from the message header not only from Get Method, but also other HTTP method.</p>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>

<p>The Jetty component only supports consumer endpoints. Therefore a Jetty endpoint URI should be used only as the <b>input</b> for a Camel route (in a <tt>from()</tt> DSL call). To issue HTTP requests against other HTTP endpoints, use the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP Component</a></p>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In this sample we define a route that exposes a HTTP service at <tt><a href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"jetty:http:<span class="code-comment">//localhost:9080/myapp/myservice"</span>).process(<span class="code-keyword">new</span> MyBookService());</span>
</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Usage of localhost</b><br /><p>When you specify <tt>localhost</tt> in a URL, Camel exposes the endpoint only on the local TCP/IP network interface, so it cannot be accessed from outside the machine it operates on.</p>

<p>If you need to expose a Jetty endpoint on a specific network interface, the numerical IP address of this interface should be used as the host. If you need to expose a Jetty endpoint on all network interfaces, the <tt>0.0.0.0</tt> address should be used.</p></td></tr></table></div>

<p>Our business logic is implemented in the <tt>MyBookService</tt> class, which accesses the HTTP request contents and then returns a response.<br/>
<b>Note:</b> The <tt>assert</tt> call appears in this example, because the code is part of an unit test.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyBookService <span class="code-keyword">implements</span> Processor {
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// just get the body as a string
</span>        <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);

        <span class="code-comment">// we have access to the HttpServletRequest here and we can grab it <span class="code-keyword">if</span> we need it
</span>        HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
        assertNotNull(req);

        <span class="code-comment">// <span class="code-keyword">for</span> unit testing
</span>        assertEquals(<span class="code-quote">"bookid=123"</span>, body);

        <span class="code-comment">// send a html response
</span>        exchange.getOut().setBody(<span class="code-quote">"&lt;html&gt;&lt;body&gt;Book 123 is Camel in Action&lt;/body&gt;&lt;/html&gt;"</span>);
    }
}
</pre>
</div></div>

<p>The following sample shows a content-based route that routes all requests containing the URI parameter, <tt>one</tt>, to the endpoint, <tt>mock:one</tt>, and all others to <tt>mock:other</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"jetty:"</span> + serverUri)
    .choice()
    .when().simple(<span class="code-quote">"in.header.one"</span>).to(<span class="code-quote">"mock:one"</span>)
    .otherwise()
    .to(<span class="code-quote">"mock:other"</span>);
</pre>
</div></div>
<p>So if a client sends the HTTP request, <tt><a href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></tt>, the Jetty component will copy the HTTP request parameter, <tt>one</tt> to the exchange's <tt>in.header</tt>. We can then use the <tt>simple</tt> language to route exchanges that contain this header to a specific endpoint and all others to another. If we used a language more powerful than <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>&mdash;such as <a href="/confluence/display/CAMEL/EL" title="EL">EL</a> or <a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a>&mdash;we could also test for the parameter value and do routing based on the header value as well.</p>

<h3><a name="BookComponentAppendix-SessionSupport"></a>Session Support</h3>

<p>The session support option, <tt>sessionSupport</tt>, can be used to enable a <tt>HttpSession</tt> object and access the session object while processing the exchange. For example, the following route enables sessions:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"</span>/&gt;</span>
     <span class="code-tag">&lt;processRef ref=<span class="code-quote">"myCode"</span>/&gt;</span>
   <span class="code-tag">&lt;route&gt;</span>
</pre>
</div></div>

<p>The <tt>myCode</tt> <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> can be instantiated by a Spring <tt>bean</tt> element:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myCode"</span> class=<span class="code-quote">"com.mycompany.MyCodeProcessor"</span>/&gt;</span>
</pre>
</div></div>

<p>Where the processor implementation can access the <tt>HttpSession</tt> as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
     HttpSession session = ((HttpExchange)exchange).getRequest().getSession();
     ...
   }
</pre>
</div></div>   

<h3><a name="BookComponentAppendix-SSLSupport%28HTTPS%29"></a>SSL Support (HTTPS)</h3>

<p>Jetty provides SSL support out of the box. To enable Jetty to run in SSL mode, simply format the URI with the <tt>https://</tt> prefix&mdash;for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:https://0.0.0.0/myapp/myservice/"</span>/&gt;</span>
</pre>
</div></div>

<p>Jetty also needs to know where to load your keystore from and what passwords to use in order to load the correct SSL certificate. Set the following JVM System Properties:</p>

<ul>
	<li><tt>jetty.ssl.keystore</tt> specifies the location of the Java keystore file, which contains the Jetty server's own X.509 certificate in a <em>key entry</em>. A key entry stores the X.509 certificate (effectively, the <em>public key</em>) and also its associated private key.</li>
	<li><tt>jetty.ssl.password</tt> the store password, which is required to access the keystore file (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>-storepass</tt> option).</li>
	<li><tt>jetty.ssl.keypassword</tt> the key password, which is used to access the certificate's key entry in the keystore (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>-keypass</tt> option).</li>
</ul>


<p>For details of how to configure SSL on a Jetty endpoint, read the following documentation at the Jetty Site: <span style='cursor:pointer;width:auto' class='clickable' title='link' onclick='document.location.href="/confluence/pages/createpage.action?spaceKey=CAMEL&title=link&linkCreation=true&fromPageId=64903"' onkeypress='document.location.href="/confluence/pages/createpage.action?spaceKey=CAMEL&title=link&linkCreation=true&fromPageId=64903"'><a href="http://docs.codehaus.org/display/JETTY/How+to+configure+SSL" rel="nofollow">http://docs.codehaus.org/display/JETTY/How+to+configure+SSL</a></span></p>

<p>Some SSL properties aren't exposed directly by Camel, however Camel does expose the underlying SslSocketConnector, which will allow you to set properties like needClientAuth for mutual authentication requiring a client certificate or wantClientAuth for mutual authentication where a client doesn't need a certificate but can have one.  There's a slight difference between Camel 1.6.x and 2.x:</p>

<p><b>Camel 1.x</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  &lt;bean id=<span class="code-quote">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;
    &lt;property name=<span class="code-quote">"sslSocketConnector"</span>&gt;
      &lt;bean class=<span class="code-quote">"org.mortbay.jetty.security.SslSocketConnector"</span>&gt;
        &lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"..."</span> /&gt;
        &lt;property name=<span class="code-quote">"keyPassword"</span> value=<span class="code-quote">"..."</span> /&gt;
        &lt;property name=<span class="code-quote">"keystore"</span> value=<span class="code-quote">"..."</span> /&gt;
        &lt;property name=<span class="code-quote">"wantClientAuth"</span> value=<span class="code-quote">"..."</span> /&gt;
        &lt;property name=<span class="code-quote">"truststore"</span> value=<span class="code-quote">"..."</span> /&gt;
      &lt;/bean&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
</pre>
</div></div>

<p><b>Camel 2.x</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  &lt;bean id=<span class="code-quote">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;
     &lt;property name=<span class="code-quote">"sslSocketConnectors"</span>&gt;
        &lt;map&gt;
           &lt;entry key=<span class="code-quote">"8043"</span>&gt;
             &lt;bean class=<span class="code-quote">"org.mortbay.jetty.security.SslSocketConnector"</span>&gt;
               &lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"..."</span> /&gt;
               &lt;property name=<span class="code-quote">"keyPassword"</span> value=<span class="code-quote">"..."</span> /&gt;
               &lt;property name=<span class="code-quote">"keystore"</span> value=<span class="code-quote">"..."</span> /&gt;
               &lt;property name=<span class="code-quote">"needClientAuth"</span> value=<span class="code-quote">"..."</span> /&gt;
               &lt;property name=<span class="code-quote">"truststore"</span> value=<span class="code-quote">"..."</span> /&gt;
             &lt;/bean&gt;
          &lt;/entry&gt;
       &lt;/map&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
</pre>
</div></div>

<p>The value you use as keys in the above map is the port you configure Jetty to listen on.</p>

<h3><a name="BookComponentAppendix-DefaultbehaviorforreturningHTTPstatuscodes"></a>Default behavior for returning HTTP status codes</h3>

<p>The default behavior of HTTP status codes is defined by the <tt>org.apache.camel.component.http.DefaultHttpBinding</tt> class, which handles how a response is written and also sets the HTTP status code.</p>

<p>If the exchange was processed successfully, the 200 HTTP status code is returned.<br/>
If the exchange failed with an exception, the 500 HTTP status code is returned, and the stacktrace is returned in the body. If you want to specify which HTTP status code to return, set the code in the <tt>HttpProducer.HTTP_RESPONSE_CODE</tt> header of the OUT message.</p>

<h3><a name="BookComponentAppendix-CustomizingHttpBinding"></a>Customizing HttpBinding</h3>
<p><b>Available as of Camel 1.5.1/2.0</b> </p>

<p>By default, Camel uses the <tt>org.apache.camel.component.http.DefaultHttpBinding</tt> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <tt>HttpBinding</tt> class or by extending <tt>DefaultHttpBinding</tt> and overriding the appropriate methods.</p>

<p>The following example shows how to customize the <tt>DefaultHttpBinding</tt> in order to change how exceptions are returned:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyHttpBinding <span class="code-keyword">extends</span> DefaultHttpBinding {

    @Override
    <span class="code-keyword">public</span> void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) <span class="code-keyword">throws</span> IOException {
        <span class="code-comment">// we override the doWriteExceptionResponse as we only want to alter the binding how exceptions is
</span>        <span class="code-comment">// written back to the client. 
</span>
        <span class="code-comment">// we just <span class="code-keyword">return</span> HTTP 200 so the client thinks its okay
</span>        response.setStatus(200);
        <span class="code-comment">// and we <span class="code-keyword">return</span> <span class="code-keyword">this</span> fixed text
</span>        response.getWriter().write(<span class="code-quote">"Something went wrong but we dont care"</span>);
    }
}
</pre>
</div></div>

<p>We can then create an instance of our binding and register it in the Spring registry as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;bean id=<span class="code-quote">"mybinding"</span> class=<span class="code-quote">"com.mycompany.MyHttpBinding"</span>/&gt;</span>
</pre>
</div></div>

<p>And then we can reference this binding when we define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://0.0.0.0:8080/myapp/myservice?httpBindingRef=mybinding"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:doSomething"</span>/&gt;</span>
   <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Jettyhandlersandsecurityconfiguration"></a>Jetty handlers and security configuration</h3>
<p><b>Available as of Camel 1.6.1/2.0:</b> You can configure a list of Jetty handlers on the endpoint, which can be useful for enabling advanced Jetty security features. These handlers are configured in Spring XML as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;-- Jetty Security handling --&gt;</span>
	<span class="code-tag">&lt;bean id=<span class="code-quote">"userRealm"</span> class=<span class="code-quote">"org.mortbay.jetty.plus.jaas.JAASUserRealm"</span>&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"name"</span> value=<span class="code-quote">"tracker-users"</span> /&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"loginModuleName"</span> value=<span class="code-quote">"ldaploginmodule"</span> /&gt;</span>
	<span class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;bean id=<span class="code-quote">"constraint"</span> class=<span class="code-quote">"org.mortbay.jetty.security.Constraint"</span>&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"name"</span> value=<span class="code-quote">"BASIC"</span> /&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"roles"</span> value=<span class="code-quote">"tracker-users"</span> /&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"authenticate"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
	<span class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;bean id=<span class="code-quote">"constraintMapping"</span> class=<span class="code-quote">"org.mortbay.jetty.security.ConstraintMapping"</span>&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"constraint"</span> ref=<span class="code-quote">"constraint"</span> /&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"pathSpec"</span> value=<span class="code-quote">"/*"</span> /&gt;</span>
	<span class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;bean id=<span class="code-quote">"securityHandler"</span> class=<span class="code-quote">"org.mortbay.jetty.security.SecurityHandler"</span>&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"userRealm"</span> ref=<span class="code-quote">"userRealm"</span> /&gt;</span>
		<span class="code-tag">&lt;property name=<span class="code-quote">"constraintMappings"</span> ref=<span class="code-quote">"constraintMapping"</span> /&gt;</span>
	<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>You can then define the endpoint as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jetty:http:<span class="code-comment">//0.0.0.0:9080/myservice?handlers=securityHandler"</span>)</span>
</pre>
</div></div>

<p>If you need more handlers, set the <tt>handlers</tt> option equal to a comma-separated list of bean IDs.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a></li>
</ul>

<h2><a name="BookComponentAppendix-JingComponent"></a>Jing Component</h2>

<p>The Jing component uses the <a href="http://www.thaiopensource.com/relaxng/jing.html" rel="nofollow">Jing Library</a> to perform XML validation of the message body using either</p>

<ul>
	<li><a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a></li>
	<li><a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG Compact Syntax</a></li>
</ul>


<p>Note that the <a href="/confluence/display/CAMEL/MSV" title="MSV">MSV</a> component can also support RelaxNG XML syntax.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rng:someLocalOrRemoteResource
rnc:someLocalOrRemoteResource
</pre>
</div></div>

<p>Where <b>rng</b> means use the <a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a> whereas <b>rnc</b> means use <a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG Compact Syntax</a>. The following examples show possible URI values</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Example</th>
<th class='confluenceTh'>Description</th>
</tr>
<tr>
<td class='confluenceTd'>rng:foo/bar.rng</td>
<td class='confluenceTd'> References the XML file <b>foo/bar.rng</b> on the classpath </td>
</tr>
<tr>
<td class='confluenceTd'>rnc:<a href="http://foo.com/bar.rnc" rel="nofollow">http://foo.com/bar.rnc</a></td>
<td class='confluenceTd'> References the RelaxNG Compact Syntax file from the URL, <a href="http://foo.com/bar.rnc" rel="nofollow">http://foo.com/bar.rnc</a></td>
</tr>
</tbody></table>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>useDom</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies whether DOMSource/DOMResult or SaxSource/SaxResult should be used by the validator. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>

<p>The following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml" rel="nofollow">example</a> shows how to configure a route from the endpoint <b>direct:start</b> which then goes to one of two endpoints, either <b>mock:valid</b> or <b>mock:invalid</b> based on whether or not the XML matches the given <a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG Compact Syntax</a> schema (which is supplied on the classpath).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;doTry&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"rnc:org/apache/camel/component/validator/jing/schema.rnc"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:valid"</span>/&gt;</span>

            <span class="code-tag">&lt;doCatch&gt;</span>
                <span class="code-tag">&lt;exception&gt;</span>org.apache.camel.ValidationException<span class="code-tag">&lt;/exception&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:invalid"</span>/&gt;</span>
            <span class="code-tag">&lt;/doCatch&gt;</span>
            <span class="code-tag">&lt;doFinally&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:finally"</span>/&gt;</span>
            <span class="code-tag">&lt;/doFinally&gt;</span>
        <span class="code-tag">&lt;/doTry&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-JMSComponent"></a>JMS Component</h2>

<p>The JMS component allows messages to be sent to (or consumed from) a <a href="http://java.sun.com/products/jms/" rel="nofollow">JMS</a> Queue or Topic. The implementation of the JMS Component uses Spring's JMS support for declarative transactions, using Spring's <tt>JmsTemplate</tt> for sending and a <tt>MessageListenerContainer</tt> for consuming.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For users with Camel 1.6.1 or older</b><br /><p>JMS consumers have a bad default in Camel 1.6.1 or older. The <tt>maxMessagesPerTask</tt> is set to 1, whereas it really should be -1.<br/>
This issue causes Spring to create a new thread after it has processed a message, causing the thread count to rise continuously. You can see this in the log where a new thread name is used.</p>

<p>To remedy this, change a route such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;from uri=<span class="code-quote">"jms:queue:foo"</span>/&gt;</span>
</pre>
</div></div>

<p>By adding the <tt>maxMessagesPerTask</tt> option and setting its value to -1, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;from uri=<span class="code-quote">"jms:queue:foo&amp;amp;maxMessagesPerTask=-1"</span>/&gt;</span>
</pre>
</div></div>

<p>This has been fixed in Camel 1.6.2/2.0.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using ActiveMQ</b><br /><p>If you are using <a href="http://activemq.apache.org/" rel="nofollow">Apache ActiveMQ</a>, you should prefer the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component as it has been particularly optimized for <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a>.<br/>
All of the options and samples on this page are also valid for the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component.</p></td></tr></table></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using JMS API 1.0.2</b><br /><p>The old JMS API 1.0.2 has been <b>@deprecated</b> in Camel 2.1 and will be removed in Camel 2.2 release.<br/>
Its no longer provided in Spring 3.0 which we want to be able to support out of the box in Camel 2.2+ releases.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:[temp:][queue:|topic:]destinationName[?options]
</pre>
</div></div>

<p>Where <tt>destinationName</tt> is a JMS queue or topic name. By default, the<br/>
<tt>destinationName</tt> is interpreted as a queue name. For example, to connect<br/>
to the queue, FOO.BAR, use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:FOO.BAR
</pre>
</div></div>

<p>You can include the optional <tt>queue:</tt> prefix, if you prefer:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:queue:FOO.BAR
</pre>
</div></div>

<p>To connect to a topic, you <em>must</em> include the <tt>topic:</tt> prefix. For example, to<br/>
connect to the topic, <tt>Stocks.Prices</tt>, use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:topic:Stocks.Prices
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h4><a name="BookComponentAppendix-UsingTemporaryDestinations"></a>Using Temporary Destinations</h4>

<p>As of Camel 1.4.0, you can access temporary queues using the following URL format:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:temp:queue:foo
</pre>
</div></div>

<p>Or temporary topics using the following URL format:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:temp:topic:bar
</pre>
</div></div>

<p>This URL format enables multiple routes or processors or beans to refer to the same temporary destination. For example, you can create three temporary destinations and use them in routes as inputs or outputs by referring to them by name.</p>

<h3><a name="BookComponentAppendix-Notes"></a>Notes</h3>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>If you are using ActiveMQ</b><br /><p>Note that the JMS component reuses Spring 2's <tt>JmsTemplate</tt> for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching in the JMS provider to avoid performance <a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">being lousy</a>.</p>

<p>So if you intend to use <a href="http://activemq.apache.org/" rel="nofollow">Apache ActiveMQ</a> as your Message Broker - which is a good choice as ActiveMQ rocks <img class="emoticon" src="/confluence/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/>, then we recommend that you either</p>

<ul>
	<li>Use the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component, which is already configured to use ActiveMQ efficiently, or</li>
	<li>Use the <tt>PoolingConnectionFactory</tt> in ActiveMQ.</li>
</ul>
</td></tr></table></div>

<p>If you wish to use durable topic subscriptions, you need to specify both <b>clientId</b> and <b>durableSubscriptionName</b>. Note that the value of the <tt>clientId</tt> must be unique and can only be used by a single JMS connection instance in your entire network. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" rel="nofollow">Virtual Topics</a> instead to avoid this limitation. More background on durable messaging <a href="http://activemq.apache.org/how-do-durable-queues-and-topics-work.html" rel="nofollow">here</a>.</p>

<p>When using message headers, the JMS specification states that header names must be valid Java identifiers. So, by default, Camel ignores any headers that do not match this rule. So try to name your headers as if they are valid Java identifiers. One benefit of doing this is that you can then use your headers inside a JMS Selector (whose SQL92 syntax mandates Java identifier syntax for headers).</p>

<p>From Camel 1.4 onwards, a simple strategy for mapping header names is used by default. The strategy is to replace any dots in the header name with the underscore character and to reverse the replacement when the header name is restored from a JMS message sent over the wire. What does this mean? No more losing method names to invoke on a bean component, no more losing the filename header for the File Component, and so on. </p>

<p>The current header name strategy for accepting header names in Camel is as follows:</p>
<ul class="alternate" type="square">
	<li>Replace all dots with underscores (for example, <tt>org.apache.camel.MethodName</tt> becomes <tt>org_apache_camel_MethodName</tt>).</li>
	<li>Test if the name is a valid java identifier using the JDK core classes.</li>
	<li>If the test success, the header is added and sent over the wire; otherwise it is dropped (and logged at <tt>DEBUG</tt> level).</li>
</ul>


<p>In Camel 2.0 this strategy has been change a bit to use the following replacement strategy:</p>
<ul class="alternate" type="square">
	<li>Dots are replaced by <tt>&#95;DOT&#95;</tt> and the replacement is reversed when Camel consume the message</li>
	<li>Hyphen is replaced by <tt>&#95;HYPHEN&#95;</tt> and the replacement is reversed when Camel consumes the message</li>
</ul>


<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For Consuming Messages cacheLevelName settings are vital!</b><br /><p>If you are using Spring before 2.5.1 and Camel before 1.3.0, you might want to set the <tt>cacheLevelName</tt> to be <tt>CACHE_CONSUMER</tt> for maximum performance. </p>

<p>Due to a <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3890" rel="nofollow">bug in earlier Spring versions</a> causing a lack of transactional integrity, previous versions of Camel and Camel versions from 1.3.0 onwwards when used with Spring versions earlier than 2.5.1 will default to using <tt>CACHE_CONNECTION</tt>. See the JIRAs <a href="https://issues.apache.org/activemq/browse/CAMEL-163" rel="nofollow">CAMEL-163</a> and <a href="https://issues.apache.org/activemq/browse/CAMEL-294" rel="nofollow">CAMEL-294</a>.</p>

<p>Also, if you are using XA resources or running in a J2EE container, you may want to set the <tt>cacheLevelName</tt> to be <tt>CACHE_NONE</tt> as we have found that when using JBoss with TibCo EMS and JTA/XA you must disable caching.</p>

<p>Another user reports problems using WebSphere MQ 6.0.2.5, Camel 1.6.0 and Spring 2.5.6. The application does not use XA and is not running inside a J2EE Container, but the <tt>cacheLevelName=CACHE_NONE</tt> setting seems to solve the problem with WebSphere MQ.</p>

<p>See also more about <a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">JmsTemplate gotchas</a>.</p></td></tr></table></div>


<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<p>You can configure many different properties on the JMS endpoint which map to properties on the <a href="http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/JmsConfiguration.html" rel="nofollow">JMSConfiguration POJO</a>. <b>Note:</b> Many of these properties map to properties on Spring JMS, which Camel uses for sending and receiving messages. So you can get more information about these properties by consulting the relevant Spring documentation.</p>

<p>The options is divided into two tables, the first one with the most common options used. The latter contains the rest.</p>

<h4><a name="BookComponentAppendix-Mostcommonlyusedoptions"></a>Most commonly used options</h4>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>autoStartup</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the consumer container should auto-startup. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>clientId</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. It is typically only required for durable topic subscriptions. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" rel="nofollow">Virtual Topics</a> instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>concurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the default number of concurrent consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableReplyTo</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, ignore the <tt>JMSReplyTo</tt> header and so treat messages as <em>InOnly</em> by default and do not send a reply back. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>durableSubscriptionName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The durable subscriber name for specifying durable topic subscriptions. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxConcurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the maximum number of concurrent consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyTo</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Provides an explicit ReployTo destination, which overrides any incoming value of <tt>Message.getJMSReplyTo()</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestTimeout</tt> </td>
<td class='confluenceTd'> <tt>20000</tt> </td>
<td class='confluenceTd'> The timeout for sending messages (in milliseconds). The default is 20 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>selector</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS Selector, which is an SQL 92 predicate that is used to filter messages within the broker. You may have to encode special characters such as = as %3D </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToLive</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> When sending messages, specifies the time-to-live of the message (in milliseconds). The <tt>explicitQosEnabled</tt> option <b>must</b> also be enabled in order for this option to have any effect. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transacted</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to use transacted mode for sending/receiving messages using the InOnly <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>testConnectionOnStartup</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensure that Camel is not started with failed connections. </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-Alltheotheroptions"></a>All the other options</h4>

<div class="confluenceTableSmall"></div>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>acceptMessagesWhileStopping</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether the consumer accept messages while it is stopping. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementModeName</tt> </td>
<td class='confluenceTd'> <tt>AUTO_ACKNOWLEDGE</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement name, which is one of: <tt>TRANSACTED</tt>, <tt>CLIENT_ACKNOWLEDGE</tt>, <tt>AUTO_ACKNOWLEDGE</tt>, <tt>DUPS_OK_ACKNOWLEDGE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementMode</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement mode defined as an Integer. Allows you to set vendor-specific extensions to the acknowledgment mode. For the regular modes, it is preferable to use the <tt>acknowledgementModeName</tt> instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alwaysCopyMessage</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a <tt>replyToDestinationSelectorName</tt> is set (incidentally, Camel will set the <tt>alwaysCopyMessage</tt> option to <tt>true</tt>, if a <tt>replyToDestinationSelectorName</tt> is set) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevelName</tt> </td>
<td class='confluenceTd'> <tt>CACHE_CONSUMER</tt> </td>
<td class='confluenceTd'> Sets the cache level by name for the underlying JMS resources. Possible values are: <tt>CACHE_AUTO</tt>, <tt>CACHE_CONNECTION</tt>, <tt>CACHE_CONSUMER</tt>, <tt>CACHE_NONE</tt>, and <tt>CACHE_SESSION</tt>. See the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" rel="nofollow">Spring documentation</a> and see the warning above. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevel</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Sets the cache level by ID for the underlying JMS resources. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumerType</tt> </td>
<td class='confluenceTd'> <tt>Default</tt> </td>
<td class='confluenceTd'> The consumer type to use, which can be one of: <tt>Simple</tt>, <tt>Default</tt> or <tt>ServerSessionPool</tt>. The consumer type determines which Spring JMS listener to use. <tt>Default</tt> will use <tt>org.springframework.jms.listener.DefaultMessageListenerContainer</tt>, <tt>Simple</tt> will use <tt>org.springframework.jms.listener.SimpleMessageListenerContainer</tt>, and <tt>ServerSessionPool</tt> will use <tt>org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer</tt>. If the option, <tt>useVersion102=true</tt>, Camel will use the JMS 1.0.2 Spring classes instead. <tt>ServerSessionPool</tt> is <b>@deprecated</b> and will be removed in Camel 2.0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default JMS connection factory to use for the <tt>listenerConnectionFactory</tt> and <tt>templateConnectionFactory</tt>, if neither is specified. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deliveryMode</tt> </td>
<td class='confluenceTd'> <tt>2</tt> </td>
<td class='confluenceTd'> Specifies the delivery mode when sending, where 1 = non-persistent, and 2 = persistent. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether persistent delivery is used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS Destination object to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS destination name to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationResolver</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.springframework.jms.support.destination.DestinationResolver</tt> that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eagerLoadingOfProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enables eager loading of JMS properties as soon as a message is received, which is generally inefficient, because the JMS properties might not be required. But this feature can sometimes catch early any issues with the underlying JMS provider and the use of JMS properties. This feature can also be used for testing purposes, to ensure JMS properties can be understood and handled correctly. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exceptionListener</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>explicitQosEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set if the <tt>deliveryMode</tt>, <tt>priority</tt> or <tt>timeToLive</tt> qualities of service should be used when sending messages. This option is based on Spring's <tt>JmsTemplate</tt>. The <tt>deliveryMode</tt>, <tt>priority</tt> and <tt>timeToLive</tt> options are applied to the current endpoint. This contrasts with the <tt>preserveMessageQos</tt> option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exposeListenerSession</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the listener session should be exposed when consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idleTaskExecutionLimit</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the <tt>maxConcurrentConsumers</tt> setting). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsMessageType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Allows you to force the use of a specific <tt>javax.jms.Message</tt> implementation for sending JMS messages. Possible values are: <tt>Bytes</tt>, <tt>Map</tt>, <tt>Object</tt>, <tt>Stream</tt>, <tt>Text</tt>. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsKeyFormatStrategy</tt> </td>
<td class='confluenceTd'> <tt>default</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: <tt>default</tt> and <tt>passthrough</tt>. The <tt>default</tt> strategy will safely marshal dots and hyphens (<tt>.</tt> and <tt>-</tt>). The <tt>passthrough</tt> strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the <tt>org.apache.camel.component.jms.JmsKeyFormatStrategy</tt> and refer to it using the <tt>#</tt> notation.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsOperations</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to use your own implementation of the <tt>org.springframework.jms.core.JmsOperations</tt> interface. Camel uses <tt>JmsTemplate</tt> as default. Can be used for testing purpose, but not used much as stated in the spring API docs. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lazyCreateTransactionManager</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If <tt>true</tt>, Camel will create a <tt>JmsTransactionManager</tt>, if there is no <tt>transactionManager</tt> injected when option <tt>transacted=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>listenerConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mapJmsMessage</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> Specifies whether Camel should auto map the received JMS message to an appropiate payload type, such as <tt>javax.jms.TextMessage</tt> to a <tt>String</tt> etc. See section about how mapping works below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerTask</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The number of messages per task. -1 is unlimited. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageConverter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> To use a custom Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> so you can be 100% in control how to map to/from a <tt>javax.jms.Message</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageIdEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> When sending, specifies whether message IDs should be added. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageTimestampEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether timestamps should be enabled by default on sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>priority</tt> </td>
<td class='confluenceTd'> <tt>4</tt> </td>
<td class='confluenceTd'> Values greater than 1 specify the message priority when sending (where 0 is the lowest priority and 9 is the highest). The <tt>explicitQosEnabled</tt> option <b>must</b> also be enabled in order for this option to have any effect. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preserveMessageQos</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'>  <b>Camel 2.0</b>: Set to <tt>true</tt>, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered <tt>JMSPriority</tt>, <tt>JMSDeliveryMode</tt>, and <tt>JMSExpiration</tt>. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The <tt>explicitQosEnabled</tt> option, by contrast, will only use options set on the endpoint, and not values from the message header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pubSubNoLocal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to inhibit the delivery of messages published by its own connection. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveTimeout</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> The timeout for receiving messages (in milliseconds). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>recoveryInterval</tt> </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToTempDestinationAffinity</tt> </td>
<td class='confluenceTd'> <tt>producer</tt> </td>
<td class='confluenceTd'> Defines the component-created temporary <tt>replyTo</tt> destination sharing strategy. Possible values are: <tt>component</tt>, <tt>endpoint</tt> or <tt>producer</tt>. <b>component</b> = a single temp queue is shared among all producers for a given component instance; <b>endpoint</b> = a single temp queue is shared among all producers for a given endpoint instance; <b>producer</b> = a single temp queue is created for each producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDestinationSelectorName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDeliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether to use persistent delivery by default for replies. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serverSessionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b> - will be removed in Camel 2.0. The JMS <tt>ServerSessionFactory</tt>, if you wish to use <tt>ServerSessionFactory</tt> for consumption </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subscriptionDurable</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enabled by default, if you specify a <tt>durableSubscriberName</tt> and a <tt>clientId</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>taskExecutor</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to specify a custom task executor for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>templateConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactedInOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated:</b> Specifies whether to use transacted mode for sending messages using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. Applies only to producer endpoints. See section Enabling Transacted Consumption for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The Spring transaction manager to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The name of the transaction to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The timeout value of the transaction, if using transacted mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If enabled and you are using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> messaging (InOut) and an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> failed on the consumer side, then the caused <tt>Exception</tt> will be send back in response as a <tt>javax.jms.ObjectMessage</tt>. If the client is Camel, the returned <tt>Exception</tt> is rethrown. This allows you to use Camel <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have <b>transferExchange</b> enabled, this option takes precedence. The caught exception is required to be serializable. The original <tt>Exception</tt> on the consumer side can be wrapped in an outer exception such as <tt>org.apache.camel.RuntimeCamelException</tt> when returned to the producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at <tt>WARN</tt> level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The username for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useMessageIDAsCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether <tt>JMSMessageID</tt> should always be used as <tt>JMSCorrelationID</tt> for <b>InOut</b> messages. Be careful: When this option is set camel will ignore the incoming correlation id and always use the message id instead. Camel will by default use a GUID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useVersion102</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b>: Specifies whether the old JMS API should be used. Will be removed in Camel 2.2, as JMS API 1.0.2 is no longer provided in Spring 3.0. </td>
</tr>
</tbody></table></div>

<h3><a name="BookComponentAppendix-MessageMappingbetweenJMSandCamel"></a>Message Mapping between JMS and Camel</h3>
<p>Camel automatically maps messages between <tt>javax.jms.Message</tt> and <tt>org.apache.camel.Message</tt>. </p>

<p>When sending a JMS message, Camel converts the message body to the following JMS message types:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Body Type </th>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Comment </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.w3c.dom.Node</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> The DOM will be converted to <tt>String</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Map</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Serializable</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.File</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Reader</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.InputStream</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.nio.ByteBuffer</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>

<p>When receiving a JMS message, Camel converts the JMS message to the following body type:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Body Type </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'> <tt>Map&lt;String, Object&gt;</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'> <tt>Object</tt> </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-DisablingautomappingofJMSmessages"></a>Disabling auto-mapping of JMS messages</h4>
<p><b>Available as of Camel 1.6.2/2.0</b></p>

<p>You can use the <tt>mapJmsMessage</tt> option to disable the auto-mapping above. If disabled, Camel will not try to map the received JMS message, but instead uses it directly as the payload. This allows you to avoid the overhead of mapping and let Camel just pass through the JMS message. For instance, it even allows you to route <tt>javax.jms.ObjectMessage</tt> JMS messages with classes you do <b>not</b> have on the classpath.</p>

<h4><a name="BookComponentAppendix-UsingacustomMessageConverter"></a>Using a custom MessageConverter</h4>
<p><b>Available as of Camel 1.6.2/2.0</b></p>

<p>You can use the <tt>messageConverter</tt> option to do the mapping yourself in a Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> class. </p>

<p>For example, in the route below we use a custom message converter when sending a message to the JMS order queue:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?messageConverter=#myMessageConverter"</span>);</span>
</pre>
</div></div>

<p>You can also use a custom message converter when consuming from a JMS destination.</p>

<h4><a name="BookComponentAppendix-Controllingthemappingstrategyselected"></a>Controlling the mapping strategy selected</h4>
<p><b>Available as of Camel 2.0</b></p>

<p>You can use the <b>jmsMessageType</b> option on the endpoint URL to force a specific message type for all messages.<br/>
In the route below, we poll files from a folder and send them as <tt>javax.jms.TextMessage</tt> as we have forced the JMS producer endpoint to use text messages:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?jmsMessageType=Text"</span>);</span>
</pre>
</div></div>

<p>You can also specify the message type to use for each messabe by setting the header with the key <tt>CamelJmsMessageType</tt>. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).setHeader(<span class="code-quote">"CamelJmsMessageType"</span>, JmsMessageType.Text).to(<span class="code-quote">"jms:queue:order"</span>);</span>
</pre>
</div></div>

<p>The possible values are defined in the <tt>enum</tt> class, <tt>org.apache.camel.jms.JmsMessageType</tt>.</p>

<h3><a name="BookComponentAppendix-Messageformatwhensending"></a>Message format when sending</h3>
<p>The exchange that is sent over the JMS wire must conform to the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html" rel="nofollow">JMS Message spec</a>.</p>

<p>For the <tt>exchange.in.header</tt> the following rules apply for the header <b>keys</b>:</p>
<ul class="alternate" type="square">
	<li>Keys starting with <tt>JMS</tt> or <tt>JMSX</tt> are reserved.</li>
	<li><tt>exchange.in.headers</tt> keys must be literals and all be valid Java identifiers (do not use dots in the key name).</li>
	<li>From Camel 1.4 until Camel 1.6.x, Camel automatically replaces all dots with underscores in key names. This replacement is reversed when Camel consumes JMS messages.</li>
	<li>From Camel 2.0 onwards, Camel replaces dots &amp; hyphens and the reverse when when consuming JMS messages:<br/>
   <tt>.</tt> is replaced by <tt>&#95;DOT&#95;</tt> and the reverse replacement when Camel consumes the message.<br/>
   <tt>&#45;</tt> is replaced by <tt>&#95;HYPHEN&#95;</tt> and the reverse replacement when Camel consumes the message.</li>
	<li>See also the option <tt>jmsKeyFormatStrategy</tt> introduced in <b>Camel 2.0</b>, which allows you to use your own custom strategy for formatting keys.</li>
</ul>


<p>For the <tt>exchange.in.header</tt>, the following rules apply for the header <b>values</b>:</p>
<ul class="alternate" type="square">
	<li>The values must be primitives or their counter objects (such as <tt>Integer</tt>, <tt>Long</tt>, <tt>Character</tt>). The types, <tt>String</tt>, <tt>CharSequence</tt>, <tt>Date</tt>, <tt>BigDecimal</tt> and <tt>BigInteger</tt> are all converted to their <tt>toString()</tt> representation. All other types are dropped.</li>
</ul>


<p>Camel will log with category <tt>org.apache.camel.component.jms.JmsBinding</tt> at <b>DEBUG</b> level if it drops a given header value. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-07-09 06:43:04,046 [main           ] DEBUG JmsBinding  
  - Ignoring non primitive header: order of class: org.apache.camel.component.jms.issues.DummyOrder with value: DummyOrder{orderId=333, itemId=4444, quantity=2}
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Messageformatwhenreceiving"></a>Message format when receiving</h3>

<p>Camel adds the following properties to the <tt>Exchange</tt> when it receives a message:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.jms.replyDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The reply destination. </td>
</tr>
</tbody></table>

<p>Camel adds the following JMS properties to the In message headers when it receives a JMS message:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS correlation ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDeliveryMode</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS delivery mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSExpiration</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS expiration. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSMessageID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS unique message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSPriority</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS priority (with 0 as the lowest priority and 9 as the highest). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSRedelivered</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> Is the JMS message redelivered. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS reply-to destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSTimestamp</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS timestamp. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSXGroupID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS group ID. </td>
</tr>
</tbody></table>

<p>As all the above information is standard JMS you can check the <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html" rel="nofollow">JMS documentation</a> for further details.</p>


<h3><a name="BookComponentAppendix-AboutusingCameltosendandreceivemessagesandJMSReplyTo"></a>About using Camel to send and receive messages and JMSReplyTo </h3>
<p>The JMS component is complex and you have to pay close attention to how it works in some cases. So this is a short summary of some of the areas/pitfalls to look for.</p>

<p>When Camel sends a message using its <tt>JMSProducer</tt>, it checks the following conditions:</p>
<ul class="alternate" type="square">
	<li>The message exchange pattern,</li>
	<li>Whether a <tt>JMSReplyTo</tt> was set in the endpoint or in the message headers,</li>
	<li>Whether any of the following options have been set on the JMS endpoint: <tt>disableReplyTo</tt>, <tt>preserveMessageQos</tt>, <tt>explicitQosEnabled</tt>.</li>
</ul>


<p>All this can be a tad complex to understand and configure to support your use case.</p>

<h4><a name="BookComponentAppendix-JmsProducer"></a>JmsProducer</h4>
<p>The <tt>JmsProducer</tt> behaves as follows, depending on configuration:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will expect a reply, set a temporary <tt>JMSReplyTo</tt>, and after sending the message, it will start to listen for the reply message on the temporary queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is set </td>
<td class='confluenceTd'> Camel will expect a reply and, after sending the message, it will start to listen for the reply message on the specified <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the message and <b>not</b> expect a reply. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is set </td>
<td class='confluenceTd'> Camel sees this as a contradiction and will suppress the <tt>JMSReplyTo</tt>. In fact, Camel will disable it by clearing it before sending. Camel will send the message and <b>not</b> expect a reply. Camel logs this in the log at <tt>WARN</tt> level and you should see: <tt>WARN  JmsProducer - Disabling JMSReplyTo as this Exchange is not OUT capable with JMSReplyTo: myReplyQueue to destination: myQueue</tt>. <b>Note:</b> You can use the <tt>preserveMessageQos=true</tt> setting or the <tt>explicitQosEnabled=true</tt> setting to force Camel to send the <tt>JMSReplyTo</tt> anyway, and the <tt>WARN</tt> log will disappear. </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-JmsConsumer"></a>JmsConsumer</h4>
<p>The <tt>JmsConsumer</tt> behaves as follows, depending on configuration:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the reply back to the <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will not send a reply back, as the pattern is <em>InOnly</em>.</td>
</tr>
<tr>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> <tt>disableReplyTo=true</tt> </td>
<td class='confluenceTd'> This option suppresses replies. </td>
</tr>
</tbody></table>

<p>So pay attention to the message exchange pattern set on your exchanges.</p>

<p>If you send a message to a JMS destination in the middle of your route you can specify the exchange pattern to use, see more at <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>.<br/>
This is useful if you want to send an <tt>InOnly</tt> message to a JMS topic:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:in"</span>)
   .to(<span class="code-quote">"bean:validateOrder"</span>)
   .to(ExchangePattern.InOnly, <span class="code-quote">"activemq:topic:order"</span>)
   .to(<span class="code-quote">"bean:handleOrder"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Reuseendpointandsendtodifferentdestinationscomputedatruntime"></a>Reuse endpoint and send to different destinations computed at runtime</h3>
<p><b>Available as of Camel 1.6.2/2.0</b><br/>
If you need to send messages to a lot of different JMS destinations, it makes sense to reuse a JMS endpoint and specify the real destination in a message header. This allows Camel to reuse the same endpoint, but send to different destinations. This greatly reduces the number of endpoints created and economizes on memory and thread resources.</p>

<p>You can specify the destination in the following headers:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJmsDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> A destination object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJmsDestinationName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> The destination name. </td>
</tr>
</tbody></table>


<p>For example, the following route shows how you can compute a destination at run time and use it to override the destination appearing in the JMS URL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inbox"</span>)
</span>  .to(<span class="code-quote">"bean:computeDestination"</span>)
  .to(<span class="code-quote">"activemq:queue:dummy"</span>);
</pre>
</div></div>

<p>The queue name, <tt>dummy</tt>, is just a placeholder. It must be provided as part of the JMS endpoint URL, but it will be ignored in this example.</p>

<p>In the <tt>computeDestination</tt> bean, specify the real destination by setting the <tt>CamelJmsDestinationName</tt> header as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> void setJmsHeader(Exchange exchange) {
   <span class="code-object">String</span> id = ....
   exchange.getIn().setHeader(<span class="code-quote">"CamelJmsDestinationName"</span>, <span class="code-quote">"order:"</span> + id");
}
</pre>
</div></div>

<p>Then Camel will read this header and use it as the destination instead of the one configured on the endpoint. So, in this example Camel sends the message to <tt>activemq:queue:order:2</tt>, assuming the <tt>id</tt> value was 2.</p>

<p>If both the <tt>CamelJmsDestination</tt> and the <tt>CamelJmsDestinationName</tt> headers are set, <tt>CamelJmsDestination</tt> takes priority.</p>


<h3><a name="BookComponentAppendix-ConfiguringdifferentJMSproviders"></a>Configuring different JMS providers</h3>

<p>You can configure your JMS provider in <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a> XML as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span>&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span class="code-quote">"vm://localhost?broker.persistent=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Basically, you can configure as many JMS component instances as you wish and give them <b>a unique name using the <tt>id</tt> attribute</b>. The preceding example configures an <tt>activemq</tt> component. You could do the same to configure MQSeries, TibCo, BEA, Sonic and so on.</p>

<p>Once you have a named JMS component, you can then refer to endpoints within that component using URIs. For example for the component name, <tt>activemq</tt>, you can then refer to destinations using the URI format, <tt>activemq:[queue:&#124;topic:]destinationName</tt>. You can use the same approach for all other JMS providers.</p>

<p>This works by the SpringCamelContext lazily fetching components from the spring context for the scheme name you use for <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a> and having the <a href="/confluence/display/CAMEL/Component" title="Component">Component</a> resolve the endpoint URIs. </p>


<h4><a name="BookComponentAppendix-UsingJNDItofindtheConnectionFactory"></a>Using JNDI to find the ConnectionFactory</h4>

<p>If you are using a J2EE container, you might need to look up JNDI to find the JMS <tt>ConnectionFactory</tt> rather than use the usual <tt>&lt;bean&gt;</tt> mechanism in Spring. You can do this using Spring's factory bean or the new Spring XML namespace. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"weblogic"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span class="code-quote">"myConnectionFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;jee:jndi-lookup id=<span class="code-quote">"myConnectionFactory"</span> jndi-name=<span class="code-quote">"jms/connectionFactory"</span>/&gt;</span>
</pre>
</div></div>

<p>See <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-jee" rel="nofollow">The jee schema</a> in the Spring reference documentation for more details about JNDI lookup.</p>

<h4><a name="BookComponentAppendix-UsingJNDItolookupthephysicalqueues"></a>Using JNDI to lookup the physical queues</h4>
<p>You need to use the <tt>destinationResolver</tt> option to use the Spring JNDI resolver that can lookup in the JNDI, or use your own custom implementation. </p>

<p>See this nabble post for more details:
<a href="http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html" rel="nofollow">http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html</a></p>


<h4><a name="BookComponentAppendix-UsingWebSphereMQ"></a>Using WebSphere MQ</h4>
<p>See this <a href="http://www.nabble.com/Camel-and-IBM-MQ-Series-td24524277.html" rel="nofollow">link at nabble</a> for details of how a Camel user configured <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> to connect to remote WebSphere MQ brokers.</p>


<h3><a name="BookComponentAppendix-ConcurrentConsuming"></a>Concurrent Consuming</h3>

<p>A common requirement with JMS is to consume messages concurrently in multiple threads in order to make an application more responsive. You can set the <tt>concurrentConsumers</tt> option to specify the number of threads servicing the JMS endpoint, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:SomeQueue?concurrentConsumers=20"</span>).
  bean(MyClass.class);
</pre>
</div></div>

<p>You can configure this option in one of the following ways:</p>
<ul>
	<li>On the <tt>JmsComponent</tt>,</li>
	<li>On the endpoint URI or,</li>
	<li>By invoking <tt>setConcurrentConsumers()</tt> directly on the <tt>JmsEndpoint</tt>.</li>
</ul>



<h3><a name="BookComponentAppendix-EnablingTransactedConsumption"></a>Enabling Transacted Consumption</h3>

<p>A common requirement is to consume from a queue in a transaction and then process the message using the Camel route. To do this, just ensure that you set the following properties on the component/endpoint:</p>

<ul>
	<li><tt>transacted</tt> = true</li>
	<li><tt>transactionManager</tt> = a Transsaction Manager - typically the <tt>JmsTransactionManager</tt></li>
</ul>


<p>See also the <a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a> EIP pattern for further details.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Transaction and <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS</b><br /><p>Note that when using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS you cannot use a single transaction; as JMS will not send any messages until a commit is performed, the server side won't receive anything at all until the transaction commits. So, with request/response you must commit a transaction after sending the first request and then use a separate transaction for receiving the response.</p>

<p>This is why the <tt>transacted</tt> property applies only to the InOnly message <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (MEP). If you want to use transactions for the InOut MEP as well, you must set <tt>transactedInOut=true</tt>.</p>

<p>To recap: if you have <tt>transacted=true</tt>, <tt>transactedInOut=false</tt> and are sending an <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">InOut</a>, the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> will <b>not</b> use transactions.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-UsingJMSReplyToforlatereplies"></a>Using JMSReplyTo for late replies</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>When using Camel as a JMS listener, it sets an Exchange property with the value of the ReplyTo <tt>javax.jms.Destination</tt> object, having the key <tt>ReplyTo</tt>. You can obtain this <tt>Destination</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
</pre>
</div></div>

<p>And then later use it to send a reply using regular JMS or Camel.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we need to pass in the JMS component, and in <span class="code-keyword">this</span> sample we use ActiveMQ
</span>    JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent);
    <span class="code-comment">// now we have the endpoint we can use regular Camel API to send a message to it
</span>    template.sendBody(endpoint, <span class="code-quote">"Here is the late reply."</span>);
</pre>
</div></div>

<p>A different solution to sending a reply is to provide the <tt>replyDestination</tt> object in the same Exchange property when sending. Camel will then pick up this property and use it for the real destination. The endpoint URI must include a dummy destination, however. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we pretend to send it to some non existing dummy queue
</span>    template.send("activemq:queue:dummy, <span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
</span>            exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
            exchange.getIn().setBody(<span class="code-quote">"Here is the late reply."</span>);
        }
    }
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Usingarequesttimeout"></a>Using a request timeout</h3>
<p>In the sample below we send a <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> style message <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> (we use the <tt>requestBody</tt> method = <tt>InOut</tt>) to the slow queue for further processing in Camel and we wait for a return reply: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// send a in-out with a timeout <span class="code-keyword">for</span> 5 sec
</span><span class="code-object">Object</span> out = template.requestBody(<span class="code-quote">"activemq:queue:slow?requestTimeout=5000"</span>, <span class="code-quote">"Hello World"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>
<p>JMS is used in many examples for other components as well. But we provide a few samples below to get started.</p>

<h4><a name="BookComponentAppendix-ReceivingfromJMS"></a>Receiving from JMS</h4>
<p>In the following sample we configure a route that receives JMS messages and routes the message to a POJO:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   from(<span class="code-quote">"jms:queue:foo"</span>).
     to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<p>You can of course use any of the EIP patterns so the route can be context based. For example, here's how to filter an order topic for the big spenders:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:topic:OrdersTopic"</span>).
  filter().method(<span class="code-quote">"myBean"</span>, <span class="code-quote">"isGoldCustomer"</span>).
    to(<span class="code-quote">"jms:queue:BigSpendersQueue"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-SendingtoaJMS"></a>Sending to a JMS </h4>
<p>In the sample below we poll a file folder and send the file content to a JMS topic. As we want the content of the file as a <tt>TextMessage</tt> instead of a <tt>BytesMessage</tt>, we need to convert the body to a <tt>String</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//orders"</span>).
</span>  convertBodyTo(<span class="code-object">String</span>.class).
  to(<span class="code-quote">"jms:topic:OrdersTopic"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingAnnotationsBeanIntegration"></a>Using <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Annotations</a></h4>
<p>Camel also has annotations so you can use <a href="/confluence/display/CAMEL/POJO+Consuming" title="POJO Consuming">POJO Consuming</a> and <a href="/confluence/display/CAMEL/POJO+Producing" title="POJO Producing">POJO Producing</a>. </p>

<h4><a name="BookComponentAppendix-SpringDSLsample"></a>Spring DSL sample</h4>
<p>The preceding examples use the Java DSL. Camel also supports Spring XML DSL. Here is the big spender sample using Spring DSL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"jms:topic:OrdersTopic"</span>/&gt;</span>
  <span class="code-tag">&lt;filter&gt;</span>
    <span class="code-tag">&lt;method bean=<span class="code-quote">"myBean"</span> method=<span class="code-quote">"isGoldCustomer"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"jms:queue:BigSpendersQueue"</span>/&gt;</span>
  <span class="code-tag">&lt;/filter&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Othersamples"></a>Other samples</h4>
<p>JMS appears in many of the examples for other components and EIP patterns, as well in this Camel documentation. So feel free to browse the documentation. If you have time, check out the this tutorial that uses JMS but focuses on how well Spring Remoting and Camel works together <a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a>.</p>

<h4><a name="BookComponentAppendix-UsingJMSasaDeadLetterQueuestoringExchange"></a>Using JMS as a Dead Letter Queue storing Exchange</h4>
<p><b>Available as of Camel 2.0</b><br/>
Normally, when using <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as the transport, it only transfers the body and headers as the payload. If you want to use <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with a <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead Letter Channel</a>, using a JMS queue as the Dead Letter Queue, then normally the caused Exception is not stored in the JMS message. You can, however, use the <b>transferExchange</b> option on the JMS dead letter queue to instruct Camel to store the entire <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> in the queue as a <tt>javax.jms.ObjectMessage</tt> that holds a <tt>org.apache.camel.impl.DefaultExchangeHolder</tt>. This allows you to consume from the Dead Letter Queue and retrieve the caused exception from the Exchange property with the key <tt>Exchange.EXCEPTION_CAUGHT</tt>. The demo below illustrates this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// setup error handler to use JMS as queue and store the entire Exchange
</span>errorHandler(deadLetterChannel(<span class="code-quote">"jms:queue:dead?transferExchange=<span class="code-keyword">true</span>"</span>));
</pre>
</div></div>

<p>Then you can consume from the JMS queue and analyze the problem:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:queue:dead"</span>).to(<span class="code-quote">"bean:myErrorAnalyzer"</span>);

<span class="code-comment">// and in our bean
</span><span class="code-object">String</span> body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
<span class="code-comment">// the cause message is
</span><span class="code-object">String</span> problem = cause.getMessage();
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingJMSasaDeadLetterChannelstoringerroronly"></a>Using JMS as a Dead Letter Channel storing error only</h4>
<p>You can use JMS to store the cause error message or to store a custom body, which you can initialize yourself. The following example uses the <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> EIP to do a transformation on the failed exchange before it is moved to the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> dead letter queue:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// we sent it to a seda dead queue first
</span>errorHandler(deadLetterChannel(<span class="code-quote">"seda:dead"</span>));

<span class="code-comment">// and on the seda dead queue we can <span class="code-keyword">do</span> the custom transformation before its sent to the JMS queue
</span>from(<span class="code-quote">"seda:dead"</span>).transform(exceptionMessage()).to(<span class="code-quote">"jms:queue:dead"</span>);
</pre>
</div></div>
<p>Here we only store the original cause error message in the transform. You can, however, use any <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to send whatever you like. For example, you can invoke a method on a Bean or use a custom processor.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a></li>
	<li><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a></li>
	<li><a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">JMSTemplate gotchas</a></li>
</ul>

<h2><a name="BookComponentAppendix-JPAComponent"></a>JPA Component</h2>

<p>The <b>jpa</b> component enables you to store and retrieve Java objects from persistent storage using EJB 3's Java Persistence Architecture (JPA), which is a standard interface layer that wraps Object/Relational Mapping (ORM) products such as OpenJPA, Hibernate, TopLink, and so on.</p>

<h3><a name="BookComponentAppendix-Sendingtotheendpoint"></a>Sending to the endpoint</h3>

<p>You can store a Java entity bean in a database by sending it to a JPA producer endpoint. The body of the <em>In</em> message is assumed to be an entity bean (that is, a POJO with an <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Entity.html" rel="nofollow">@Entity</a> annotation on it). </p>

<p>If the body does not contain an entity bean, put a <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> in front of the endpoint to perform the necessary conversion first.</p>

<h3><a name="BookComponentAppendix-Consumingfromtheendpoint"></a>Consuming from the endpoint</h3>

<p>Consuming messages from a JPA consumer endpoint removes (or updates) entity beans in the database. This allows you to use a database table as a logical queue: consumers take messages from the queue and then delete/update them to logically remove them from the queue.</p>

<p>If you do not wish to delete the entity bean when it has been processed, you can specify <tt>consumeDelete=false</tt> on the URI. This will result in the entity being processed each poll.</p>

<p>If you would rather perform some update on the entity to mark it as processed (such as to exclude it from a future query) then you can annotate a method with <a href="http://activemq.apache.org/camel/maven/camel-jpa/apidocs/org/apache/camel/component/jpa/Consumed.html" rel="nofollow">@Consumed</a> which will be invoked on your entity bean when the entity bean is consumed.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jpa:[entityClassName][?options]
</pre>
</div></div>

<p>For sending to the endpoint, the <em>entityClassName</em> is optional. If specified, it helps the <a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> to ensure the body is of the correct type.</p>

<p>For consuming, the <em>entityClassName</em> is mandatory.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>entityType</tt> </td>
<td class='confluenceTd'> <em>entityClassName</em> </td>
<td class='confluenceTd'> Overrides the <em>entityClassName</em> from the URI. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>persistenceUnit</tt> </td>
<td class='confluenceTd'> <tt>camel</tt> </td>
<td class='confluenceTd'> The JPA persistence unit used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeDelete</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> If <tt>true</tt>, the entity is deleted after it is consumed; if <tt>false</tt>, the entity is not deleted. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeLockEntity</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flushOnSend</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA producer only:</b> Flushes the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html" rel="nofollow">EntityManager</a> after the entity bean has been persisted. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maximumResults</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'>  <b>JPA consumer only:</b> Set the maximum number of results to retrieve on the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html" rel="nofollow">Query</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Specifies the transaction manager to use. If none provided, Camel will use a <tt>JpaTransactionManager</tt> by default. Can be used to set a JTA transaction manager (for integration with an EJB container). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Set to <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> <b>JPA consumer only:</b> An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to avoid polling many thousands of messages when starting up the server. Set a value of 0 or negative to disable. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.query</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a custom query when consuming data. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.namedQuery</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a named query when consuming data. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.nativeQuery</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a custom native query when consuming data. </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel adds the following message headers to the exchange:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJpaTemplate</tt> </td>
<td class='confluenceTd'> <tt>JpaTemplate</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> The <tt>JpaTemplate</tt> object that is used to access the entity bean. You need this object in some situations, for instance in a type converter or when you are doing some custom processing. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-ConfiguringEntityManagerFactory"></a>Configuring EntityManagerFactory</h3>
<p>You can configure the JPA component to use a specific <tt>EntityManagerFactory</tt> instance. For example, you can instantiate a JPA component that references the <tt>myEMFactory</tt> entity manager factory, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpa"</span> class=<span class="code-quote">"org.apache.camel.component.jpa.JpaComponent"</span>&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"entityManagerFactory"</span> ref=<span class="code-quote">"myEMFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfiguringTransactionManager"></a>Configuring TransactionManager</h3>
<p>You can specify the <tt>TransactionManager</tt> instance used by the JPA component. For example, you can instantiate a JPA component that references the <tt>myTransactionManager</tt> transaction manager, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpa"</span> class=<span class="code-quote">"org.apache.camel.component.jpa.JpaComponent"</span>&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"entityManagerFactory"</span> ref=<span class="code-quote">"myEMFactory"</span>/&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"transactionManager"</span> ref=<span class="code-quote">"myTransactionManager"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>See <a href="/confluence/display/CAMEL/Tracer+Example" title="Tracer Example">Tracer Example</a> for an example using <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> to store traced messages into a database.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Tracer+Example" title="Tracer Example">Tracer Example</a></li>
</ul>

<h2><a name="BookComponentAppendix-JT%2F400Component"></a>JT/400 Component</h2>

<p>The <b><tt>jt400</tt></b> component allows you to exchanges messages with an AS/400 system using data queues.  This components is only available in Camel 1.5 and above.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jt400:<span class="code-comment">//user:password@system/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ[?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-URIoptions"></a>URI options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>ccsid</tt> </td>
<td class='confluenceTd'> default system CCSID </td>
<td class='confluenceTd'> Specifies the CCSID to use for the connection with the AS/400 system. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>format</tt> </td>
<td class='confluenceTd'> <tt>text</tt> </td>
<td class='confluenceTd'> Specifies the data format for sending messages <br clear="all" /> valid options are: <tt>text</tt> (represented by <tt>String</tt>) and <tt>binary</tt> (represented by <tt>byte[]</tt>) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>When configured as a consumer endpoint, the endpoint will poll a data queue on a remote system.  For every entry on the data queue, a new <tt>Exchange</tt> is sent with the entry's data in the <em>In</em> message's body, formatted either as a <tt>String</tt> or a <tt>byte[]</tt>, depending on the format.  For a provider endpoint, the <em>In</em> message body contents will be put on the data queue as either raw bytes or text.</p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>In the snippet below, the data for an exchange sent to the <tt>direct:george</tt> endpoint will be put in the data queue <tt>PENNYLANE</tt> in library <tt>BEATLES</tt> on a system named <tt>LIVERPOOL</tt>.  <br clear="all" />
Another user connects to the same data queue to receive the information from the data queue and forward it to the <tt>mock:ringo</tt> endpoint.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class Jt400RouteBuilder <span class="code-keyword">extends</span> RouteBuilder {

    @Override
    <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
       from(<span class="code-quote">"direct:george"</span>).to(<span class="code-quote">"jt400:<span class="code-comment">//GEORGE:EGROEG@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"</span>);
</span>       from(<span class="code-quote">"jt400:<span class="code-comment">//RINGO:OGNIR@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"</span>).to(<span class="code-quote">"mock:ringo"</span>);
</span>    }
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-LDAPComponent"></a>LDAP Component</h2>

<p>The <b>ldap</b> component allows you to perform searches in LDAP servers using filters as the message payload.<br/>
This component uses standard JNDI (<tt>javax.naming</tt> package) to access the server. </p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ldap:ldapServerBean[?options]
</pre>
</div></div>

<p>The <em>ldapServerBean</em> portion of the URI refers to a <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html" rel="nofollow">DirContext</a> bean in the registry. The LDAP component only supports producer endpoints, which means that an <tt>ldap</tt> URI cannot appear in the <tt>from</tt> at the start of a route.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>base</tt> </td>
<td class='confluenceTd'> <tt>ou=system</tt> </td>
<td class='confluenceTd'> The base DN for searches. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scope</tt> </td>
<td class='confluenceTd'> <tt>subtree</tt> </td>
<td class='confluenceTd'> Specifies how deeply to search the tree of entries, starting at the base DN.  Value can be <tt>object</tt>, <tt>onelevel</tt>, or <tt>subtree</tt>. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Result"></a>Result</h3>
<p>The result is returned in the Out body as a <tt>ArrayList&lt;javax.naming.directory.SearchResult&gt;</tt> object. </p>

<h3><a name="BookComponentAppendix-DirContext"></a>DirContext</h3>

<p>The URI, <tt>ldap:ldapserver</tt>, references a Spring bean with the ID, <tt>ldapserver</tt>. The <tt>ldapserver</tt> bean may be defined as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"ldapserver"</span> class=<span class="code-quote">"javax.naming.directory.InitialDirContext"</span> scope=<span class="code-quote">"prototype"</span>&gt;
  &lt;constructor-arg&gt;
    &lt;props&gt;
      &lt;prop key=<span class="code-quote">"java.naming.factory.initial"</span>&gt;com.sun.jndi.ldap.LdapCtxFactory&lt;/prop&gt;
      &lt;prop key=<span class="code-quote">"java.naming.provider.url"</span>&gt;ldap:<span class="code-comment">//localhost:10389&lt;/prop&gt;
</span>      &lt;prop key=<span class="code-quote">"java.naming.security.authentication"</span>&gt;none&lt;/prop&gt;
    &lt;/props&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p>The preceding example declares a regular Sun based LDAP <tt>DirContext</tt> that connects anonymously to a locally hosted LDAP server.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p><tt>DirContext</tt> objects are <b>not</b> required to support concurrency by contract. It is therefore important that the directory context is declared with the setting, <tt>scope="prototype"</tt>, in the <tt>bean</tt> definition or that the context supports concurrency. In the Spring framework, <tt>prototype</tt> scoped objects are instantiated each time they are looked up.</p></td></tr></table></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>Camel 1.6.1 and Camel 2.0 include a <a href="https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=51503" rel="nofollow">fix</a> to support concurrency for LDAP producers. <em>ldapServerBean</em> contexts are now looked up each time a request is sent to the LDAP server. In addition, the contexts are released as soon as the producer completes.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>Following on from the Spring configuration above, the code sample below sends an LDAP request to filter search a group for a member. The Common Name is then extracted from the response.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ProducerTemplate&lt;Exchange&gt; template = exchange
  .getContext().createProducerTemplate();

Collection&lt;?&gt; results = (Collection&lt;?&gt;) (template
  .sendBody(
    <span class="code-quote">"ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system"</span>,
    <span class="code-quote">"(member=uid=huntc,ou=users,ou=system)"</span>));

<span class="code-keyword">if</span> (results.size() &gt; 0) {
  <span class="code-comment">// Extract what we need from the device's profile
</span>
  Iterator&lt;?&gt; resultIter = results.iterator();
  SearchResult searchResult = (SearchResult) resultIter
      .next();
  Attributes attributes = searchResult
      .getAttributes();
  Attribute deviceCNAttr = attributes.get(<span class="code-quote">"cn"</span>);
  <span class="code-object">String</span> deviceCN = (<span class="code-object">String</span>) deviceCNAttr.get();

  ...
</pre>
</div></div>

<p>If no specific filter is required - for example, you just need to look up a single entry - specify a wildcard filter expression. For example, if the LDAP entry has a Common Name, use a filter expression like:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
(cn=*)
</pre>
</div></div>
<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-LogComponent"></a>Log Component</h2>

<p>The <b>log:</b> component logs message exchanges to the underlying logging mechanism.</p>

<p>Camel uses <a href="http://commons.apache.org/logging/" rel="nofollow">commons-logging</a> which allows you to configure logging via </p>
<ul>
	<li><a href="http://logging.apache.org/log4j/" rel="nofollow">Log4j</a></li>
	<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html" rel="nofollow">JDK 1.4 logging</a></li>
	<li>Avalon</li>
	<li>SimpleLog - a simple provider in commons-logging</li>
</ul>


<p>Refer to the <a href="http://commons.apache.org/logging/commons-logging-1.1.1/guide.html" rel="nofollow">commons-logging user guide</a> for a more complete overview of how to use and configure commons-logging.</p>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
log:loggingCategory[?options]
</pre>
</div></div>

<p>Where <b>loggingCategory</b> is the name of the logging category to use. You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<p>For example, a log endpoint typically specifies the logging level using the <tt>level</tt> option, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
log:org.apache.camel.example?level=DEBUG
</pre>
</div></div>

<p>The default logger logs every exchange (<em>regular logging</em>). But Camel also ships with the <tt>Throughput</tt> logger, which is used whenever the <tt>groupSize</tt> option is specified.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Also a log in the DSL</b><br /><p>In <b>Camel 2.2</b> onwards there is a <tt>log</tt> directly in the DSL, but it has a different purpose. Its meant for lightweight and human logs. See more details at <a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a>.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>level</tt> </td>
<td class='confluenceTd'> <tt>INFO</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Logging level to use. Possible values: <tt>FATAL</tt>, <tt>ERROR</tt>, <tt>WARN</tt>, <tt>INFO</tt>, <tt>DEBUG</tt>, <tt>TRACE</tt>, <tt>OFF</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> An integer that specifies a group size for throughput logging. By default, regular logging is used. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Formatting"></a>Formatting</h3>
<p>The log formats the execution of exchanges to log lines. <br/>
By default, the log uses <tt>LogFormatter</tt> to format the log output, where <tt>LogFormatter</tt> has the following options:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>showAll</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Quick option for turning all options on. (multiline, maxChars has to be manually set if to be used) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showExchangeId</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the unique exchange ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the exchange properties. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showHeaders</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBodyType</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body Java type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBody</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If the exchange has an Out message, show the Out message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If the exchange has an exception, show the exception message (no stack trace). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showCaughtException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If the exchange has a caught exception, show the exception message (no stack trace). A caught exception is stored as a property on the exchange and for instance a <tt>doCatch</tt> can catch exceptions. See <a href="/confluence/display/CAMEL/Try+Catch+Finally" title="Try Catch Finally">Try Catch Finally</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showStackTrace</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Show the stack trace, if an exchange has an exception. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showFuture</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Whether Camel should show <tt>java.util.concurrent.Future</tt> bodies or not. If enabled Camel could potentially wait until the <tt>Future</tt> task is done. Will by default not wait. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, each piece of information is logged on a new line. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxChars</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Limits the number of characters logged per line. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Regularloggersample"></a>Regular logger sample</h3>
<p>In the route below we log the incoming orders at <tt>DEBUG</tt> level before the order is processed:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<p>Or using Spring XML to define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:orders"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processOrder"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span> 
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Regularloggerwithformattersample"></a>Regular logger with formatter sample</h3>
<p>In the route below we log the incoming orders at <tt>INFO</tt> level before the order is processed.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?showAll=<span class="code-keyword">true</span>&amp;multiline=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Throughputloggersample"></a>Throughput logger sample</h3>
<p>In the route below we log the throughput of the incoming orders at <tt>DEBUG</tt> level grouped by 10 messages.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG?groupSize=10"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+log4j" title="How do I use log4j">How do I use log4j</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+Java+1.4+logging" title="How do I use Java 1.4 logging">How do I use Java 1.4 logging</a></li>
	<li><a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a> for using <tt>log</tt> directly in the DSL for human logs.</li>
</ul>


<h2><a name="BookComponentAppendix-Lucene%28IndexerandSearch%29Component"></a>Lucene (Indexer and Search) Component</h2>

<p><b>Available as of Camel 2.2</b></p>

<p>The <b>lucene</b> component is based on the Apache Lucene project. Apache Lucene is a powerful high-performance, full-featured text search engine library written entirely in Java. For more details about Lucene, please see the following links </p>
<ul>
	<li><a href="http://lucene.apache.org/java/docs/" rel="nofollow">http://lucene.apache.org/java/docs/</a></li>
	<li><a href="http://lucene.apache.org/java/docs/features.html" rel="nofollow">http://lucene.apache.org/java/docs/features.html</a></li>
</ul>


<p>The lucene component in camel facilitates integration and utilization of Lucene endpoints in enterprise integration patterns and scenarios. The lucene component does the following</p>
<ul>
	<li>builds a searchable index of documents when payloads are sent to the Lucene Endpoint</li>
	<li>facilitates performing of indexed searches in Camel</li>
</ul>


<p>This component only supports producer endpoints. </p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
lucene:searcherName:insert[?options]
lucene:searcherName:query[?options]
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-InsertOptions"></a>Insert Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>analyzer</tt> </td>
<td class='confluenceTd'> <tt>StandardAnalyzer</tt> </td>
<td class='confluenceTd'> An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class org.apache.lucene.analysis.Analyzer. Lucene also offers a rich set of analyzers out of the box </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>indexDir</tt> </td>
<td class='confluenceTd'> <tt>./indexDirectory</tt> </td>
<td class='confluenceTd'> A file system directory in which index files are created upon analysis of the document by the specified analyzer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>srcDir</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> An optional directory containing files to be used to be analyzed and added to the index at producer startup. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-QueryOptions"></a>Query Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>analyzer</tt> </td>
<td class='confluenceTd'> <tt>StandardAnalyzer</tt> </td>
<td class='confluenceTd'> An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class org.apache.lucene.analysis.Analyzer. Lucene also offers a rich set of analyzers out of the box </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>indexDir</tt> </td>
<td class='confluenceTd'> <tt>./indexDirectory</tt> </td>
<td class='confluenceTd'> A file system directory in which index files are created upon analysis of the document by the specified analyzer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxHits</tt> </td>
<td class='confluenceTd'> <tt>10</tt> </td>
<td class='confluenceTd'> An integer value that limits the result set of the search operation </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Sending%2FReceivingMessagesto%2Ffromthecache"></a>Sending/Receiving Messages to/from the cache</h3>

<h4><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>QUERY</tt> </td>
<td class='confluenceTd'> The Lucene Query to performed on the index. The query may include wildcards and phrases </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-LuceneProducers"></a>Lucene Producers </h4>
<p>This component supports 2 producer endpoints.</p>
<ul>
	<li><b>insert</b> - The insert producer builds a searchable index by analyzing the body in incoming exchanges and associating it with a token ("content").</li>
	<li><b>query</b> - The query producer performs searches on a pre-created index. The query uses the searchable index to perform score &amp; relevance based searches. Queries are sent via the incoming exchange contains a header property name called 'QUERY'. The value of the header property 'QUERY' is a Lucene Query. For more details on how to create Lucene Queries check out <a href="http://lucene.apache.org/java/3_0_0/queryparsersyntax.html" rel="nofollow">http://lucene.apache.org/java/3_0_0/queryparsersyntax.html</a></li>
</ul>


<h4><a name="BookComponentAppendix-LuceneProcessor"></a>Lucene Processor </h4>
<p>There is a processor called LuceneQueryProcessor available to perform queries against lucene without the need to create a producer.</p>

<h3><a name="BookComponentAppendix-LuceneUsageSamples"></a>Lucene Usage Samples</h3>

<h4><a name="BookComponentAppendix-Example1%3ACreatingaLuceneindex"></a>Example 1: Creating a Lucene index</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(<span class="code-quote">"direct:start"</span>).
           to(<span class="code-quote">"lucene:whitespaceQuotesIndex:insert?analyzer=#whitespaceAnalyzer&amp;indexDir=#whitespace&amp;srcDir=#load_dir"</span>).
           to(<span class="code-quote">"mock:result"</span>);
    }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3ALoadingpropertiesintotheJNDIregistryintheCamelContext"></a>Example 2: Loading properties into the JNDI registry in the Camel Context </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Override
<span class="code-keyword">protected</span> JndiRegistry createRegistry() <span class="code-keyword">throws</span> Exception {
  JndiRegistry registry =
         <span class="code-keyword">new</span> JndiRegistry(createJndiContext());
  registry.bind(<span class="code-quote">"whitespace"</span>, <span class="code-keyword">new</span> File(<span class="code-quote">"./whitespaceIndexDir"</span>));
  registry.bind(<span class="code-quote">"load_dir"</span>,
        <span class="code-keyword">new</span> File(<span class="code-quote">"src/test/resources/sources"</span>));
  registry.bind(<span class="code-quote">"whitespaceAnalyzer"</span>,
        <span class="code-keyword">new</span> WhitespaceAnalyzer());
  <span class="code-keyword">return</span> registry;
}
...
CamelContext context = <span class="code-keyword">new</span> DefaultCamelContext(createRegistry());
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3APerformingsearchesusingaQueryProducer"></a>Example 2: Performing searches using a Query Producer</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(<span class="code-quote">"direct:start"</span>).
          setHeader(<span class="code-quote">"QUERY"</span>, constant(<span class="code-quote">"Seinfeld"</span>)).
          to(<span class="code-quote">"lucene:searchIndex:query?analyzer=#whitespaceAnalyzer&amp;indexDir=#whitespace&amp;maxHits=20"</span>).
          to(<span class="code-quote">"direct:next"</span>);
                
       from(<span class="code-quote">"direct:next"</span>).process(<span class="code-keyword">new</span> Processor() {
          <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
             Hits hits = exchange.getIn().getBody(Hits.class);
             printResults(hits);
          }

          <span class="code-keyword">private</span> void printResults(Hits hits) {
              LOG.debug(<span class="code-quote">"<span class="code-object">Number</span> of hits: "</span> + hits.getNumberOfHits());
              <span class="code-keyword">for</span> (<span class="code-object">int</span> i = 0; i &lt; hits.getNumberOfHits(); i++) {
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Index Location:"</span> + hits.getHit().get(i).getHitLocation());
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Score:"</span> + hits.getHit().get(i).getScore());
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Data:"</span> + hits.getHit().get(i).getData());
              }
           }
       }).to(<span class="code-quote">"mock:searchResult"</span>);
   }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example3%3APerformingsearchesusingaQueryProcessor"></a>Example 3: Performing searches using a Query Processor </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {            
        <span class="code-keyword">try</span> {
            from(<span class="code-quote">"direct:start"</span>).
                setHeader(<span class="code-quote">"QUERY"</span>, constant(<span class="code-quote">"Rodney Dangerfield"</span>)).
                process(<span class="code-keyword">new</span> LuceneQueryProcessor(<span class="code-quote">"target/stdindexDir"</span>, analyzer, <span class="code-keyword">null</span>, 20)).
                to(<span class="code-quote">"direct:next"</span>);
        } <span class="code-keyword">catch</span> (Exception e) {
            e.printStackTrace();
        }
                
        from(<span class="code-quote">"direct:next"</span>).process(<span class="code-keyword">new</span> Processor() {
            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                Hits hits = exchange.getIn().getBody(Hits.class);
                printResults(hits);
            }
                    
            <span class="code-keyword">private</span> void printResults(Hits hits) {
                LOG.debug(<span class="code-quote">"<span class="code-object">Number</span> of hits: "</span> + hits.getNumberOfHits());
                <span class="code-keyword">for</span> (<span class="code-object">int</span> i = 0; i &lt; hits.getNumberOfHits(); i++) {
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Index Location:"</span> + hits.getHit().get(i).getHitLocation());
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Score:"</span> + hits.getHit().get(i).getScore());
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Data:"</span> + hits.getHit().get(i).getData());
                }
            }
       }).to(<span class="code-quote">"mock:searchResult"</span>);
   }
};
</pre>
</div></div>
<h2><a name="BookComponentAppendix-MailComponent"></a>Mail Component</h2>

<p>The mail component provides access to Email via Spring's Mail support and the underlying JavaMail system.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Geronimo mail .jar</b><br /><p>We have discovered that the geronimo mail <tt>.jar</tt> (v1.6) has a bug when polling mails with attachments. It cannot correctly identify the <tt>Content-Type</tt>. So, if you attach a <tt>.jpeg</tt> file to a mail and you poll it, the <tt>Content-Type</tt> is resolved as <tt>text/plain</tt> and not as <tt>image/jpeg</tt>. For that reason, we have added an <tt>org.apache.camel.component.ContentTypeResolver</tt> SPI interface which enables you to provide your own implementation and fix this bug by returning the correct Mime type based on the file name. So if the file name ends with <tt>jpeg/jpg</tt>, you can return <tt>image/jpeg</tt>.</p>

<p>You can set your custom resolver on the <tt>MailComponent</tt> instance or on the <tt>MailEndpoint</tt> instance. This feature is added in Camel 1.6.2/2.0.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>POP3 or IMAP</b><br /><p>POP3 has some limitations and end users are encouraged to use IMAP if possible.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<p>Mail endpoints can have one of the following URI formats (for the protocols, SMTP, POP3, or IMAP, respectively):</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//[username@]host[:port][?options]
</span>pop3:<span class="code-comment">//[username@]host[:port][?options]
</span>imap:<span class="code-comment">//[username@]host[:port][?options]</span>
</pre>
</div></div>

<p>The mail component also supports secure variants of these protocols (layered over SSL). You can enable the secure protocols by adding <tt>s</tt> to the scheme:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtps:<span class="code-comment">//[username@]host[:port][?options]
</span>pop3s:<span class="code-comment">//[username@]host[:port][?options]
</span>imaps:<span class="code-comment">//[username@]host[:port][?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h4><a name="BookComponentAppendix-Sampleendpoints"></a>Sample endpoints</h4>

<p>Typically, you specify a URI with login credentials as follows (taking SMTP as an example):</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//[username@]host[:port][?password=somepwd]</span>
</pre>
</div></div>

<p>Alternatively, it is possible to specify both the user name and the password as query options:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//host[:port]?password=somepwd&amp;username=someuser</span>
</pre>
</div></div>

<p>For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//mycompany.mailserver:30?password=tiger&amp;username=scott</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Defaultports"></a><a name="BookComponentAppendix-DefaultPorts"></a>Default ports</h4>
<p>As of Camel 1.4, default port numbers are supported. If the port number is omitted, Camel determines the port number to use based on the protocol.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Protocol </th>
<th class='confluenceTh'> Default Port Number </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMPT</tt> </td>
<td class='confluenceTd'> <tt>25</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMPTS</tt> </td>
<td class='confluenceTd'> <tt>465</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3</tt> </td>
<td class='confluenceTd'> <tt>110</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3S</tt> </td>
<td class='confluenceTd'> <tt>995</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAP</tt> </td>
<td class='confluenceTd'> <tt>143</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAPS</tt> </td>
<td class='confluenceTd'> <tt>993</tt> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>host</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The host name or IP address to connect to. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>port</tt> </td>
<td class='confluenceTd'> See <a href="#BookComponentAppendix-DefaultPorts">DefaultPorts</a> </td>
<td class='confluenceTd'> The TCP port number to connect on. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The user name on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUriScheme</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>false</tt>, Camel uses the scheme to determine the transport protocol (POP, IMAP, SMTP etc.) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultEncoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default encoding to use for Mime Messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentType</tt> </td>
<td class='confluenceTd'> <tt>text/plain</tt> </td>
<td class='confluenceTd'> New option in <b>Camel 1.5</b>. The mail message content type. Use <tt>text/html</tt> for HTML mails. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>folderName</tt> </td>
<td class='confluenceTd'> <tt>INBOX</tt> </td>
<td class='confluenceTd'> The folder to poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b> Use the <tt>to</tt> option instead. The <tt>TO</tt> recipients (receivers of the email). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>to</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the TO recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the CC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>BCC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the BCC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>from</tt> </td>
<td class='confluenceTd'> <tt>camel@localhost</tt> </td>
<td class='confluenceTd'> The FROM email address. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deleteProcessedMessages</tt> </td>
<td class='confluenceTd'> <tt>true</tt>/<tt>false</tt> </td>
<td class='confluenceTd'> Deletes the messages after they have been processed. This is done by setting the <tt>DELETED</tt> flag on the mail message. If <tt>false</tt>, the <tt>SEEN</tt> flag is set instead. As of <b>Camel 1.5</b>, the default setting is <tt>false</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delete</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Deletes the messages after they have been processed. This is done by setting the <tt>DELETED</tt> flag on the mail message. If <tt>false</tt>, the <tt>SEEN</tt> flag is set instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>processOnlyUnseenMessages</tt> </td>
<td class='confluenceTd'> <tt>false</tt>/<tt>true</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, it is possible to configure a consumer endpoint so that it processes only unseen messages (that is, new messages) or all messages. Note that Camel always skips deleted messages. Setting this option to <tt>true</tt> will filter to only unseen messages. As of Camel 1.5, the default setting is <tt>true</tt>. POP3 does not support the <tt>SEEN</tt> flag, so this option is not supported in POP3; use IMAP instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>unseen</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Is used to fetch only unseen messages (that is, new messages). Note that POP3 does not support the <tt>SEEN</tt> flag; use IMAP instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fetchSize</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, this option sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server, if a mailbox folder contains a lot of messages. Default value of <tt>-1</tt> means no fetch size and all messages will be consumed. Setting the value to 0 is a special corner case, where Camel will not consume any messages at all. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alternateBodyHeader</tt> </td>
<td class='confluenceTd'> <tt>mail_alternateBody</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1</b>: Specifies the key to an IN message header that contains an alternative email body. For example, if you send emails in <tt>text/html</tt> format and want to provide an alternative mail body for non-HTML email clients, set the alternative mail body with this key as a header. In Camel 2.0, this option has been renamed to <tt>alternativeBodyHeader</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alternativeBodyHeader</tt> </td>
<td class='confluenceTd'> <tt>CamelMailAlternativeBody</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Specifies the key to an IN message header that contains an alternative email body. For example, if you send emails in <tt>text/html</tt> format and want to provide an alternative mail body for non-HTML email clients, set the alternative mail body with this key as a header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>debugMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, it is possible to enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to <tt>System.out</tt> by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the connection timeout can be configured in milliseconds. Default is 30 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before the polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the default consumer delay is now 60 seconds. Camel will therefore only poll the mailbox once a minute to avoid overloading the mail server. The default value in Camel 1.3 is 500 milliseconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.useFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use a fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mail.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 2.0</b>, you can set any <a href="http://java.sun.com/products/javamail/javadocs/index.html" rel="nofollow">additional java mail properties</a>. For instance if you want to set a special property when using POP3 you can now provide the option directly in the URI such as: <tt>mail.pop3.forgettopheaders=true</tt>. You can set multiple such options, for example: <tt>mail.pop3.forgettopheaders=true&amp;mail.mime.encodefilename=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid downloading thousands of files when the server starts up. Set a value of 0 or negative to disable this option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javaMailSender</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies a pluggable <tt>org.springframework.mail.javamail.JavaMailSender</tt> instance in order to use a custom email implementation. If none provided, Camel uses the default, <tt>org.springframework.mail.javamail.JavaMailSenderImpl</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>dummyTrustManager</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, when testing SSL connections, you can enable the dummy trust manager by setting this option to <tt>true</tt>. When the dummy trust manager is enabled, the mail client skips the server certificate check. <div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Warning</b><br />Enabling this option makes the email connection <em>completely insecure</em>. The connection becomes vulnerable to a <em>man-in-the-middle</em> attack, which implies that your login credentials can be stolen. Do not use this option in a production environment.</td></tr></table></div></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUnsupportedCharset</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then <tt>charset=XXX</tt> (where <tt>XXX</tt> represents the unsupported charset) is removed from the <tt>content-type</tt> and it relies on the platform default instead. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-SSLsupport"></a>SSL support</h3>
<p>The underlying mail framework is responsible for providing SSL support. Camel uses SUN JavaMail, which only trusts certificates issued by well known Certificate Authorities. So if you issue your own certificate, you have to import it into the local Java keystore file (see <tt>SSLNOTES.txt</tt> in JavaMail for details).</p>

<h3><a name="BookComponentAppendix-DefaultschangedinCamel1.4"></a>Defaults changed in Camel 1.4</h3>
<p>As of Camel 1.4 the default consumer delay is now 60 seconds. Camel will therefore only poll the mailbox once a minute to avoid overloading the mail server. The default value in Camel 1.3 is 500 milliseconds.</p>

<h3><a name="BookComponentAppendix-DefaultschangedinCamel1.5"></a>Defaults changed in Camel 1.5</h3>
<p>In Camel 1.5 the following default options have changed:</p>
<ul class="alternate" type="square">
	<li><tt>deleteProcessedMessages</tt> is now <b>false</b>, as we felt Camel should not delete mails on the mail server by default.</li>
	<li><tt>processOnlyUnseenMessages</tt> is now <b>true</b>, as we felt Camel should only poll new mails by default.</li>
</ul>


<h3><a name="BookComponentAppendix-MailMessageContent"></a>Mail Message Content</h3>
<p>Camel uses the message exchange's IN body as the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" rel="nofollow">MimeMessage</a> text content. The body is converted to <tt>String.class</tt>.</p>

<p>Camel copies all of the exchange's IN headers to the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" rel="nofollow">MimeMessage</a> headers. </p>

<p>The subject of the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" rel="nofollow">MimeMessage</a> can be configured using a header property on the IN message. The code below demonstrates this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:a"</span>).setHeader(<span class="code-quote">"subject"</span>, constant(subject)).to(<span class="code-quote">"smtp:<span class="code-comment">//james2@localhost"</span>);</span>
</pre>
</div></div>

<p>The same applies for other MimeMessage headers such as recipients, so you can use a header property as <tt>To</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Map map = <span class="code-keyword">new</span> HashMap();
map.put(<span class="code-quote">"To"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"jstrachan@apache.org"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel rocks"</span>);

<span class="code-object">String</span> body = <span class="code-quote">"Hello Claus.\nYes it does.\n\nRegards James."</span>;
template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//davsclaus@apache.org"</span>, body, map);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Headerstakeprecedenceoverpreconfiguredrecipients"></a>Headers take precedence over pre-configured recipients</h3>
<p>From Camel 1.5 onwards, the recipients specified in the message headers always take precedence over recipients pre-configured in the endpoint URI. The idea is that if you provide any recipients in the message headers, that is what you get. The recipients pre-configured in the endpoint URI are treated as a fallback.</p>

<p>In the sample code below, the email message is sent to <tt>davsclaus@apache.org</tt>, because it takes precedence over the pre-configured recipient, <tt>info@mycompany.com</tt>. Any <tt>CC</tt> and <tt>BCC</tt> settings in the endpoint URI are also ignored and those recipients will not receive any mail. The choice between headers and pre-configured settings is all or nothing: the mail component <em>either</em> takes the recipients exclusively from the headers or exclusively from the pre-configured settings. It is not possible to mix and match headers and pre-configured settings.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);

        template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//admin@localhost?to=info@mycompany.com"</span>, <span class="code-quote">"Hello World"</span>, headers);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Multiplerecipientsforeasierconfiguration"></a>Multiple recipients for easier configuration</h3>
<p>As of Camel 1.5, it is possible to set multiple recipients using a comma-separated or a semicolon-separated list. This applies both to header settings and to settings in an endpoint URI. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org ; jstrachan@apache.org ; ningjiang@apache.org"</span>);
</pre>
</div></div>

<p>The preceding example uses a semicolon, <tt>;</tt>, as the separator character.</p>

<h3><a name="BookComponentAppendix-Settingsendernameandemail"></a>Setting sender name and email</h3>
<p>You can specify recipients in the format, <tt>name &lt;email&gt;</tt>, to include both the name and the email address of the recipient.</p>

<p>For example, you define the following headers on the a <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Map headers = <span class="code-keyword">new</span> HashMap();
map.put(<span class="code-quote">"To"</span>, <span class="code-quote">"Claus Ibsen &lt;davsclaus@apache.org&gt;"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"James Strachan &lt;jstrachan@apache.org&gt;"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel is cool"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SUNJavaMail"></a>SUN JavaMail </h3>
<p><a href="http://java.sun.com/products/javamail/" rel="nofollow">SUN JavaMail</a> is used under the hood for consuming and producing mails. <br/>
We encourage end-users to consult these references when using either POP3 or IMAP protocol. Note particularly that POP3 has a much more limited set of features than IMAP.</p>
<ul class="alternate" type="square">
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/pop3/package-summary.html" rel="nofollow">SUN POP3 API</a></li>
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html" rel="nofollow">SUN IMAP API</a></li>
	<li>And generally about the <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/Flags.html" rel="nofollow">MAIL Flags</a></li>
</ul>


<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>We start with a simple route that sends the messages received from a JMS queue as emails. The email account is the <tt>admin</tt> account on <tt>mymailserver.com</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:<span class="code-comment">//queue:subscription"</span>).to(<span class="code-quote">"smtp://admin@mymailserver.com?password=secret"</span>);</span>
</pre>
</div></div>

<p>In the next sample, we poll a mailbox for new emails once every minute. Notice that we use the special <tt>consumer</tt> option for setting the poll interval, <tt>consumer.delay</tt>, as 60000 milliseconds = 60 seconds.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imap:<span class="code-comment">//admin@mymailserver.com?password=secret&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).to(<span class="code-quote">"seda://mails"</span>);</span>
</pre>
</div></div>

<p>In this sample we want to send a mail to multiple recipients. This feature was introduced in camel 1.4:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// all the recipients of <span class="code-keyword">this</span> mail are:
</span><span class="code-comment">// To: camel@riders.org , easy@riders.org
</span><span class="code-comment">// CC: me@you.org
</span><span class="code-comment">// BCC: someone@somewhere.org
</span><span class="code-object">String</span> recipients = <span class="code-quote">"&amp;To=camel@riders.org,easy@riders.org&amp;CC=me@you.org&amp;BCC=someone@somewhere.org"</span>;

from(<span class="code-quote">"direct:a"</span>).to(<span class="code-quote">"smtp:<span class="code-comment">//you@mymailserver.com?password=secret&amp;From=you@apache.org"</span> + recipients);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Sendingmailwithattachmentsample"></a>Sending mail with attachment sample</h3>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Attachments are not support by all Camel components</b><br /><p>The <em>Attachments API</em> is based on the Java Activation Framework and is generally only used by the Mail API. Since many of the other Camel components do not support attachments, the attachments could potentially be lost as they propagate along the route. The rule of thumb, therefore, is to add attachments just before sending a message to the mail endpoint. </p></td></tr></table></div>

<p>The mail component supports attachments, which is a feature that was introduced in Camel 1.4. In the sample below, we send a mail message containing a plain text message with a logo file attachment.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// create an exchange with a normal body and attachment to be produced as email
</span>Endpoint endpoint = context.getEndpoint(<span class="code-quote">"smtp:<span class="code-comment">//james@mymailserver.com?password=secret"</span>);
</span>
<span class="code-comment">// create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
</span>Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
in.setBody(<span class="code-quote">"Hello World"</span>);
in.addAttachment(<span class="code-quote">"logo.jpeg"</span>, <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> FileDataSource(<span class="code-quote">"src/test/data/logo.jpeg"</span>)));

<span class="code-comment">// create a producer that can produce the exchange (= send the mail)
</span>Producer producer = endpoint.createProducer();
<span class="code-comment">// start the producer
</span>producer.start();
<span class="code-comment">// and let it go (processes the exchange by sending the email)
</span>producer.process(exchange);

</pre>
</div></div>

<h3><a name="BookComponentAppendix-SSLsample"></a>SSL sample</h3>

<p>In this sample, we want to poll our Google mail inbox for mails. To download mail onto a local mail client, Google mail requires you to enable and configure SSL. This is done by logging into your Google mail account and changing your settings to allow IMAP access. Google have extensive documentation on how to do this.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;deleteProcessedMessages=<span class="code-keyword">false</span>&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).to(<span class="code-quote">"log:newmail"</span>);
</pre>
</div></div>

<p>The preceding route polls the Google mail inbox for new mails once every minute and logs the received messages to the <tt>newmail</tt> logger category.<br/>
Running the sample with <tt>DEBUG</tt> logging enabled, we can monitor the progress in the logs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-05-08 06:32:09,640 DEBUG MailConsumer - Connecting to MailStore imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX
</span>2008-05-08 06:32:11,203 DEBUG MailConsumer - Polling mailfolder: imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX 
</span>2008-05-08 06:32:11,640 DEBUG MailConsumer - Fetching 1 messages. Total 1 messages. 
2008-05-08 06:32:12,171 DEBUG MailConsumer - Processing message: messageNumber=[332], from=[James Bond &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[... 
2008-05-08 06:32:12,187 INFO  newmail - Exchange[MailMessage: messageNumber=[332], from=[James Bond &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[...
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Consumingmailswithattachmentsample"></a>Consuming mails with attachment sample</h3>
<p>In this sample we poll a mailbox and store all attachments from the mails as files. First, we define a route to poll the mailbox. As this sample is based on google mail, it uses the same route as shown in the SSL sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;deleteProcessedMessages=<span class="code-keyword">false</span>&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).process(<span class="code-keyword">new</span> MyMailProcessor());
</pre>
</div></div>

<p>Instead of logging the mail we use a processor where we can process the mail from java code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// the API is a bit clunky so we need to loop
</span>        Map&lt;<span class="code-object">String</span>, DataHandler&gt; attachments = exchange.getIn().getAttachments();
        <span class="code-keyword">if</span> (attachments.size() &gt; 0) {
            <span class="code-keyword">for</span> (<span class="code-object">String</span> name : attachments.keySet()) {
                DataHandler dh = attachments.get(name);
                <span class="code-comment">// get the file name
</span>                <span class="code-object">String</span> filename = dh.getName();

                <span class="code-comment">// get the content and convert it to <span class="code-object">byte</span>[]
</span>                 <span class="code-object">byte</span>[] data = exchange.getContext().getTypeConverter().convertTo(<span class="code-object">byte</span>[].class, dh.getInputStream());

                <span class="code-comment">// write the data to a file
</span>                FileOutputStream out = <span class="code-keyword">new</span> FileOutputStream(filename);
                out.write(data);
                out.flush();
                out.close();
            }
        }
   }
</pre>
</div></div>
<p>As you can see the API to handle attachments is a bit clunky but it's there so you can get the <tt>javax.activation.DataHandler</tt> so you can handle the attachments using standard API.        </p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-MINAComponent"></a>MINA Component</h2>

<p>The <b>mina:</b> component is a transport for working with <a href="http://mina.apache.org/" rel="nofollow">Apache MINA</a></p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mina:tcp:<span class="code-comment">//hostname[:port][?options]
</span>mina:udp:<span class="code-comment">//hostname[:port][?options]
</span>mina:multicast:<span class="code-comment">//hostname[:port][?options]
</span>mina:vm:<span class="code-comment">//hostname[:port][?options]</span>
</pre>
</div></div>
<p>From Camel 1.3 onwards you can specify a codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> using the <b>codec</b> option. If you are using TCP and no codec is specified then the <tt>textline</tt> flag is used to determine if text line based codec or object serialization should be used instead. By default the object serialization is used.</p>

<p>For UDP/Multicast if no codec is specified the default uses a basic <tt>ByteBuffer</tt> based codec.</p>

<p>Multicast also has a shorthand notation <b>mcast</b>.</p>

<p>The VM protocol is used as a direct forwarding mechanism in the same JVM. See the <a href="http://mina.apache.org/report/1.1/apidocs/org/apache/mina/transport/vmpipe/package-summary.html" rel="nofollow">MINA VM-Pipe API documentation</a> for details.</p>

<p>A Mina producer has a default timeout value of 30 seconds, while it waits for a response from the remote server.</p>

<p>In normal use, <tt>camel-mina</tt> only supports marshalling the body content&mdash;message headers and exchange properties are not sent.<br/>
However, the option, <b>transferExchange</b>, does allow you to transfer the exchange itself over the wire. See options below.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option</th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>codec</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of 1.3, you can refer to a named <tt>ProtocolCodecFactory</tt> instance in your <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> such as your Spring <tt>ApplicationContext</tt>, which is then used for the marshalling. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>codec</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> You must use the <tt>&#35;</tt> notation to look up your codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. For example, use <tt>#myCodec</tt> to look up a bean with the <tt>id</tt> value, <tt>myCodec</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Only used for TCP. If no codec is specified, you can use this flag in 1.3 or later to indicate a text line based codec; if not specified or the value is <tt>false</tt>, then Object Serialization is assumed over TCP. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textlineDelimiter</tt> </td>
<td class='confluenceTd'> <tt>DEFAULT</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5.1/2.0</b> Only used for TCP and if <b>textline=true</b>. Sets the text line delimiter to use. Possible values are: <tt>DEFAULT</tt>, <tt>AUTO</tt>, <tt>WINDOWS</tt>, <tt>UNIX</tt> or <tt>MAC</tt>. If none provided, Camel will use <tt>DEFAULT</tt>. This delimiter is used to mark the end of text. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sync</tt> </td>
<td class='confluenceTd'> <tt>false</tt>/<tt>true</tt> </td>
<td class='confluenceTd'> As of 1.3, you can configure the exchange pattern to be either InOnly (default) or InOut. Setting <tt>sync=true</tt> means a synchronous exchange (InOut), where the client can read the response from MINA (the exchange Out message). The default value has changed in Camel 1.5 to <tt>true</tt>. In older releases, the default value is <tt>false</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lazySessionCreation</tt> </td>
<td class='confluenceTd'> <em>See description</em> </td>
<td class='confluenceTd'> As of 1.3, sessions can be lazily created to avoid exceptions, if the remote server is not up and running when the Camel producer is started. From Camel 2.0 onwards, the default is <tt>true</tt>. In Camel 1.x, the default is <tt>false</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> As of 1.3, you can configure the timeout that specifies how long to wait for a response from a remote server. The timeout unit is in milliseconds, so 60000 is 60 seconds. The timeout is only used for Mina producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <em>JVM Default</em> </td>
<td class='confluenceTd'> As of 1.3, you can configure the encoding (a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" rel="nofollow">charset name</a>) to use for the TCP textline codec and the UDP protocol. If not provided, Camel will use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()" rel="nofollow">JVM default Charset</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Only used for TCP. As of 1.3, you can transfer the exchange over the wire instead of just the body. The following fields are transferred: In body, Out body, fault body, In headers, Out headers, fault headers, exchange properties, exchange exception. This requires that the objects are <em>serializable</em>. Camel will exclude any non-serializable objects and log it at <tt>WARN</tt> level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>minaLogger</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> As of 1.3, you can enable the Apache MINA logging filter. Apache MINA uses <tt>slf4j</tt> logging at <tt>INFO</tt> level to log all input and output. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of 2.0, you can set a list of <a href="http://mina.apache.org/iofilter.html" rel="nofollow">Mina IoFilters</a> to register. The <tt>filters</tt> value must be one of the following: 
<ul>
	<li><b>Camel 2.2:</b> comma-separated list of bean references (e.g. <tt>#filterBean1,#filterBean2</tt>) where each bean must be of type <tt>org.apache.mina.common.IoFilter</tt>.</li>
	<li><b>Camel 2.0:</b> a reference to a bean of type <tt>List&lt;org.apache.mina.common.IoFilter&gt;</tt>.</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoderMaxLineLength</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of 2.1, you can set the textline protocol encoder max line length. By default the default value of Mina itself is used which are <tt>Integer.MAX_VALUE</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decorderMaxLineLength</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of 2.1, you can set the textline protocol decoder max line length. By default the default value of Mina itself is used which are 1024. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>producerPoolSize</tt> </td>
<td class='confluenceTd'> 16 </td>
<td class='confluenceTd'> <b>1.6.2 (only in 1.6.x)</b>: The TCP producer is now thread safe and supports concurrency much better. This option allows you to configure the number of threads in its thread pool for concurrent producers. <b>Note:</b> Camel 2.0 have a pooled service which ensured it was already thread safe and supported concurrency already. So this is a special patch for 1.6.x. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowDefaultCodec</tt> </td>
<td class='confluenceTd'><tt>true</tt></td>
<td class='confluenceTd'> The mina component installs a default codec if both, <tt>codec</tt> is <tt>null</tt> and <tt>textline</tt> is <tt>false</tt>. Setting <tt>allowDefaultCodec</tt> to <tt>false</tt> prevents the mina component from installing a default codec as the first element in the filter chain. This is useful in scenarios where another filter must be the first in the filter chain, like the SSL filter.</td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Defaultbehaviorchanged"></a>Default behavior changed</h3>
<p>In Camel 2.0 the <b>codec</b> option must use <tt>&#35;</tt> notation for lookup of the codec bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.<br/>
In Camel 2.0 the <b>lazySessionCreation</b> option now defaults to <tt>true</tt>.</p>

<p>In Camel 1.5 the <tt>sync</tt> option has changed its default value from <tt>false</tt> to <tt>true</tt>, as we felt it was confusing for end-users when they used <a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a> to call remote servers and Camel wouldn't wait for the response.</p>

<p>In Camel 1.4 or later <tt>codec=textline</tt> is no longer supported. Use the <tt>textline=true</tt> option instead.</p>

<h3><a name="BookComponentAppendix-Usingacustomcodec"></a>Using a custom codec</h3>
<p>See the <a href="http://mina.apache.org/tutorial-on-protocolcodecfilter.html" rel="nofollow">Mina documentation</a> how to write your own codec. To use your custom codec with <tt>camel-mina</tt>, you should register your codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>; for example, by creating a bean in the Spring XML file. Then use the <tt>codec</tt> option to specify the bean ID of your codec. See <a href="/confluence/display/CAMEL/HL7" title="HL7">HL7</a> that has a custom codec.</p>

<h3><a name="BookComponentAppendix-Samplewithsync%3Dfalse"></a>Sample with sync=false</h3>

<p>In this sample, Camel exposes a service that listens for TCP connections on port 6200. We use the <b>textline</b> codec. In our route, we create a Mina consumer endpoint that listens on port 6200:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6200?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">false</span>"</span>).to(<span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>As the sample is part of a unit test, we test it by sending some data to it on port 6200. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
mock.expectedBodiesReceived(<span class="code-quote">"Hello World"</span>);

template.sendBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6200?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">false</span>"</span>, <span class="code-quote">"Hello World"</span>);
</span>
assertMockEndpointsSatisfied();
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Samplewithsync%3Dtrue"></a>Sample with sync=true</h3>

<p>In the next sample, we have a more common use case where we expose a TCP service on port 6201 also use the textline codec. However, this time we want to return a response, so we set the <tt>sync</tt> option to <tt>true</tt> on the consumer. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6201?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">true</span>"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
        exchange.getOut().setBody(<span class="code-quote">"Bye "</span> + body);
    }
});
</pre>
</div></div>

<p>Then we test the sample by sending some data and retrieving the response using the <tt>template.requestBody()</tt> method. As we know the response is a <tt>String</tt>, we cast it to <tt>String</tt> and can assert that the response is, in fact, something we have dynamically set in our processor code logic.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-object">String</span> response = (<span class="code-object">String</span>)template.requestBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6201?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">true</span>"</span>, <span class="code-quote">"World"</span>);
</span>assertEquals(<span class="code-quote">"Bye World"</span>, response);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SamplewithSpringDSL"></a>Sample with Spring DSL</h3>
<p>Spring DSL can, of course, also be used for <a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a>. In the sample below we expose a TCP server on port 5555:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"mina:tcp://localhost:5555?textline=true"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myTCPOrderHandler"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>In the route above, we expose a TCP server on port 5555 using the textline codec. We let the Spring bean with ID, <tt>myTCPOrderHandler</tt>, handle the request and return a reply. For instance, the handler bean could be implemented as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> <span class="code-object">String</span> handleOrder(<span class="code-object">String</span> payload) {
        ...
        <span class="code-keyword">return</span> <span class="code-quote">"Order: OK"</span>
   }
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfiguringMinaendpointsusingSpringbeanstyle"></a>Configuring Mina endpoints using Spring bean style</h3>
<p><b>Available as of Camel 2.0</b></p>

<p>Configuration of Mina endpoints is now possible using regular Spring bean style configuration in the Spring DSL.</p>

<p>However, in the underlying Apache Mina toolkit, it is relatively difficult to set up the acceptor and the connector, because you can <em>not</em> use simple setters. To resolve this difficulty, we leverage the <tt>MinaComponent</tt> as a Spring factory bean to configure this for us. If you really need to configure this yourself, there are setters on the <tt>MinaEndpoint</tt> to set these when needed.</p>

<p>The sample below shows the factory approach:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
     as a factory bean to create our endpoint, this is the easiest to do --&gt;
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaFactory"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaComponent"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- we must provide a camel context so we refer to it by its id --&gt;</span></span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myCamel"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

&lt;!-- This is our mina endpoint configured with spring, we will use the factory above
     to create it for us. The goal is to invoke the createEndpoint method with the
     mina configuration parameter we defined using the constructor-arg option --&gt;
&lt;bean id=<span class="code-quote">"myMinaEndpoint"</span>
      factory-bean=<span class="code-quote">"myMinaFactory"</span>
      factory-method=<span class="code-quote">"createEndpoint"</span>&gt;
    <span class="code-tag"><span class="code-comment">&lt;!-- and here we can pass it our configuration --&gt;</span></span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myMinaConfig"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- this is our mina configuration with plain properties --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaConfig"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaConfiguration"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"protocol"</span> value=<span class="code-quote">"tcp"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"host"</span> value=<span class="code-quote">"localhost"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"port"</span> value=<span class="code-quote">"1234"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sync"</span> value=<span class="code-quote">"false"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>And then we can refer to our endpoint directly in the route, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- here we route from or mina endpoint we have defined above --&gt;</span></span>
    <span class="code-tag">&lt;from ref=<span class="code-quote">"myMinaEndpoint"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ClosingSessionWhenComplete"></a>Closing Session When Complete</h3>
<p><b>Available as of Camel 1.6.1</b></p>

<p>When acting as a server you sometimes want to close the session when, for example, a client conversion is finished. To instruct Camel to close the session, you should add a header with the key <tt>CamelMinaCloseSessionWhenComplete</tt> set to a boolean <tt>true</tt> value.</p>

<p>For instance, the example below will close the session after it has written the <tt>bye</tt> message back to the client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:8080?sync=<span class="code-keyword">true</span>&amp;textline=<span class="code-keyword">true</span>"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
                exchange.getOut().setBody(<span class="code-quote">"Bye "</span> + body);
                exchange.getOut().setHeader(MinaConsumer.HEADER_CLOSE_SESSION_WHEN_COMPLETE, <span class="code-keyword">true</span>);
            }
        });
</pre>
</div></div>

<h3><a name="BookComponentAppendix-GettheIoSessionformessage"></a>Get the IoSession for message</h3>
<p><b>Available since Camel 2.1</b><br/>
You can get the IoSession from the message header with this key MinaEndpoint.HEADER_MINA_IOSESSION, and also get the local host address with the key MinaEndpoint.HEADER_LOCAL_ADDRESS and remote host address with the key MinaEndpoint.HEADER_REMOTE_ADDRESS.</p>

<h3><a name="BookComponentAppendix-ConfiguringMinafilters"></a>Configuring Mina filters</h3>
<p><b>Available since Camel 2.0</b></p>

<p>Filters permit you to use some Mina Filters, such as <tt>SslFilter</tt>. You can also implement some customized filters. Please note that <tt>codec</tt> and <tt>logger</tt> are also implemented as Mina filters of type, <tt>IoFilter</tt>. Any filters you may define are appended to the end of the filter chain; that is, after <tt>codec</tt> and <tt>logger</tt>.</p>

<p>For instance, the example below will send a keep-alive message after 10 seconds of inactivity:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class KeepAliveFilter <span class="code-keyword">extends</span> IoFilterAdapter {
    @Override
    <span class="code-keyword">public</span> void sessionCreated(NextFilter nextFilter, IoSession session)
            <span class="code-keyword">throws</span> Exception {
        session.setIdleTime(IdleStatus.BOTH_IDLE, 10);

        nextFilter.sessionCreated(session);
    }

    @Override
    <span class="code-keyword">public</span> void sessionIdle(NextFilter nextFilter, IoSession session,
            IdleStatus status) <span class="code-keyword">throws</span> Exception {
        session.write(<span class="code-quote">"NOOP"</span>); <span class="code-comment">// NOOP is a FTP command <span class="code-keyword">for</span> keep alive
</span>        nextFilter.sessionIdle(session, status);
    }
}
</pre>
</div></div>

<p>As Camel Mina may use a request-reply scheme, the endpoint as a client would like to drop some message, such as greeting when the connection is established. For example, when you connect to an FTP server, you will get a <tt>220</tt> message with a greeting (<tt>220 Welcome to Pure-FTPd</tt>). If you don't drop the message, your request-reply scheme will be broken.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class DropGreetingFilter <span class="code-keyword">extends</span> IoFilterAdapter {
 
    @Override
    <span class="code-keyword">public</span> void messageReceived(NextFilter nextFilter, IoSession session,
            <span class="code-object">Object</span> message) <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">if</span> (message <span class="code-keyword">instanceof</span> <span class="code-object">String</span>) {
            <span class="code-object">String</span> ftpMessage = (<span class="code-object">String</span>) message;
            <span class="code-comment">// <span class="code-quote">"220"</span> is given as greeting. <span class="code-quote">"200 Zzz"</span> is given as a response to <span class="code-quote">"NOOP"</span> (keep alive)
</span>            <span class="code-keyword">if</span> (ftpMessage.startsWith(<span class="code-quote">"220"</span>) || or ftpMessage.startsWith(<span class="code-quote">"200 Zzz"</span>)) {
                <span class="code-comment">// Dropping greeting
</span>                <span class="code-keyword">return</span>;
            }
        }
        nextFilter.messageReceived(session, message);
    }
}
</pre>
</div></div>

<p>Then, you can configure your endpoint using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaFactory"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaComponent"</span>&gt;</span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"camelContext"</span> /&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
    
&lt;bean id=<span class="code-quote">"myMinaEndpoint"</span>
      factory-bean=<span class="code-quote">"myMinaFactory"</span>
      factory-method=<span class="code-quote">"createEndpoint"</span>&gt;
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myMinaConfig"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaConfig"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaConfiguration"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"protocol"</span> value=<span class="code-quote">"tcp"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"host"</span> value=<span class="code-quote">"localhost"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"port"</span> value=<span class="code-quote">"2121"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sync"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"minaLogger"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"filters"</span> ref=<span class="code-quote">"listFilters"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"listFilters"</span> class=<span class="code-quote">"java.util.ArrayList"</span> &gt;</span>
    <span class="code-tag">&lt;constructor-arg&gt;</span>
        <span class="code-tag">&lt;list value-type=<span class="code-quote">"org.apache.mina.common.IoFilter"</span>&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"com.example.KeepAliveFilter"</span>/&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"com.example.DropGreetingFilter"</span>/&gt;</span>
        <span class="code-tag">&lt;/list&gt;</span>
    <span class="code-tag">&lt;/constructor-arg&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-MockComponent"></a>Mock Component</h2>

<a href="/confluence/display/CAMEL/Testing" title="Testing">Testing</a> of distributed and asynchronous processing is notoriously difficult. The <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a>, <a href="/confluence/display/CAMEL/Test" title="Test">Test</a> and <a href="/confluence/display/CAMEL/DataSet" title="DataSet">DataSet</a> endpoints work great with the <a href="/confluence/display/CAMEL/Testing" title="Testing">Camel Testing Framework</a> to simplify your unit and integration testing using <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise Integration Patterns">Enterprise Integration Patterns</a> and Camel's large range of <a href="/confluence/display/CAMEL/Components" title="Components">Components</a> together with the powerful <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a>.

<p>The Mock component provides a powerful declarative testing mechanism, which is similar to <a href="http://jmock.org" rel="nofollow">jMock</a> in that it allows declarative expectations to be created on any Mock endpoint before a test begins. Then the test is run, which typically fires messages to one or more endpoints, and finally the expectations can be asserted in a test case to ensure the system  worked as expected. </p>

<p>This allows you to test various things like:</p>
<ul>
	<li>The correct number of messages are received on each endpoint,</li>
	<li>The correct payloads are received, in the right order,</li>
	<li>Messages arrive on an endpoint in order, using some <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to create an order testing function,</li>
	<li>Messages arrive match some kind of <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> such as that specific headers have certain values, or that parts of the messages match some predicate, such as by evaluating an <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a> or <a href="/confluence/display/CAMEL/XQuery" title="XQuery">XQuery</a> <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>.</li>
</ul>


<p><b>Note</b> that there is also the <a href="/confluence/display/CAMEL/Test" title="Test">Test endpoint</a> which is a Mock endpoint, but which uses a second endpoint to provide the list of expected message bodies and automatically sets up the Mock endpoint assertions. In other words, it's a Mock endpoint that automatically sets up its assertions from some sample messages in a <a href="/confluence/display/CAMEL/File" title="File">File</a> or <a href="/confluence/display/CAMEL/JPA" title="JPA">database</a>, for example.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mock:someName[?options]
</pre>
</div></div>

<p>Where <b>someName</b> can be any string that uniquely identifies the endpoint.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>reportGroup</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A size to use a <a href="/confluence/display/CAMEL/Log" title="Log">throughput logger</a> for reporting </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-SimpleExample"></a>Simple Example</h3>

<p>Here's a simple example of Mock endpoint in use. First, the endpoint is resolved on the context. Then we set an expectation, and then, after the test has run, we assert that our expectations have been met.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
MockEndpoint resultEndpoint = context.resolveEndpoint(<span class="code-quote">"mock:foo"</span>, MockEndpoint.class);

resultEndpoint.expectedMessageCount(2);

<span class="code-comment">// send some messages
</span>...

<span class="code-comment">// now lets <span class="code-keyword">assert</span> that the mock:foo endpoint received 2 messages
</span>resultEndpoint.assertIsSatisfied();
</pre>
</div></div>

<p>You typically always call the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#assertIsSatisfied()" rel="nofollow">assertIsSatisfied() method</a> to test that the expectations were met after running a test.</p>

<p>Camel will by default wait 20 seconds when the <tt>assertIsSatisfied()</tt> is invoked. This can be configured by setting the <tt>setResultWaitTime(millis)</tt> method.</p>

<h3><a name="BookComponentAppendix-Settingexpectations"></a>Setting expectations</h3>

<p>You can see from the javadoc of <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html" rel="nofollow">MockEndpoint</a> the various helper methods you can use to set expectations. The main methods are as follows: </p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Method </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedMessageCount(int)" rel="nofollow">expectedMessageCount(int)</a> </td>
<td class='confluenceTd'> To define the expected message count on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedMinimumMessageCount(int)" rel="nofollow">expectedMinimumMessageCount(int)</a> </td>
<td class='confluenceTd'> To define the minimum number of expected messages on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedBodiesReceived(java.lang.Object...)" rel="nofollow">expectedBodiesReceived(...)</a> </td>
<td class='confluenceTd'> To define the expected bodies that should be received (in order). </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedHeaderReceived(java.lang.String,%20java.lang.String)" rel="nofollow">expectedHeaderReceived(...)</a> </td>
<td class='confluenceTd'> To define the expected header that should be received </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsAscending(org.apache.camel.Expression)" rel="nofollow">expectsAscending(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that messages are received in order, using the given <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to compare messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsDescending(org.apache.camel.Expression)" rel="nofollow">expectsDescending(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that messages are received in order, using the given <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to compare messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsNoDuplicates(org.apache.camel.Expression)" rel="nofollow">expectsNoDuplicates(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that no duplicate messages are received; using an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to calculate a unique identifier for each message. This could be something like the <tt>JMSMessageID</tt> if using JMS, or some unique reference number within the message. </td>
</tr>
</tbody></table>

<p>Here's another example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
resultEndpoint.expectedBodiesReceived(<span class="code-quote">"firstMessageBody"</span>, <span class="code-quote">"secondMessageBody"</span>, <span class="code-quote">"thirdMessageBody"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Addingexpectationstospecificmessages"></a>Adding expectations to specific messages</h4>

<p>In addition, you can use the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#message(int)" rel="nofollow">message(int messageIndex)</a> method to add assertions about a specific message that is received.</p>

<p>For example, to add expectations of the headers or body of the first message (using zero-based indexing like <tt>java.util.List</tt>), you can use the following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
resultEndpoint.message(0).header(<span class="code-quote">"foo"</span>).isEqualTo(<span class="code-quote">"bar"</span>);
</pre>
</div></div>

<p>There are some examples of the Mock endpoint in use in the <a href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/" rel="nofollow">camel-core processor tests</a>.</p>

<h3><a name="BookComponentAppendix-ASpringExample"></a>A Spring Example</h3>

<p>First, here's the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml" rel="nofollow">spring.xml file</a></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"file:src/test/data?noop=true"</span>/&gt;</span>
    <span class="code-tag">&lt;filter&gt;</span>
      <span class="code-tag">&lt;xpath&gt;</span>/person/city = 'London'<span class="code-tag">&lt;/xpath&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:matched"</span>/&gt;</span>
    <span class="code-tag">&lt;/filter&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myBean"</span> class=<span class="code-quote">"org.apache.camel.spring.mock.MyAssertions"</span> scope=<span class="code-quote">"singleton"</span>/&gt;</span>
</pre>
</div></div>

<p>As you can see, it defines a simple routing rule which consumes messages from the local <a href="http://svn.apache.org/repos/asf/acamel/trunk/components/camel-spring/src/test/data/" rel="nofollow">src/test/data directory</a>. The <b>noop</b> flag just means not to delete or move the file after its been processed.</p>

<p>Also note we instantiate a bean called <b>myBean</b>, here is the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java" rel="nofollow">source of the MyAssertions bean</a>. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyAssertions <span class="code-keyword">implements</span> InitializingBean {
    @EndpointInject(uri = <span class="code-quote">"mock:matched"</span>)
    <span class="code-keyword">private</span> MockEndpoint matched;

    @EndpointInject(uri = <span class="code-quote">"mock:notMatched"</span>)
    <span class="code-keyword">private</span> MockEndpoint notMatched;

    <span class="code-keyword">public</span> void afterPropertiesSet() <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// lets add some expectations
</span>        matched.expectedMessageCount(1);
        notMatched.expectedMessageCount(0);
    }

    <span class="code-keyword">public</span> void assertEndpointsValid() <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// now lets perform some assertions that the test worked as we expect
</span>        Assert.assertNotNull(<span class="code-quote">"Should have a matched endpoint"</span>, matched);
        Assert.assertNotNull(<span class="code-quote">"Should have a notMatched endpoint"</span>, notMatched);
        MockEndpoint.assertIsSatisfied(matched, notMatched);
    }
}
</pre>
</div></div>

<p>The bean is injected with a bunch of Mock endpoints using the <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">@EndpointInject annotation</a>, it then sets a bunch of expectations on startup (using Spring's <tt>InitializingBean</tt> interface and <tt>afterPropertiesSet()</tt> method) before the <tt>CamelContext</tt> starts up. </p>

<p>Then in our test case (which could be JUnit or TesNG) we lookup <b>myBean</b> in Spring (or have it injected into our test) and then invoke the <tt>assertEndpointsValid()</tt> method on it to verify that the mock endpoints have their assertions met. You could then inspect the message exchanges that were delivered to any of the endpoints using the <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#getReceivedExchanges()" rel="nofollow">getReceivedExchanges()</a> method on the Mock endpoint and perform further assertions or debug logging.</p>

<p>Here is the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java" rel="nofollow">actual JUnit test case we use</a>.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Spring+Testing" title="Spring Testing">Spring Testing</a></li>
</ul>

<h2><a name="BookComponentAppendix-MSVComponent"></a>MSV Component</h2>

<p>The MSV component performs XML validation of the message body using the <a href="https://msv.dev.java.net/" rel="nofollow">MSV Library</a> and any of the supported XML schema languages, such as <a href="http://www.w3.org/XML/Schema" rel="nofollow">XML Schema</a> or <a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a>. </p>

<p>Note that the <a href="/confluence/display/CAMEL/Jing" title="Jing">Jing</a> component also supports <a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG Compact Syntax</a></p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
msv:someLocalOrRemoteResource[?options]
</pre>
</div></div>

<p>Where <b>someLocalOrRemoteResource</b> is some URL to a local resource on the classpath or a full URL to a remote resource or resource on the file system. For example</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
msv:org/foo/bar.rng
msv:file:../foo/bar.rng
msv:http:<span class="code-comment">//acme.com/cheese.rng</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>useDom</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether DOMSource/DOMResult or SaxSource/SaxResult should be used by the validator. <b>Note:</b> DOM must be used by the <a href="/confluence/display/CAMEL/MSV" title="MSV">MSV</a> component. </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-Example"></a>Example</h3>

<p>The following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml" rel="nofollow">example</a> shows how to configure a route from endpoint <b>direct:start</b> which then goes to one of two endpoints, either <b>mock:valid</b> or <b>mock:invalid</b> based on whether or not the XML matches the given <a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Schema</a> (which is supplied on the classpath).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;doTry&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"msv:org/apache/camel/component/validator/msv/schema.rng"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:valid"</span>/&gt;</span>

            <span class="code-tag">&lt;doCatch&gt;</span>
                <span class="code-tag">&lt;exception&gt;</span>org.apache.camel.ValidationException<span class="code-tag">&lt;/exception&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:invalid"</span>/&gt;</span>
            <span class="code-tag">&lt;/doCatch&gt;</span>
            <span class="code-tag">&lt;doFinally&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:finally"</span>/&gt;</span>
            <span class="code-tag">&lt;/doFinally&gt;</span>
        <span class="code-tag">&lt;/doTry&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-Nagios"></a>Nagios</h2>
<p><b>Available as of Camel 2.2</b></p>

<p>The <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component allows you to send passive checks to <a href="http://nagios.org" rel="nofollow">Nagios</a>.</p>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
nagios:<span class="code-comment">//host[:port][?Options]</span>
</pre>
</div></div>

<p>Camel provides two abilities with the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component. You can send passive check messages by sending a message to its endpoint.<br/>
Camel also provides a <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">EventNotifer</a> which allows you to send notifications to Nagios.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>host</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> This is the address of the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> host where checks should be send. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>port</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The port number of the host. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Password to be authenticated when sending checks to Nagios. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> 5000 </td>
<td class='confluenceTd'> Connection timeout in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> 5000 </td>
<td class='confluenceTd'> Sending timeout in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nagiosSettings</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To use an already configured <tt>com.googlecode.jsendnsca.core.NagiosSettings</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendSync</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether or not to use synchronous when sending a passive check. Setting it to <tt>false</tt> will allow Camel to continue routing the message and the passive check message will be send asynchronously. </td>
</tr>
</tbody></table></div>

<h3><a name="BookComponentAppendix-Headers"></a>Headers</h3>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosHostName</tt> </td>
<td class='confluenceTd'> This is the address of the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> host where checks should be send. This header will override any existing hostname configured on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosLevel</tt> </td>
<td class='confluenceTd'> This is the severity level. You can use values <tt>CRITICAL, WARNING, OK</tt>. Camel will by default use <tt>OK</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosServiceName</tt> </td>
<td class='confluenceTd'> The servie name. Will default use the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> name. </td>
</tr>
</tbody></table></div>


<h3><a name="BookComponentAppendix-Sendingmessageexamples"></a>Sending message examples</h3>
<p>You can send a message to Nagios where the message payload contains the message. By default it will be <tt>OK</tt> level and use the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> name as the service name. You can overrule these values using headers as shown above.</p>

<p>For example we send the <tt>Hello Nagios</tt> message to Nagios as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    template.sendBody(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Hello Nagios"</span>);

    from(<span class="code-quote">"direct:start"</span>).to(<span class="code-quote">"nagios:127.0.0.1:5667?password=secret"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>To send a <tt>CRITICAL</tt> message you can send the headers such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map headers = <span class="code-keyword">new</span> HashMap();
        headers.put(NagiosConstants.LEVEL, <span class="code-quote">"CRITICAL"</span>);
        headers.put(NagiosConstants.HOST_NAME, <span class="code-quote">"myHost"</span>);
        headers.put(NagiosConstants.SERVICE_NAME, <span class="code-quote">"myService"</span>);
        template.sendBodyAndHeaders(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Hello Nagios"</span>, headers);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Using%7B%7BNagiosEventNotifer%7D%7D"></a>Using <tt>NagiosEventNotifer</tt></h3>
<p>The <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component also provides an <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">EventNotifer</a> which you can use to send events to Nagios. For example we can enable this from Java as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        NagiosEventNotifier notifier = <span class="code-keyword">new</span> NagiosEventNotifier();
        notifier.getConfiguration().setHost(<span class="code-quote">"localhost"</span>);
        notifier.getConfiguration().setPort(5667);
        notifier.getConfiguration().setPassword(<span class="code-quote">"password"</span>);

        CamelContext context = ... 
        context.getManagementStrategy().addEventNotifier(notifier);
        <span class="code-keyword">return</span> context;
</pre>
</div></div>

<p>In Spring XML its just a matter of defining a Spring bean with the type <tt>EventNotifier</tt> and Camel will pick it up as documented here: <a href="/confluence/display/CAMEL/Advanced+configuration+of+CamelContext+using+Spring" title="Advanced configuration of CamelContext using Spring">Advanced configuration of CamelContext using Spring</a>.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-NMRComponent"></a>NMR Component</h2>

<p>The <b>nmr</b> component is an adapter to the Normalized Message Router (NMR) in <a href="http://servicemix.apache.org/home.html" rel="nofollow">ServiceMix</a>, which is intended for use by Camel applications deployed directly into the OSGi container. By contrast, the <a href="/confluence/display/CAMEL/JBI" title="JBI">JBI</a> component is intended for use by Camel applications deployed into the ServiceMix JBI container.</p>

<h3><a name="BookComponentAppendix-Installing"></a>Installing</h3>

<p>The NMR component is provided with Apache ServiceMix. It is <b>not</b> distributed with Camel. To install the NMR component in ServiceMix, enter the following command in the ServiceMix console window:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
features install nmr
</pre>
</div></div>

<p>You also need to instantiate the NMR component. You can do this by editing your Spring configuration file, <tt>META-INF/spring/*.xml</tt>, and adding the following <tt>bean</tt> instance:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;beans xmlns:osgi=<span class="code-quote">"http:<span class="code-comment">//www.springframework.org/schema/osgi"</span> ... &gt;
</span>    ...
    &lt;bean id=<span class="code-quote">"nmr"</span> class=<span class="code-quote">"org.apache.servicemix.camel.nmr.ServiceMixComponent"</span>&gt;
        &lt;property name=<span class="code-quote">"nmr"</span>&gt;
            &lt;osgi:reference <span class="code-keyword">interface</span>=<span class="code-quote">"org.apache.servicemix.nmr.api.NMR"</span> /&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
    ...
&lt;/beans&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-NMRconsumerandproducerendpoints"></a>NMR consumer and producer endpoints</h3>

<p>The following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"nmr:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>)</span>
</pre>
</div></div>

<p>Automatically exposes a new endpoint to the bus, where the service QName is {<tt><a href="http://foo.bar.org" rel="nofollow">http://foo.bar.org</a>}MyService</tt> and the endpoint name is <tt>MyEndpoint</tt> (see <a href="#BookComponentAppendix-URIformat">URI&#45;format</a>).</p>

<p>When an NMR endpoint appears at the end of a route, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
to(<span class="code-quote">"nmr:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>)</span>
</pre>
</div></div>

<p>The messages sent by this producer endpoint are sent to the already deployed JBI endpoint.</p>

<p><a name="BookComponentAppendix-URIformat"></a></p>
<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
nmr:service:serviceNamespace[sep]serviceName
nmr:endpoint:serviceNamespace[sep]serviceName[sep]endpointName
nmr:name:endpointName
</pre>
</div></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>, or</li>
	<li><tt>:</tt> (colon), if <tt>serviceNamespace</tt> starts with <tt>urn:foo:bar</tt>.</li>
</ul>


<p>For more details of valid NMR URIs see the <a href="http://servicemix.apache.org/uris.html" rel="nofollow">ServiceMix URI Guide</a>. </p>

<p>Using the <tt>nmr:service:</tt> or <tt>nmr:endpoint:</tt> URI formats sets the service QName on the JBI endpoint to the one specified. Otherwise, the default Camel JBI Service QName is used, which is:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
{http:<span class="code-comment">//activemq.apache.org/camel/schema/jbi}endpoint</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Examples"></a>Examples</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
nmr:service:http:<span class="code-comment">//foo.bar.org/MyService
</span>nmr:endpoint:urn:foo:bar:MyService:MyEndpoint
nmr:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint
</span>nmr:name:cheese
</pre>
</div></div>

<h3><a name="BookComponentAppendix-UsingStreambodies"></a>Using Stream bodies</h3>
<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="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jbi:endpoint:http:<span class="code-comment">//foo.bar.org/MyService/MyEndpoint"</span>).streamCaching().to(<span class="code-quote">"xslt:transform.xsl"</span>, <span class="code-quote">"bean:doSomething"</span>);</span>
</pre>
</div></div>

<p>From <b>Camel 1.5</b> onwards, the stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt> option.<br/>
In <b>Camel 2.0</b> we store big 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>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-QuartzComponent"></a>Quartz Component</h2>

<p>The <b>quartz:</b> component provides a scheduled delivery of messages using the <a href="http://www.opensymphony.com/quartz/" rel="nofollow">Quartz scheduler</a>. <br/>
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using cron expressions</b><br /><p>Configuring the cron expression in Camel 1.x is based on path separators. We changed this to an URI option in Camel 2.0, allowing a more elegant configuration.<br/>
Also it is <b>not</b> possible to use the <tt>/</tt> cron special character (for increments) in Camel 1.x, which Camel 2.0 also fixes.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
quartz:<span class="code-comment">//timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName/cronExpression       (@deprecated)
</span>quartz:<span class="code-comment">//groupName/timerName/?cron=expression     (Camel 2.0)
</span>quartz:<span class="code-comment">//timerName?cron=expression                (Camel 2.0)</span>
</pre>
</div></div>

<p>The component uses either a <tt>CronTrigger</tt> or a <tt>SimpleTrigger</tt>. If no cron expression is provided, the component uses a simple trigger. If no <tt>groupName</tt> is provided, the quartz component uses the <tt>Camel</tt> group name.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Parameter </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cron</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> Specifies a <tt>cron</tt> expression (not compatible with the <tt>trigger.&#42;</tt> or <tt>job.&#42;</tt> options). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatCount</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: How many times should the timer repeat? </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatInterval</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: The amount of time in milliseconds between repeated triggers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.name</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job option with the <tt><em>XXX</em></tt> setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the trigger option with the <tt><em>XXX</em></tt> setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>stateful</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Uses a Quartz <tt>StatefulJob</tt> instead of the default job. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fireNow</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> New to Camel 2.2.0, if it is true will fire the trigger when the route is start when using SimpleTrigger.</td>
</tr>
</tbody></table>

<p>For example, the following routing rule will fire two timer events to the <tt>mock:results</tt> endpoint:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">from(<span class="code-quote">"quartz://myGroup/myTimerName?trigger.repeatInterval=2&amp;trigger.repeatCount=1"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>When using a <a href="http://quartz.sourceforge.net/javadoc/org/quartz/StatefulJob.html" rel="nofollow">StatefulJob</a>, the <a href="http://quartz.sourceforge.net/javadoc/org/quartz/JobDataMap.html" rel="nofollow">JobDataMap</a> is re-persisted after every execution of the job, thus preserving state for the next execution.</p>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel adds the getters from the Quartz Execution Context as header values. The following headers are added:<br/>
<tt>calendar</tt>, <tt>fireTime</tt>, <tt>jobDetail</tt>, <tt>jobInstance</tt>, <tt>jobRuntTime</tt>, <tt>mergedJobDataMap</tt>, <tt>nextFireTime</tt>, <tt>previousFireTime</tt>, <tt>refireCount</tt>, <tt>result</tt>, <tt>scheduledFireTime</tt>, <tt>scheduler</tt>, <tt>trigger</tt>, <tt>triggerName</tt>, <tt>triggerGroup</tt>.</p>

<p>The <tt>fireTime</tt> header contains the <tt>java.util.Date</tt> of when the exchange was fired.</p>

<h3><a name="BookComponentAppendix-UsingCronTriggers"></a>Using Cron Triggers</h3>
<p><b>Avaiable as of Camel 2.0</b><br/>
Quartz supports <a href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html" rel="nofollow">Cron-like expressions</a> for specifying timers in a handy format. You can use these expressions in the <tt>cron</tt> URI parameter; though to preserve valid URI encoding we allow + to be used instead of spaces. Quartz provides a <a href="http://www.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.html" rel="nofollow">little tutorial</a> on how to use cron expressions.</p>

<p>For example the following will fire a message at 12pm (noon) every day</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"quartz:<span class="code-comment">//myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI"</span>).to(<span class="code-quote">"activemq:Totally.Rocks"</span>);</span>
</pre>
</div></div>

<p>which is equivalent to using the cron expression</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
0 0/5 12-18 ? * MON-FRI
</pre>
</div></div>

<p>The following table shows the URI character encodings we use to preserve valid URI syntax:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>URI Character</th>
<th class='confluenceTh'>Cron character</th>
</tr>
<tr>
<td class='confluenceTd'> <tt>&#43;</tt> </td>
<td class='confluenceTd'> <em>Space</em> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-UsingCronTriggersinCamel1.x"></a>Using Cron Triggers in Camel 1.x</h3>
<p><b>@deprecated</b><br/>
Quartz supports <a href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html" rel="nofollow">Cron-like expressions</a> for specifying timers in a handy format. You can use these expressions in the URI; though to preserve valid URI encoding we allow <tt>/</tt> to be used instead of spaces and <tt>$</tt> to be used instead of <tt>?</tt>.</p>

<p>For example, the following endpoint URI will fire a message at 12pm (noon) every day</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
from(<span class="code-quote">"quartz://myGroup/myTimerName/0/0/12/*/*/$"</span>).to(<span class="code-quote">"activemq:Totally.Rocks"</span>);
</pre>
</div></div>

<p>which is equivalent to using the cron expression</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
0 0 12 * * ?
</pre>
</div></div>

<p>The following table shows the URI character encodings we use to preserve valid URI syntax:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>URI Character</th>
<th class='confluenceTh'>Cron character</th>
</tr>
<tr>
<td class='confluenceTd'> <tt>/</tt> </td>
<td class='confluenceTd'> <em>Space</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>$</tt> </td>
<td class='confluenceTd'> <tt>?</tt> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a></li>
</ul>


<h2><a name="BookComponentAppendix-QuickfixComponent"></a>Quickfix Component</h2>
<p><b>Available as of Camel 2.0</b></p>

<p>The <b>quickfix</b> component is an implementation of the <a href="http://www.quickfixj.org/" rel="nofollow">QuickFix</a> engine for Java . This engine allows to connect to a FIX server which is used to exchange financial messages according to <a href="http://www.fixprotocol.org/" rel="nofollow">FIX protocol</a> standard.  </p>

<p><b>Note:</b> The component can be used to send/receives messages to a FIX server.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
quickfix-server:config file
quickfix-client:config file
</pre>
</div></div>

<p>Where <b>config file</b> is the location (in your classpath) of the quickfix configuration file used to configure the engine at the startup.</p>

<p><b>Note:</b> Information about parameters available for quickfix can be found on <a href="http://www.quickfixj.org/quickfixj/usermanual/usage/configuration.html" rel="nofollow">QuickFixJ</a> web site.</p>

<p>The quickfix-server endpoint must be used to receive from FIX server FIX messages and quickfix-client endpoint in the case that you want to send messages to a FIX gateway.</p>

<p><b>Warning:</b> You cannot use a quickfix engine to send or receive messages in both direction as the FIX protocol handle logon/logout sessions with heartbeat messages which are send to verify if the server or client is still alive in only one direction.</p>

<h3><a name="BookComponentAppendix-Exchangedataformat"></a>Exchange data format</h3>

<p>The QuickFixJ engine is like CXF component a messaging bus using MINA as protocol layer to create the socket connection with the FIX engine gateway. </p>

<p>When QuickFixJ engine receives a message, then it create a QuickFix.Message instance which is next received by the camel endpoint. This object is a 'mapping object' created from a FIX message formatted initially as a collection of key value pairs data. You can use this object or you can use the method 'toString' to retrieve the original FIX message. </p>

<p><b>Note:</b> Alternatively, you can use <a href="/confluence/display/CAMEL/Bindy" title="Bindy">camel bindy dataformat</a> to transform the FIX message into your own java POJO</p>

<p>When a message must be send to QuickFix, then you must create a QuickFix.Message instance.</p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>Direction : to FIX gateway</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;route&gt;
&lt;from uri=<span class="code-quote">"activemq:queue:fix"</span>/&gt;
&lt;bean ref=<span class="code-quote">"fixService"</span> method=<span class="code-quote">"createFixMessage"</span> /&gt; <span class="code-comment">// bean method in charge to transform message into a QuickFix.Message
</span>&lt;to uri=<span class="code-quote">"quickfix-client:META-INF/quickfix/client.cfg"</span> /&gt; <span class="code-comment">// Quickfix engine who will send the FIX messages to the gateway</span>
</pre>
</div></div>

<p>Direction : from FIX gateway</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;from uri=<span class="code-quote">"quickfix-server:META-INF/quickfix/server.cfg"</span>/&gt; <span class="code-comment">// QuickFix engine who will receive the message from FIX gateway
</span>&lt;bean ref=<span class="code-quote">"fixService"</span> method=<span class="code-quote">"parseFixMessage"</span> /&gt; <span class="code-comment">// bean method parsing the QuickFix.Message
</span>&lt;to uri=<span class="code-quote">"uri="</span>activemq:queue:fix<span class="code-quote">"/&gt;"</span> /&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>





<h2><a name="BookComponentAppendix-PrinterComponent"></a>Printer Component</h2>

<p><b>Available as of Camel 2.1</b></p>

<p>The <b>printer</b> component provides a way to direct payloads on a route to a printer. Obviously the payload has to be a formatted piece of payload in order for the component to appropriately print it. The objective is to be able to direct specific payloads as jobs to a line printer in a camel flow.</p>

<p>This component only supports a camel producer endpoint.</p>

<p>The functionality allows for the payload to be printed on a default printer, named local, remote or wirelessly linked printer using the javax printing API under the covers.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<p>Since the URI scheme for a printer has not been standardized (the nearest thing to a standard being the IETF print standard) and therefore not uniformly applied by vendors, we have chosen <b>"lpr"</b> as the scheme.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
lpr:<span class="code-comment">//localhost/<span class="code-keyword">default</span>[?options]
</span>lpr:<span class="code-comment">//remotehost:port/path/to/printer[?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>mediaSize</tt> </td>
<td class='confluenceTd'> <tt>MediaSizeName.NA_LETTER</tt> </td>
<td class='confluenceTd'> Sets the stationary as defined by enumeration settings in the javax.print.attribute.standard.MediaSizeName API. The default setting is to use North American Letter sized stationary </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>copies</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Sets number of copies based on the javax.print.attribute.standard.Copies API </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sides</tt> </td>
<td class='confluenceTd'> <tt>Sides.ONE_SIDED</tt> </td>
<td class='confluenceTd'> Sets one sided or two sided printing based on the javax.print.attribute.standard.Sides API </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flavor</tt> </td>
<td class='confluenceTd'> <tt>DocFlavor.BYTE_ARRAY</tt> </td>
<td class='confluenceTd'> Sets DocFlavor based on the javax.print.DocFlavor API </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mimeType</tt> </td>
<td class='confluenceTd'> <tt>AUTOSENSE</tt> </td>
<td class='confluenceTd'> Sets mimeTypes supported by the javax.print.DocFlavor API </td>
</tr>
</tbody></table>


<h3><a name="BookComponentAppendix-SendingMessagestoaPrinter"></a>Sending Messages to a Printer</h3>

<h4><a name="BookComponentAppendix-PrinterProducer"></a>Printer Producer </h4>
<p>Sending data to the printer is very straightforward and involves creating a producer endpoint that can be sent message exchanges on in route.</p>

<h3><a name="BookComponentAppendix-UsageSamples"></a>Usage Samples</h3>

<h4><a name="BookComponentAppendix-Example1%3APrintingtextbasedpayloadsonaDefaultprinterusingletterstationaryandonesidedmode"></a>Example 1: Printing text based payloads on a Default printer using letter stationary and one-sided mode</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(file:<span class="code-comment">//inputdir/?delete=<span class="code-keyword">true</span>)
</span>       .to(<span class="code-quote">"lpr:<span class="code-comment">//localhost/<span class="code-keyword">default</span>?copies=2"</span> +
</span>           <span class="code-quote">"&amp;flavor=DocFlavor.INPUT_STREAM&amp;"</span> +
           <span class="code-quote">"&amp;mimeType=AUTOSENSE"</span> +
           <span class="code-quote">"&amp;mediaSize=na-letter"</span> +
           <span class="code-quote">"&amp;sides=one-sided"</span>)
    }};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3APrintingGIFbasedpayloadsonaRemoteprinterusingA4stationaryandonesidedmode"></a>Example 2: Printing GIF based payloads on a Remote printer using A4 stationary and one-sided mode</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(file:<span class="code-comment">//inputdir/?delete=<span class="code-keyword">true</span>)
</span>       .to(<span class="code-quote">"lpr:<span class="code-comment">//remotehost/sales/salesprinter"</span> +
</span>           <span class="code-quote">"?copies=2&amp;sides=one-sided"</span> +
           <span class="code-quote">"&amp;mimeType=GIF&amp;mediaSize=iso-a4"</span> +
           <span class="code-quote">"&amp;flavor=DocFlavor.INPUT_STREAM"</span>)
   }};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example3%3APrintingJPEGbasedpayloadsonaRemoteprinterusingJapanesePostcardstationaryandonesidedmode"></a>Example 3: Printing JPEG based payloads on a Remote printer using Japanese Postcard stationary and one-sided mode</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(file:<span class="code-comment">//inputdir/?delete=<span class="code-keyword">true</span>)
</span>       .to(<span class="code-quote">"lpr:<span class="code-comment">//remotehost/sales/salesprinter"</span> +
</span>           <span class="code-quote">"?copies=2&amp;sides=one-sided"</span> +
           <span class="code-quote">"&amp;mimeType=JPEG"</span> +
           <span class="code-quote">"&amp;mediaSize=japanese-postcard"</span> +
           <span class="code-quote">"&amp;flavor=DocFlavor.INPUT_STREAM"</span>)
    }};
</pre>
</div></div>
<h2><a name="BookComponentAppendix-RefComponent"></a>Ref Component</h2>

<p>The <b>ref:</b> component is used for lookup of existing endpoints bound in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ref:someName
</pre>
</div></div>

<p>Where <b>someName</b> is the name of an endpoint in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> (usually, but not always, the Spring registry). If you are using the Spring registry, <tt>someName</tt> would be the bean ID of an endpoint in the Spring registry.</p>

<h3><a name="BookComponentAppendix-Runtimelookup"></a>Runtime lookup</h3>
<p>This component can be used when you need dynamic discovery of endpoints in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> where you can compute the URI at runtime. Then you can look up the endpoint using the following code:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   <span class="code-comment">// lookup the endpoint
</span>   <span class="code-object">String</span> myEndpointRef = <span class="code-quote">"bigspenderOrder"</span>;
   Endpoint endpoint = context.getEndpoint(<span class="code-quote">"ref:"</span> + myEndpointRef);
   
   Producer producer = endpoint.createProducer();
   Exchange exchange = producer.createExchange();
   exchange.getIn().setBody(payloadToSend);
   <span class="code-comment">// send the exchange
</span>   producer.process(exchange);
   ...
</pre>
</div></div>

<p>And you could have a list of endpoints defined in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> such as:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://activemq.apache.org/camel/schema/spring"</span>&gt;</span>
      <span class="code-tag">&lt;endpoint id=<span class="code-quote">"normalOrder"</span> uri=<span class="code-quote">"activemq:order.slow"</span>/&gt;</span>
      <span class="code-tag">&lt;endpoint id=<span class="code-quote">"bigspenderOrder"</span> uri=<span class="code-quote">"activemq:order.high"</span>/&gt;</span>
      ...
  <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In the sample below we use the <tt>ref:</tt> in the URI to reference the endpoint with the spring ID, <tt>endpoint2</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"mybean"</span> class=<span class="code-quote">"org.apache.camel.spring.example.DummyBean"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"endpoint"</span> ref=<span class="code-quote">"endpoint1"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;endpoint id=<span class="code-quote">"endpoint1"</span> uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
  <span class="code-tag">&lt;endpoint id=<span class="code-quote">"endpoint2"</span> uri=<span class="code-quote">"mock:end"</span>/&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from ref=<span class="code-quote">"endpoint1"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"ref:endpoint2"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>You could, of course, have used the <tt>ref</tt> attribute instead:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
      <span class="code-tag">&lt;to ref=<span class="code-quote">"endpoint2"</span>/&gt;</span>
</pre>
</div></div>

<p>Which is the more common way to write it. </p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-RestletComponent"></a>Restlet Component</h2>

<p>The <b>Restlet</b> component provides <a href="http://www.restlet.org" rel="nofollow">Restlet</a> based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming and producing RESTful resources.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
restlet:restletUrl[?options]
</pre>
</div></div>
<p>Format of restletUrl:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
protocol:<span class="code-comment">//hostname[:port][/resourcePattern]</span>
</pre>
</div></div>
<p>Restlet promotes decoupling of protocol and application concerns.  The reference implementation of <a href="http://www.noelios.com/products/restlet-engine" rel="nofollow">Restlet Engine</a> supports a number of protocols.  However, we have tested the HTTP protocol only.  The default port is port 80.  We do not automatically switch default port based on the protocol yet.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy=#</tt><em>refName</em> (<b>2.x or later</b>) </td>
<td class='confluenceTd'> An instance of <tt>RestletHeaderFilterStrategy</tt> </td>
<td class='confluenceTd'> Use the <tt>#</tt> notation (<tt>headerFilterStrategy=#</tt><em>refName</em>) to reference a header filter strategy in the Camel Registry.  The strategy will be plugged into the restlet binding if it is <tt>HeaderFilterStrategyAware</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>restletBindingRef</tt> (<b>1.x</b>), <br clear="all" />
<tt>restletBinding=#</tt><em>refName</em> (<b>2.x or later</b>) </td>
<td class='confluenceTd'> An instance of <tt>DefaultRestletBinding</tt> </td>
<td class='confluenceTd'> The bean ID of a <tt>RestletBinding</tt> object in the Camel Registry. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>restletMethod</tt> </td>
<td class='confluenceTd'> <tt>GET</tt> </td>
<td class='confluenceTd'> On a producer endpoint, specifies the request method to use.  On a consumer endpoint, specifies that the endpoint consumes only <tt>restletMethod</tt> requests.  The string value is converted to <a href="http://www.restlet.org/documentation/1.1/api/org/restlet/data/Method.html" rel="nofollow">org.restlet.data.Method</a> by the <tt>Method.valueOf(String)</tt> method. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>restletMethods</tt> (<b>2.x or later</b>) </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> <b>Consumer only</b>  Specify one or more methods separated by commas (e.g. <tt>restletMethods=post,put</tt>) to be serviced by a restlet consumer endpoint.  If both <tt>restletMethod</tt> and <tt>restletMethods</tt> options are specified, the <tt>restletMethod</tt> setting is ignored. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>restletRealmRef</tt> (<b>1.x</b>), <br clear="all" />
<tt>restletRealm=#</tt><em>refName</em> <b>(2.x or later)</b> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The bean ID of the Realm Map in the Camel Registry. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>restletUriPatterns=#</tt><em>refName</em> (<b>2.x or later</b>) </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> <b>Consumer only</b>  Specify one ore more URI templates to be serviced by a restlet consumer endpoint, using the <tt>#</tt> notation to reference a <tt>List&lt;String&gt;</tt> in the Camel Registry.  If a URI pattern has been defined in the endpoint URI, both the URI pattern defined in the endpoint and the <tt>restletUriPatterns</tt> option will be honored. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>


<h4><a name="BookComponentAppendix-Camel1.x"></a>Camel 1.x</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.restlet.auth.login</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Login name for basic authentication.  It is set on the IN message by the application and gets filtered before the restlet request header by Camel. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.restlet.auth.password</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Password name for basic authentication.  It is set on the IN message by the application and gets filtered before the restlet request header by Camel. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.restlet.mediaType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Specifies the content type, which can be set on the OUT message by the application/processor.  The value is the <tt>content-type</tt> of the response message.  If this header is not set, the <tt>content-type</tt> is set based on the object type of the OUT message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.restlet.queryString</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The query string of the request URI.  It is set on the IN message by <tt>DefaultRestletBinding</tt> when the restlet component receives a request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.restlet.responseCode</tt> </td>
<td class='confluenceTd'> <tt>String</tt> or <tt>Integer</tt> </td>
<td class='confluenceTd'> The response code can be set on the OUT message by the application/processor.  The value is the response code of the response message.  If this header is not set, the response code is set by the restlet runtime engine. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.restlet.&#42;</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Attributes of a restlet message that get propagated to Camel IN headers. </td>
</tr>
</tbody></table>

<h4><a name="BookComponentAppendix-Camel2.0"></a>Camel 2.0</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelContentType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Specifies the content type, which can be set on the OUT message by the application/processor.  The value is the <tt>content-type</tt> of the response message.  If this header is not set, the <tt>content-type</tt> is based on the object type of the OUT message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpMethod</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The HTTP request method.  This is set in the IN message header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpQuery</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The query string of the request URI.  It is set on the IN message by <tt>DefaultRestletBinding</tt> when the restlet component receives a request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpRsponseCode</tt> </td>
<td class='confluenceTd'> <tt>String</tt> or <tt>Integer</tt> </td>
<td class='confluenceTd'> The response code can be set on the OUT message by the application/processor.  The value is the response code of the response message.  If this header is not set, the response code is set by the restlet runtime engine. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpUri</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The HTTP request URI.  This is set in the IN message header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelRestletLogin</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Login name for basic authentication.  It is set on the IN message by the application and gets filtered before the restlet request header by Camel. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelRestletPassword</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Password name for basic authentication.  It is set on the IN message by the application and gets filtered before the restlet request header by Camel. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.restlet.&#42;</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Attributes of a Restlet message that get propagated to Camel IN headers. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageBody"></a>Message Body</h3>

<p>Camel will store the restlet response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message, so that headers are preserved during routing.</p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>


<h4><a name="BookComponentAppendix-RestletEndpointwithAuthentication"></a>Restlet Endpoint with Authentication</h4>

<p>The following route starts a <tt>restlet</tt> consumer endpoint that listens for <tt>POST</tt> requests on <a href="http://localhost:8080" rel="nofollow">http://localhost:8080</a>.  The processor creates a response that echoes the request body and the value of the <tt>id</tt> header.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"restlet:http:<span class="code-comment">//localhost:9080/securedOrders?restletMethod=post&amp;restletRealm=#realm"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        exchange.getOut().setBody(
                <span class="code-quote">"received ["</span> + exchange.getIn().getBody()
                + <span class="code-quote">"] as an order id = "</span>
                + exchange.getIn().getHeader(<span class="code-quote">"id"</span>));
    }
});
</pre>
</div></div>
<p>The <tt>restletRealm</tt> setting (in <b>2.x</b>, use the <tt>#</tt> notation,  that is, <tt>restletRealm=#<em>refName</em></tt>)in the URI query is used to look up a Realm Map in the registry.  If this option is specified, the restlet consumer uses the information to authenticate user logins.  Only <em>authenticated</em> requests can access the resources.  In this sample, we create a Spring application context that serves as a registry.  The bean ID of the Realm Map should match the <em>restletRealmRef</em>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;util:map id=<span class="code-quote">"realm"</span>&gt;</span>
	<span class="code-tag">&lt;entry key=<span class="code-quote">"admin"</span> value=<span class="code-quote">"foo"</span> /&gt;</span>
	<span class="code-tag">&lt;entry key=<span class="code-quote">"bar"</span> value=<span class="code-quote">"foo"</span> /&gt;</span>
<span class="code-tag">&lt;/util:map&gt;</span>
</pre>
</div></div>
<p>The following sample starts a <tt>direct</tt> endpoint that sends requests to the server on <a href="http://localhost:8080" rel="nofollow">http://localhost:8080</a> (that is, our restlet consumer endpoint).</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// Note: restletMethod and restletRealmRef are stripped 
</span><span class="code-comment">// from the query before a request is sent as they are 
</span><span class="code-comment">// only processed by Camel.
</span>from(<span class="code-quote">"direct:start-auth"</span>).to(<span class="code-quote">"restlet:http:<span class="code-comment">//localhost:9080/securedOrders?restletMethod=post"</span>);</span>
</pre>
</div></div>
<p>That is all we need.  We are ready to send a request and try out the restlet component:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">final</span> <span class="code-object">String</span> id = <span class="code-quote">"89531"</span>;

Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
headers.put(RestletConstants.RESTLET_LOGIN, <span class="code-quote">"admin"</span>);
headers.put(RestletConstants.RESTLET_PASSWORD, <span class="code-quote">"foo"</span>);
headers.put(<span class="code-quote">"id"</span>, id);

<span class="code-object">String</span> response = (<span class="code-object">String</span>) template.requestBodyAndHeaders(<span class="code-quote">"direct:start-auth"</span>, 
        <span class="code-quote">"&lt;order foo='1'/&gt;"</span>, headers);
</pre>
</div></div>

<p>The sample client sends a request to the <tt>direct:start-auth</tt> endpoint with the following headers:</p>
<ul>
	<li><tt>CamelRestletLogin</tt> (used internally by Camel)</li>
	<li><tt>CamelRestletPassword</tt> (used internally by Camel)</li>
	<li><tt>id</tt> (application header)</li>
</ul>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Note</b><br /><p><tt>org.apache.camel.restlet.auth.login</tt> and <tt>org.apache.camel.restlet.auth.password</tt> will not be propagated as Restlet header.</p></td></tr></table></div>

<p>The sample client gets a response like the following:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
received [&lt;order foo='1'/&gt;] as an order id = 89531
</pre>
</div></div>

<h4><a name="BookComponentAppendix-SinglerestletendpointtoservicemultiplemethodsandURItemplates%282.0orlater%29"></a>Single restlet endpoint to service multiple methods and URI templates (2.0 or later)</h4>

<p>It is possible to create a single route to service multiple HTTP methods using the <tt>restletMethods</tt> option.  This snippet also shows how to retrieve the request method from the header:  </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"restlet:http:<span class="code-comment">//localhost:9080/users/{username}?restletMethods=post,get"</span>)
</span>    .process(<span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// echo the method
</span>            exchange.getOut().setBody(exchange.getIn().getHeader(Exchange.HTTP_METHOD,
                                                                 <span class="code-object">String</span>.class));

        }
    });
</pre>
</div></div>

<p>In addition to servicing multiple methods, the next snippet shows how to create an endpoint that supports multiple URI templates using the <tt>restletUriPatterns</tt> option.  The request URI is available in the header of the IN message as well.  If a URI pattern has been defined in the endpoint URI (which is not the case in this sample), both the URI pattern defined in the endpoint and the <tt>restletUriPatterns</tt> option will be honored.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"restlet:http:<span class="code-comment">//localhost:9080?restletMethods=post,get&amp;restletUriPatterns=#uriTemplates"</span>)
</span>    .process(<span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// echo the method
</span>            <span class="code-object">String</span> uri = exchange.getIn().getHeader(Exchange.HTTP_URI, <span class="code-object">String</span>.class);
            <span class="code-object">String</span> out = exchange.getIn().getHeader(Exchange.HTTP_METHOD, <span class="code-object">String</span>.class);
            <span class="code-keyword">if</span> (<span class="code-quote">"http:<span class="code-comment">//localhost:9080/users/homer"</span>.equals(uri)) {
</span>                exchange.getOut().setBody(out + <span class="code-quote">" "</span> + exchange.getIn().getHeader(<span class="code-quote">"username"</span>, <span class="code-object">String</span>.class));
            } <span class="code-keyword">else</span> <span class="code-keyword">if</span> (<span class="code-quote">"http:<span class="code-comment">//localhost:9080/atom/collection/foo/component/bar"</span>.equals(uri)) {
</span>                exchange.getOut().setBody(out + <span class="code-quote">" "</span> + exchange.getIn().getHeader(<span class="code-quote">"id"</span>, <span class="code-object">String</span>.class)
                                          + <span class="code-quote">" "</span> + exchange.getIn().getHeader(<span class="code-quote">"cid"</span>, <span class="code-object">String</span>.class));

            }

        }
    });
</pre>
</div></div>

<p>The <tt>restletUriPatterns=#uriTemplates</tt> option references the <tt>List&lt;String&gt;</tt> bean defined in the Spring XML configuration.  </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"uriTemplates"</span>&gt;</span>
  <span class="code-tag">&lt;list&gt;</span>
     <span class="code-tag">&lt;value&gt;</span>/users/{username}<span class="code-tag">&lt;/value&gt;</span>
     <span class="code-tag">&lt;value&gt;</span>/atom/collection/{id}/component/{cid}<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

</pre>
</div></div>

<h2><a name="BookComponentAppendix-RMIComponent"></a>RMI Component</h2>

<p>The <b>rmi:</b> component binds <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/component/pojo/PojoExchange.html" rel="nofollow">PojoExchanges</a> to the RMI protocol (JRMP).</p>

<p>Since this binding is just using RMI, normal RMI rules still apply regarding what methods can be invoked.  This component supports only <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/component/pojo/PojoExchange.html" rel="nofollow">PojoExchanges</a> that carry a method invocation from an interface that extends the <a href="http://java.sun.com/j2se/1.3/docs/api/java/rmi/Remote.html" rel="nofollow">Remote</a> interface.  All parameters in the method should be either <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html" rel="nofollow">Serializable</a> or <tt>Remote</tt> objects.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rmi:<span class="code-comment">//rmi-regisitry-host:rmi-registry-port/registry-path[?options]</span>
</pre>
</div></div>

<p>For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rmi:<span class="code-comment">//localhost:1099/path/to/service</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>method</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.3</b>, you can set the name of the method to invoke. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Using"></a>Using</h3>

<p>To call out to an existing RMI service registered in an RMI registry, create a route similar to the following:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"pojo:foo"</span>).to(<span class="code-quote">"rmi:<span class="code-comment">//localhost:1099/foo"</span>);</span>
</pre>
</div></div>

<p>To bind an existing camel processor or service in an RMI registry, define an RMI endpoint as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RmiEndpoint endpoint= (RmiEndpoint) endpoint(<span class="code-quote">"rmi:<span class="code-comment">//localhost:1099/bar"</span>);
</span>endpoint.setRemoteInterfaces(ISay.class);
from(endpoint).to(<span class="code-quote">"pojo:bar"</span>);
</pre>
</div></div>

<p>Note that when binding an RMI consumer endpoint, you must specify the <tt>Remote</tt> interfaces exposed.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-RSSComponent"></a>RSS Component</h2>

<p>The <b>rss:</b> component is used for polling RSS feeds. Camel will default poll the feed every 60th seconds.</p>

<p><b>Note:</b> The component currently only supports polling (consuming) feeds.</p>

<p><b>New in Camel 2.0</b></p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rss:rssUri
</pre>
</div></div>

<p>Where <tt>rssUri</tt> is the URI to the RSS feed to poll. </p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, Camel splits a feed into its individual entries and returns each entry, poll by poll. For example, if a feed contains seven entries, Camel returns the first entry on the first poll, the second entry on the second poll, and so on. When no more entries are left in the feed, Camel contacts the remote RSS URI to obtain a new feed. If <tt>false</tt>, Camel obtains a fresh feed on every poll and returns all of the feed's entries. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  Use in combination with the <tt>splitEntries</tt> option in order to filter returned entries. By default, Camel applies the <tt>UpdateDateFilter</tt> filter, which returns only new entries from the feed, ensuring that the consumer endpoint never receives an entry more than once. The filter orders the entries chronologically, with the newest returned last. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lastUpdate</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use in combination with the <tt>filter</tt> option to block entries earlier than a specific date/time (uses the <tt>entry.updated</tt> timestamp). The format is: <tt>yyyy-MM-ddTHH:MM:ss</tt>. Example: <tt>2007-12-24T17:45:59</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>feedHeader</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether to add the ROME <tt>SyndFeed</tt> object as a header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sortEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>splitEntries</tt> is <tt>true</tt>, this specifies whether to sort the entries by updated date. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use fixed delay between pools, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Exchangedatatypes"></a>Exchange data types</h3>

<p>Camel initializes the In body on the Exchange with a ROME <tt>SyndFeed</tt>. Depending on the value of the <tt>splitEntries</tt> flag, Camel returns either a <tt>SyndFeed</tt> with one <tt>SyndEntry</tt> or a <tt>java.util.List</tt> of <tt>SyndEntrys</tt>.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Value </th>
<th class='confluenceTh'> Behavior </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  A single entry from the current feed is set in the exchange. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> The entire list of entries from the current feed is set in the exchange. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.component.rss.feed</tt> </td>
<td class='confluenceTd'> Camel 1.x: The entire <tt>SyncFeed</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelRssFeed</tt> </td>
<td class='confluenceTd'> Camel 2.0: The entire <tt>SyncFeed</tt> object. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-RSSDataformat"></a>RSS Dataformat</h3>

<p>The RSS component ships with an RSS dataformat that can be used to convert between String (as XML) and ROME RSS model objects. </p>

<ul>
	<li>marshal = from ROME <tt>SyndFeed</tt> to XML <tt>String</tt></li>
	<li>unmarshal = from XML <tt>String</tt> to ROME <tt>SyndFeed</tt></li>
</ul>


<p>A route using this would look something like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span class="code-keyword">false</span>&amp;consumer.delay=1000"</span>).marshal().rss().to(<span class="code-quote">"mock:marshal"</span>);
</pre>
</div></div>

<p>The purpose of this feature is to make it possible to use Camel's lovely built-in expressions for manipulating RSS messages. As shown below, an XPath expression can be used to filter the RSS message:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// only entries with Camel in the title will get through the filter
</span>from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span class="code-keyword">true</span>&amp;consumer.delay=100"</span>)
    .marshal().rss().filter().xpath(<span class="code-quote">"<span class="code-comment">//item/title[contains(.,'Camel')]"</span>).to(<span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Mergingmultipleincomingfeeds"></a>Merging multiple incoming feeds</h3>

<p>To merge multiple incoming feeds into a single feed, you can apply the custom aggregator, <tt>AggregationCollection</tt>, provided with camel-rss. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?sortEntries=<span class="code-keyword">true</span>&amp;consumer.delay=50"</span>).to(<span class="code-quote">"seda:temp"</span>);
from(<span class="code-quote">"rss:file:target/rss20.xml?sortEntries=<span class="code-keyword">true</span>&amp;consumer.delay=50"</span>).to(<span class="code-quote">"seda:temp"</span>);

from(<span class="code-quote">"seda:temp"</span>).aggregate(<span class="code-keyword">new</span> AggregateRssFeedCollection()).batchTimeout(5000L).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>Here we use a <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> queue to gather up entries from two RSS feeds. The entries are then fed into the custom aggregator which combines these entries into a single ROME <tt>SyndFeed</tt> object.</p>

<h3><a name="BookComponentAppendix-Filteringentries"></a>Filtering entries</h3>

<p>You can filter out entries quite easily using XPath, as shown in the data format section above. You can also exploit Camel's <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a> to implement your own conditions. For instance, a filter equivalent to the XPath example above would be:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// only entries with Camel in the title will get through the filter
</span>from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span class="code-keyword">true</span>&amp;consumer.delay=100"</span>).
    filter().method(<span class="code-quote">"myFilterBean"</span>, <span class="code-quote">"titleContainsCamel"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>The custom bean for this would be:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span class="code-keyword">static</span> class FilterBean {
    <span class="code-keyword">public</span> <span class="code-object">boolean</span> titleContainsCamel(@Body SyndFeed feed) {
        SyndEntry firstEntry = (SyndEntry) feed.getEntries().get(0);
        <span class="code-keyword">return</span> firstEntry.getTitle().contains(<span class="code-quote">"Camel"</span>);
    }
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-Scalate"></a>Scalate</h2>

<p>The <b>scalate:</b> component allows you to process a message using <a href="http://scalate.fusesource.org/" rel="nofollow">Scalate</a> template, which supports either SSP or Scaml format templates. This can be ideal when using <a href="/confluence/display/CAMEL/Templating" title="Templating">Templating</a> to generate responses for requests.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
scalate:templateName[?options]
</pre>
</div></div>

<p>Where <b>templateName</b> is the classpath-local URI of the template to invoke; or the complete URL of the remote template (eg: <a href="file://folder/myfile.ssp" rel="nofollow">file://folder/myfile.ssp</a>).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>

<p>The scalate component sets a couple headers on the message (you can't set these yourself and from Camel 2.1 scalate component will not set these headers which will cause some side effect on the dynamic template support):</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelScalateResource</tt> </td>
<td class='confluenceTd'> Camel 2.0: The resource as an <tt>org.springframework.core.io.Resource</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelScalateResourceUri</tt> </td>
<td class='confluenceTd'> Camel 2.0: The <b>templateName</b> as a <tt>String</tt> object. </td>
</tr>
</tbody></table>

<p>Headers set during the Scalate evaluation are returned to the message and added as headers. Then its kinda possible to return values from Scalate to the Message.</p>

<p>For example, to set the header value of <tt>fruit</tt> in the Scalate template <tt>.tm</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;% in.setHeader('fruit', 'Apple') %&gt;
</pre>
</div></div>

<p>The <tt>fruit</tt> header is now accessible from the <tt>message.out.headers</tt>.</p>

<h3><a name="BookComponentAppendix-ScalateContext"></a>Scalate Context</h3>
<p>Camel will provide exchange information in the Scalate context (just a <tt>Map</tt>). The <tt>Exchange</tt> is transfered as:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> key </th>
<th class='confluenceTh'> value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>exchange</tt> </td>
<td class='confluenceTd'> The <tt>Exchange</tt> itself. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headers</tt> </td>
<td class='confluenceTd'> The headers of the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelContext</tt> </td>
<td class='confluenceTd'> The Camel Context intance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>in</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>body</tt> </td>
<td class='confluenceTd'> The In message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>out</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>response</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Hotreloading"></a>Hot reloading</h3>
<p>The Scalate template resource is, by default, hot reloadable for both file and classpath resources (expanded jar). </p>

<h3><a name="BookComponentAppendix-Dynamictemplates"></a>Dynamic templates</h3>

<p>Camel provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> CamelScalateResourceUri </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> A URI for the template resource to use instead of the endpoint configured. </td>
</tr>
<tr>
<td class='confluenceTd'> CamelScalateTemplate </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The template to use instead of the endpoint configured. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>For example you could use something like</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"scalate:com/acme/MyResponse.ssp"</span>);
</pre>
</div></div>

<p>To use a Scalate template to formulate a response to a message for InOut message exchanges (where there is a <tt>JMSReplyTo</tt> header).</p>

<p>If you want to use InOnly and consume the message and send it to another destination, you could use the following route:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"scalate:com/acme/MyResponse.haml"</span>).
  to(<span class="code-quote">"activemq:Another.Queue"</span>);
</pre>
</div></div>

<p>It's possible to specify what template the component should use dynamically via a header, so for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:in"</span>).
  setHeader(<span class="code-quote">"CamelScalateResourceUri"</span>).constant(<span class="code-quote">"path/to/my/template.vm"</span>).
  to(<span class="code-quote">"scalate:dummy"</span>);
</pre>
</div></div>

<p>It's possible to specify a template directly as a header the component should use dynamically via a header, so for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:in"</span>).
  setHeader(<span class="code-quote">"CamelScalateTemplate"</span>).constant(<span class="code-quote">"&lt;%@ attribute body: <span class="code-object">Object</span> %&gt;\nHi <span class="code-keyword">this</span> is a scalate template that can <span class="code-keyword">do</span> templating ${body}"</span>).
  to(<span class="code-quote">"scalate:dummy"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-TheEmailSample"></a>The Email Sample</h3>
<p>In this sample we want to use Scalate templating for an order confirmation email. The email template is laid out in Scalate as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;%@ attribute in: org.apache.camel.scala.RichMessage %&gt;
Dear ${in(<span class="code-quote">"lastName"</span>}, ${in(<span class="code-quote">"firstName"</span>)}

Thanks <span class="code-keyword">for</span> the order of ${in(<span class="code-quote">"item"</span>)}.

Regards Camel Riders Bookstore
${in.body}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-SEDAComponent"></a>SEDA Component</h2>

<p>The <b>seda:</b> component provides asynchronous <a href="http://www.eecs.harvard.edu/~mdw/proj/seda/" rel="nofollow">SEDA</a> behavior, so that messages are exchanged on a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html" rel="nofollow">BlockingQueue</a> and consumers are invoked in a separate thread from the producer.</p>

<p>Note that queues are only visible within a <em>single</em> <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>. If you want to communicate across <tt>CamelContext</tt> instances (for example, communicating between Web applications), see the <a href="/confluence/display/CAMEL/VM" title="VM">VM</a> component.</p>

<p>This component does not implement any kind of persistence or recovery, if the VM terminates while messages are yet to be processed. If you need persistence, reliability or distributed SEDA, try using either <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> or <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a>.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Synchronous</b><br /><p>The <a href="/confluence/display/CAMEL/Direct" title="Direct">Direct</a> component provides synchronous invocation of any consumers when a producer sends a message exchange.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
seda:someName[?options]
</pre>
</div></div>

<p>Where <b>someName</b> can be any string that uniquely identifies the endpoint within the current <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Same URI must be used for both producer and consumer</b><br /><p>An exactly identical <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> endpoint URI <b>must</b> be used for both the producer endpoint and the consumer endpoint. Otherwise Camel will create a second <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> endpoint, even thought the <tt>someName</tt> portion of the URI is identical. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:foo"</span>).to(<span class="code-quote">"seda:bar?concurrentConsumers=5"</span>);

from(<span class="code-quote">"seda:bar?concurrentConsumers=5"</span>).to(<span class="code-quote">"file:<span class="code-comment">//output"</span>);</span>
</pre>
</div></div>
<p>Notice that we have to use the full URI including options in both the producer and consumer.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>size</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> The maximum size of the SEDA queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>concurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0</b>: Number of concurrent threads processing exchanges. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>waitForTaskToComplete</tt> </td>
<td class='confluenceTd'> <tt>IfReplyExpected</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Option to specify whether the caller should wait for the async task to complete or not before continuing. The following three options are supported: <tt>Always</tt>, <tt>Never</tt> or <tt>IfReplyExpected</tt>. The first two values are self-explanatory. The last value, <tt>IfReplyExpected</tt>, will only wait if the message is <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> based. The default option is <tt>IfReplyExpected</tt>. See more information about <a href="/confluence/display/CAMEL/Async" title="Async">Async</a> messaging. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Timeout in millis a seda producer will at most waiting for an async task to complete. See <tt>waitForTaskToComplete</tt> and <a href="/confluence/display/CAMEL/Async" title="Async">Async</a> for more details. In <b>Camel 2.2</b> you can now disable timeout by using 0 or a negative value. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multipleConsumers</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Specifies whether multiple consumers is allowed or not. If enabled you can use <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> for a pubsub kinda style messaging. Send a message to a seda queue and have multiple consumers receive a copy of the message. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-ChangesinCamel2.0"></a>Changes in Camel 2.0</h3>
<p>In Camel 2.0 the <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> component supports using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>, where the caller will wait for the <a href="/confluence/display/CAMEL/Async" title="Async">Async</a> route to complete. For instance:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"mina:tcp:<span class="code-comment">//0.0.0.0:9876?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"seda:input"</span>);
</span>
from(<span class="code-quote">"seda:input"</span>).to(<span class="code-quote">"bean:processInput"</span>).to(<span class="code-quote">"bean:createResponse"</span>);
</pre>
</div></div>
<p>In the route above, we have a TCP listener on port 9876 that accepts incoming requests. The request is routed to the <tt>seda:input</tt> queue. As it is a <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> message, we wait for the response. When the consumer on the <tt>seda:input</tt> queue is complete, it copies the response to the original message response.</p>

<p>Camel 1.x does <b>not</b> have this feature implemented, the <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> queues in Camel 1.x will newer wait.</p>

<h3><a name="BookComponentAppendix-Concurrentconsumers"></a>Concurrent consumers</h3>
<p>By default, the SEDA endpoint uses a single consumer thread, but you can configure it to use concurrent consumer threads. So instead of thread pools you can use:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"seda:stageName?concurrentConsumers=5"</span>).process(...)
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Differencebetweenthreadpoolsandconcurrentconsumers"></a>Difference between thread pools and concurrent consumers</h4>
<p>The <em>thread pool</em> is a pool that can increase/shrink dynamically at runtime depending on load, whereas the concurrent consumers are always fixed.</p>

<h3><a name="BookComponentAppendix-Threadpools"></a>Thread pools</h3>
<p>Be aware that adding a thread pool to a SEDA endpoint by doing something like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"seda:stageName"</span>).thread(5).process(...)
</pre>
</div></div>
<p>Can wind up with two <tt>BlockQueues</tt>: one from the SEDA endpoint, and one from the workqueue of the thread pool, which may not be what you want. Instead, you might want to consider configuring a <a href="/confluence/display/CAMEL/Direct" title="Direct">Direct</a> endpoint with a thread pool, which can process messages both synchronously and asynchronously. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:stageName"</span>).thread(5).process(...)
</pre>
</div></div>
<p>You can also directly configure number of threads that process messages on a SEDA endpoint using the <tt>concurrentConsumers</tt> option.</p>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In the route below we use the SEDA queue to send the request to this async queue to be able to send a fire-and-forget message for further processing in another thread, and return a constant reply in this thread to the original caller. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
    from(<span class="code-quote">"direct:start"</span>)
        <span class="code-comment">// send it to the seda queue that is async
</span>        .to(<span class="code-quote">"seda:next"</span>)
        <span class="code-comment">// <span class="code-keyword">return</span> a constant response
</span>        .transform(constant(<span class="code-quote">"OK"</span>));

    from(<span class="code-quote">"seda:next"</span>).to(<span class="code-quote">"mock:result"</span>);
}
</pre>
</div></div>

<p>Here we send a Hello World message and expects the reply to be OK.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-object">Object</span> out = template.requestBody(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Hello World"</span>);
assertEquals(<span class="code-quote">"OK"</span>, out);
</pre>
</div></div>

<p>The "Hello World" message will be consumed from the SEDA queue from another thread for further processing. Since this is from a unit test, it will be sent to a <tt>mock</tt> endpoint where we can do assertions in the unit test.</p>

<h3><a name="BookComponentAppendix-UsingmultipleConsumers"></a>Using multipleConsumers</h3>
<p><b>Available as of Camel 2.2</b></p>

<p>In this example we have defined two consumers and registered them as spring beans.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- define the consumers as spring beans --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"consumer1"</span> class=<span class="code-quote">"org.apache.camel.spring.example.FooEventConsumer"</span>/&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"consumer2"</span> class=<span class="code-quote">"org.apache.camel.spring.example.AnotherFooEventConsumer"</span>/&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- define a shared endpoint which the consumers can refer to instead of using url --&gt;</span></span>
    <span class="code-tag">&lt;endpoint id=<span class="code-quote">"foo"</span> uri=<span class="code-quote">"seda:foo?multipleConsumers=true"</span>/&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>Since we have specified <b>multipleConsumers=true</b> on the seda foo endpoint we can have those two consumers receive their own copy of the message as a kind of pub-sub style messaging.</p>

<p>As the beans are part of an unit test they simply send the message to a mock endpoint, but notice how we can use @Consume to consume from the seda queue.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class FooEventConsumer {

    @EndpointInject(uri = <span class="code-quote">"mock:result"</span>)
    <span class="code-keyword">private</span> ProducerTemplate destination;

    @Consume(ref = <span class="code-quote">"foo"</span>)
    <span class="code-keyword">public</span> void doSomething(<span class="code-object">String</span> body) {
        destination.sendBody(<span class="code-quote">"foo"</span> + body);
    }

}
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Direct" title="Direct">Direct</a></li>
	<li><a href="/confluence/display/CAMEL/Async" title="Async">Async</a></li>
</ul>

<h2><a name="BookComponentAppendix-ServletComponent"></a>Servlet Component</h2>

<p>The <b>servlet:</b> component provides HTTP based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming HTTP requests that arrive at a HTTP endpoint and this endpoint is bound to a published Servlet.</p>

<p>Note: This component is new to Camel 2.0-M3.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt> for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-servlet&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;\!-\- use the same version as your Camel core version \--&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
servlet:<span class="code-comment">//relative_path[?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>


<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Reference to an <tt>org.apache.camel.component.http.HttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. A <tt>HttpBinding</tt> implementation can be used to customize how to write a response. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>matchOnUriPrefix</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether or not the <tt>CamelServlet</tt> should try to find a target consumer by matching the URI prefix, if no exact match is found. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>servletName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the servlet name that the servlet endpoint will bind to. If there is no servlet name specified, the servlet endpoint will be bind to first published Servlet </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel will apply the same Message Headers as the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a> component.</p>

<p>Camel will also populate <b>all</b> <tt>request.parameter</tt> and <tt>request.headers</tt>. For example, if a client request has the URL, <tt><a href="http://myserver/myserver?orderid=123" rel="nofollow">http://myserver/myserver?orderid=123</a></tt>, the exchange will contain a header named <tt>orderid</tt> with the value 123. </p>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>

<p>You can only consume from endpoints generated by the Servlet component. Therefore, it should only be used as input into your camel routes. To issue HTTP requests against other HTTP endpoints, use the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP Component</a></p>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In this sample, we define a route that exposes a HTTP service at <tt><a href="http://localhost:8080/camel/services/hello" rel="nofollow">http://localhost:8080/camel/services/hello</a></tt>.<br/>
First, you need to publish the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java" rel="nofollow">CamelHttpTransportServlet</a> through the normal Web Container, or OSGi Service.<br/>
Use the <tt>Web.xml</tt> file to publish the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java" rel="nofollow">CamelHttpTransportServlet</a> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;web-app&gt;</span>

  <span class="code-tag">&lt;servlet&gt;</span>
    <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span class="code-tag">&lt;/servlet-name&gt;</span>
    <span class="code-tag">&lt;display-name&gt;</span>Camel Http Transport Servlet<span class="code-tag">&lt;/display-name&gt;</span>
    <span class="code-tag">&lt;servlet-class&gt;</span>
        org.apache.camel.component.servlet.CamelHttpTransportServlet
    <span class="code-tag">&lt;/servlet-class&gt;</span>
    
  <span class="code-tag">&lt;/servlet&gt;</span>

  <span class="code-tag">&lt;servlet-mapping&gt;</span>
    <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span class="code-tag">&lt;/servlet-name&gt;</span>
    <span class="code-tag">&lt;url-pattern&gt;</span>/services/*<span class="code-tag">&lt;/url-pattern&gt;</span>
  <span class="code-tag">&lt;/servlet-mapping&gt;</span>

<span class="code-tag">&lt;/web-app&gt;</span>
</pre>
</div></div>

<p>Use an <tt>Activator</tt> to publish the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java" rel="nofollow">CamelHttpTransportServlet</a> on the OSGi platform </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">import</span> java.util.Dictionary;
<span class="code-keyword">import</span> java.util.Hashtable;

<span class="code-keyword">import</span> javax.servlet.Servlet;

<span class="code-keyword">import</span> org.apache.camel.component.servlet.CamelHttpTransportServlet;
<span class="code-keyword">import</span> org.apache.commons.logging.Log;
<span class="code-keyword">import</span> org.apache.commons.logging.LogFactory;
<span class="code-keyword">import</span> org.osgi.framework.BundleActivator;
<span class="code-keyword">import</span> org.osgi.framework.BundleContext;
<span class="code-keyword">import</span> org.osgi.framework.ServiceReference;
<span class="code-keyword">import</span> org.osgi.service.http.HttpContext;
<span class="code-keyword">import</span> org.osgi.service.http.HttpService;
<span class="code-keyword">import</span> org.springframework.osgi.context.BundleContextAware;

<span class="code-keyword">public</span> <span class="code-keyword">final</span> class ServletActivator <span class="code-keyword">implements</span> BundleActivator, BundleContextAware {
    <span class="code-keyword">private</span> <span class="code-keyword">static</span> <span class="code-keyword">final</span> <span class="code-keyword">transient</span> Log LOG = LogFactory.getLog(ServletActivator.class);
    <span class="code-keyword">private</span> <span class="code-keyword">static</span> <span class="code-object">boolean</span> registerService;
    
    /**
     * HttpService reference.
     */
    <span class="code-keyword">private</span> ServiceReference httpServiceRef;
    
    /**
     * Called when the OSGi framework starts our bundle
     */
    <span class="code-keyword">public</span> void start(BundleContext bc) <span class="code-keyword">throws</span> Exception {
        registerServlet(bc);
    }

    /**
     * Called when the OSGi framework stops our bundle
     */
    <span class="code-keyword">public</span> void stop(BundleContext bc) <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">if</span> (httpServiceRef != <span class="code-keyword">null</span>) {
            bc.ungetService(httpServiceRef);
            httpServiceRef = <span class="code-keyword">null</span>;
        }
    }
    
    <span class="code-keyword">protected</span> void registerServlet(BundleContext bundleContext) <span class="code-keyword">throws</span> Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
        
        <span class="code-keyword">if</span> (httpServiceRef != <span class="code-keyword">null</span> &amp;&amp; !registerService) {
            LOG.info(<span class="code-quote">"Regist the servlet service"</span>);
            <span class="code-keyword">final</span> HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            <span class="code-keyword">if</span> (httpService != <span class="code-keyword">null</span>) {
                <span class="code-comment">// create a <span class="code-keyword">default</span> context to share between registrations
</span>                <span class="code-keyword">final</span> HttpContext httpContext = httpService.createDefaultHttpContext();
                <span class="code-comment">// register the hello world servlet
</span>                <span class="code-keyword">final</span> Dictionary initParams = <span class="code-keyword">new</span> Hashtable();
                initParams.put(<span class="code-quote">"matchOnUriPrefix"</span>, <span class="code-quote">"<span class="code-keyword">false</span>"</span>);
                initParams.put(<span class="code-quote">"servlet-name"</span>, <span class="code-quote">"camelServlet"</span>);
                httpService.registerServlet(<span class="code-quote">"/camel/services"</span>, <span class="code-comment">// alias
</span>                    (Servlet)<span class="code-keyword">new</span> CamelHttpTransportServlet(), <span class="code-comment">// register servlet
</span>                    initParams, <span class="code-comment">// init params
</span>                    httpContext <span class="code-comment">// http context
</span>                );
                registerService = <span class="code-keyword">true</span>;
            }
        }
    }

    <span class="code-keyword">public</span> void setBundleContext(BundleContext bc) {
        <span class="code-keyword">try</span> {
            registerServlet(bc);
        } <span class="code-keyword">catch</span> (Exception e) {
            LOG.error(<span class="code-quote">"Can't register the servlet, the reason is "</span> + e);
        }
    }

}
</pre>
</div></div>

<p>Then you can define your route as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"servlet:<span class="code-comment">///hello?matchOnUriPrefix=<span class="code-keyword">true</span>"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-object">String</span> contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, <span class="code-object">String</span>.class);
        <span class="code-object">String</span> path = exchange.getIn().getHeader(Exchange.HTTP_PATH, <span class="code-object">String</span>.class);
        assertEquals(<span class="code-quote">"Get a wrong content type"</span>, CONTENT_TYPE, contentType);
        <span class="code-object">String</span> charsetEncoding = exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, <span class="code-object">String</span>.class);
        assertEquals(<span class="code-quote">"Get a wrong charset name"</span>, <span class="code-quote">"UTF-8"</span>, charsetEncoding);
        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + <span class="code-quote">"; charset=UTF-8"</span>);                        
        exchange.getOut().setHeader(<span class="code-quote">"PATH"</span>, path);
        exchange.getOut().setBody(<span class="code-quote">"&lt;b&gt;Hello World&lt;/b&gt;"</span>);
    }
});
</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Specify the relative path for camel-servlet endpoint</b><br /></td></tr></table></div>
<p>Since we are binding the Http transport with a published servlet, and we don't know the servlet's application context path, the <tt>camel-servlet</tt> endpoint uses the relative path to specify the endpoint's URL. A client can access the <tt>camel-servlet</tt> endpoint through the servlet publish address: <tt>("http://localhost:8080/camel/services") + RELATIVE_PATH("/hello")</tt>.</p>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a></li>
</ul>

<h2><a name="BookComponentAppendix-Smooks"></a>Smooks</h2>

<p>The <b>smooks</b> component supports the <a href="http://milyn.codehaus.org/Smooks" rel="nofollow">Smooks Library</a> for EDI parsing. The <b>camel-smooks</b> library is provided by the <a href="http://code.google.com/p/camel-extra/" rel="nofollow">Camel Extra</a> project which hosts all *GPL related components for Camel.</p>

<p>It is <b>only</b> the EDI parsing feature that is implemented in this component. The other features from Smooks are covered in existing camel components.<br/>
Parsing from any given data source to EDI is implemented using Camel <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data Format</a>. </p>

<h2><a name="BookComponentAppendix-EDIDataFormat"></a>EDI DataFormat</h2>

<p>This component ships with a EDI dataformat that can be used to format from a <tt>java.io.InputStream</tt> to XML as a <tt>org.w3c.Document</tt> Object.</p>
<ul>
	<li>marshal = currently not supported by <a href="http://milyn.codehaus.org/Home" rel="nofollow">Smooks</a></li>
	<li>unmarshal = from stream to XML (can be used when reading EDI files)</li>
</ul>


<p>The EDIDataFormat must be configued with either a:</p>
<ul>
	<li><tt>setSmooksConfig(configfile)</tt> = a fully <a href="http://milyn.codehaus.org/Home" rel="nofollow">Smooks</a> configuration file</li>
	<li><tt>setMappingModel(modelfile)</tt> = just the mapping model xml file and Camel will use a default <a href="http://milyn.codehaus.org/Home" rel="nofollow">Smooks</a> configuration</li>
</ul>


<p>To use the data format simply instantiate an instance, set the configuration (above) and invoke the unmarshal operation in the route builder:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
DataFormat edi = <span class="code-keyword">new</span> EDIDataFormat();
edi.setMappingModel(<span class="code-quote">"my-order-mapping.xml"</span>);
...
from(<span class="code-quote">"file:<span class="code-comment">//edi/in"</span>).
</span>  unmarshal(edi).
  to(<span class="code-quote">"jms:queue:edi"</span>);
</pre>
</div></div>

<p>And you can also provide the full <a href="http://milyn.codehaus.org/Home" rel="nofollow">Smooks</a> configuration file where you can configure <a href="http://milyn.codehaus.org/Home" rel="nofollow">Smooks</a> as you want, in case the default configuration isn't useful:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
DataFormat edi = <span class="code-keyword">new</span> EDIDataFormat();
edi.setSmooksConfig(<span class="code-quote">"my-smooks-config.xml"</span>);
...
from(<span class="code-quote">"file:<span class="code-comment">//edi/in"</span>).
</span>  unmarshal(edi).
  to(<span class="code-quote">"jms:queue:edi"</span>);
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Dependencies"></a>Dependencies</h3>

<p>To use EDI in your camel routes you need to add the a dependency on <b>camel-smooks</b> which implements this data format. </p>

<p>This component is hosted at the <a href="http://camel-extra.googlecode.com/" rel="nofollow">Camel Extra</a> project since the Smooks library uses a licenses which cant be included directly in an Apache project.</p>
<h2><a name="BookComponentAppendix-SNMPComponent"></a>SNMP Component</h2>
<p><b>Available as of Camel 2.1</b></p>

<p>The <b>snmp:</b> component gives you the ability to poll SNMP capable devices or receiving traps.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
snmp:<span class="code-comment">//hostname[:port][?Options]</span>
</pre>
</div></div>
<p>The component supports polling OID values from an SNMP enabled device and receiving traps.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>type</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> The type of action you want to perform. Actually you can enter here <tt>poll</tt> or <tt>trap</tt>. The value <tt>poll</tt> will instruct the endpoint to poll a given host for the supplied OID keys. If you put in <tt>trap</tt> you will setup a listener for SNMP Trap Events. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>address</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> This is the IP address and the port of the host to poll or where to setup the Trap Receiver. Example: <tt>127.0.0.1:162</tt></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>protocol</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> Here you can select which protocol to use. By default it will be <tt>udp</tt> protocol but you may want to use <tt>tcp</tt> as well </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>retries</tt> </td>
<td class='confluenceTd'> <tt>2</tt> </td>
<td class='confluenceTd'> Defines how often a retry is made before canceling the request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>1500</tt> </td>
<td class='confluenceTd'> Sets the timeout value for the request in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>snmpVersion</tt> </td>
<td class='confluenceTd'> <tt>0</tt> (which means SNMPv1) </td>
<td class='confluenceTd'> Sets the snmp version for the request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>snmpCommunity</tt> </td>
<td class='confluenceTd'> <tt>public</tt> </td>
<td class='confluenceTd'> Sets the community octet string for the snmp request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>60</tt> seconds </td>
<td class='confluenceTd'> Defines the delay in seconds between to poll cycles. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>oids</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> Defines which values you are interested in. Please have a look at the <a href="http://en.wikipedia.org/wiki/Object_identifier" rel="nofollow">Wikipedia </a> to get a better understanding. You may provide a single OID or a coma separated list of OIDs. Example: oids="1.3.6.1.2.1.1.3.0,1.3.6.1.2.1.25.3.2.1.5.1,1.3.6.1.2.1.25.3.5.1.1.1,1.3.6.1.2.1.43.5.1.1.11.1" </td>
</tr>
</tbody></table></div>

<h3><a name="BookComponentAppendix-Theresultofapoll"></a>The result of a poll</h3>

<p>Given the situation, that I poll for the following OIDs:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>oids</b></div><div class="codeContent panelContent">
<pre class="code-java">
1.3.6.1.2.1.1.3.0
1.3.6.1.2.1.25.3.2.1.5.1
1.3.6.1.2.1.25.3.5.1.1.1
1.3.6.1.2.1.43.5.1.1.11.1
</pre>
</div></div>

<p>The result will be the following:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Result of toString conversion</b></div><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
<span class="code-tag">&lt;snmp&gt;</span>
  <span class="code-tag">&lt;entry&gt;</span>
    <span class="code-tag">&lt;oid&gt;</span>1.3.6.1.2.1.1.3.0<span class="code-tag">&lt;/oid&gt;</span>
    <span class="code-tag">&lt;value&gt;</span>6 days, 21:14:28.00<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/entry&gt;</span>
  <span class="code-tag">&lt;entry&gt;</span>
    <span class="code-tag">&lt;oid&gt;</span>1.3.6.1.2.1.25.3.2.1.5.1<span class="code-tag">&lt;/oid&gt;</span>
    <span class="code-tag">&lt;value&gt;</span>2<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/entry&gt;</span>
  <span class="code-tag">&lt;entry&gt;</span>
    <span class="code-tag">&lt;oid&gt;</span>1.3.6.1.2.1.25.3.5.1.1.1<span class="code-tag">&lt;/oid&gt;</span>
    <span class="code-tag">&lt;value&gt;</span>3<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/entry&gt;</span>
  <span class="code-tag">&lt;entry&gt;</span>
    <span class="code-tag">&lt;oid&gt;</span>1.3.6.1.2.1.43.5.1.1.11.1<span class="code-tag">&lt;/oid&gt;</span>
    <span class="code-tag">&lt;value&gt;</span>6<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/entry&gt;</span>
  <span class="code-tag">&lt;entry&gt;</span>
    <span class="code-tag">&lt;oid&gt;</span>1.3.6.1.2.1.1.1.0<span class="code-tag">&lt;/oid&gt;</span>
    <span class="code-tag">&lt;value&gt;</span>My Very Special Printer Of Brand Unknown<span class="code-tag">&lt;/value&gt;</span>
  <span class="code-tag">&lt;/entry&gt;</span>
<span class="code-tag">&lt;/snmp&gt;</span>
</pre>
</div></div>

<p>As you maybe recognized there is one more result than requested....1.3.6.1.2.1.1.1.0.<br/>
This one is filled in by the device automatically in this special case. So it may absolutely happen, that you receive more than you requested...be prepared.</p>


<h3><a name="BookComponentAppendix-Examples"></a>Examples</h3>

<p>Polling a remote device:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
snmp:192.168.178.23:161?protocol=udp&amp;type=poll&amp;oids=1.3.6.1.2.1.1.5.0
</pre>
</div></div>

<p>Setting up a trap receiver (<b>Note that no OID info is needed here!</b>):</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
snmp:127.0.0.1:162?protocol=udp&amp;type=trap
</pre>
</div></div>

<p>Routing example in Java: (converts the SNMP PDU to XML String)</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"snmp:192.168.178.23:161?protocol=udp&amp;type=poll&amp;oids=1.3.6.1.2.1.1.5.0"</span>).
convertBodyTo(<span class="code-object">String</span>.class).
to(<span class="code-quote">"activemq:snmp.states"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-SpringIntegrationComponent"></a>Spring Integration Component</h2>

<p>The <b>spring-integration:</b> component provides a bridge for Camel components to talk to <a href="http://camel.apache.org/springintegration.html" rel="nofollow">spring integration endpoints</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
spring-integration:defaultChannelName[?options]
</pre>
</div></div>
<p>Where <b>defaultChannelName</b> represents the default channel name which is used by the Spring Integration Spring context. It will equal to the <tt>inputChannel</tt> name for the Spring Integration consumer and the <tt>outputChannel</tt> name for the Spring Integration provider.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>inputChannel</tt> </td>
<td class='confluenceTd'> The Spring integration input channel name that this endpoint wants to consume from, where the specified channel name is defined in the Spring context. </td>
<td class='confluenceTd'> <tt>inputChannel=requestChannel</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>outputChannel</tt> </td>
<td class='confluenceTd'> The Spring integration output channel name that is used to send messages to the Spring integration context. </td>
<td class='confluenceTd'> <tt>outputChannel=replyChannel</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inOut</tt> </td>
<td class='confluenceTd'> The exchange pattern that the Spring integration endpoint should use. </td>
<td class='confluenceTd'> <tt>inOut=true</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>inOnly</tt> for the Spring integration consumer and <tt>outOnly</tt> for the Spring integration provider </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
<td class='confluenceTd'> <tt>consumer.delay=60000</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>500</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
<td class='confluenceTd'> <tt>consumer.initialDelay=10000</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> Specify <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See the Java<a href="http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Character.html" rel="nofollow">ScheduledExecutorService</a> class for details. </td>
<td class='confluenceTd'> <tt>consumer.userFixedDelay=false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>

<p>The Spring integration component is a bridge that connects Camel endpoints with Spring integration endpoints through the Spring integration's input channels and output channels. Using this component, we can send Camel messages to Spring Integration endpoints or receive messages from Spring integration endpoints in a Camel routing context.</p>

<h3><a name="BookComponentAppendix-Examples"></a>Examples</h3>

<h4><a name="BookComponentAppendix-UsingtheSpringintegrationendpoint"></a>Using the Spring integration endpoint</h4>
<p>You can set up a Spring integration endpoint using a URI, as follows: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
	<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
	xsi:schemaLocation="http://www.springframework.org/schema/beans
			http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/integration
			http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
			http://camel.apache.org/schema/spring
			http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
	
	<span class="code-tag">&lt;channel id=<span class="code-quote">"inputChannel"</span>/&gt;</span>
   	<span class="code-tag">&lt;channel id=<span class="code-quote">"outputChannel"</span>/&gt;</span>
   	<span class="code-tag">&lt;channel id=<span class="code-quote">"onewayChannel"</span>/&gt;</span>

	&lt;service-activator input-channel=<span class="code-quote">"inputChannel"</span>	          
	          ref=<span class="code-quote">"helloService"</span>
	          method=<span class="code-quote">"sayHello"</span>/&gt;
	          	      
	&lt;service-activator input-channel=<span class="code-quote">"onewayChannel"</span>	          
	          ref=<span class="code-quote">"helloService"</span>
	          method=<span class="code-quote">"greet"</span>/&gt;
	          
	<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"helloService"</span> class=<span class="code-quote">"org.apache.camel.component.spring.integration.HelloWorldService"</span>/&gt;</span>
    
    <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:twowayMessage"</span>/&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- Using the &amp;amp; as the separator of &amp; --&gt;</span></span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"spring-integration:inputChannel?inOut=true&amp;amp;inputChannel=outputChannel"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>      
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:onewayMessage"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"spring-integration:onewayChannel?inOut=false"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;channel id=<span class="code-quote">"requestChannel"</span>/&gt;</span>
<span class="code-tag">&lt;channel id=<span class="code-quote">"responseChannel"</span>/&gt;</span>

<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"myProcessor"</span> class=<span class="code-quote">"org.apache.camel.component.spring.integration.MyProcessor"</span>/&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- Using the &amp;amp; as the separator of &amp; --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"spring-integration://requestChannel?outputChannel=responseChannel&amp;amp;inOut=true"</span>/&gt;</span>
    <span class="code-tag">&lt;process ref=<span class="code-quote">"myProcessor"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>Or directly using a Spring integration channel name:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
	<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
	xsi:schemaLocation="http://www.springframework.org/schema/beans
			http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/integration
			http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
			http://camel.apache.org/schema/spring
			http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
	<span class="code-tag">&lt;channel id=<span class="code-quote">"outputChannel"</span>/&gt;</span>

    <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- camel will create a spring integration endpoint automatically --&gt;</span></span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"outputChannel"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-TheSourceandTargetadapter"></a>The Source and Target adapter</h4>

<p>Spring integration also provides the Spring integration's source and target adapters, which can route messages from a Spring integration channel to a Camel endpoint or from a Camel endpoint to a Spring integration channel.</p>

<p>This example uses the following namespaces:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
       <span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel-si</span>=<span class="code-quote">"http://camel.apache.org/schema/spring/integration"</span>
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/integration
	   http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
       http://camel.apache.org/schema/spring/integration
       http://camel.apache.org/schema/spring/integration/camel-spring-integration.xsd
       http://camel.apache.org/schema/spring
       http://camel.apache.org/schema/spring/camel-spring.xsd
    "&gt;
</pre>
</div></div>

<p>You can bind your source or target to a Camel endpoint as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- Create the camel context here --&gt;</span></span>
<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camelTargetContext"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:EndpointA"</span> /&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span> /&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:EndpointC"</span>/&gt;</span>
        <span class="code-tag">&lt;process ref=<span class="code-quote">"myProcessor"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- We can bind the camelTarget to the camel context's endpoint by specifying the camelEndpointUri attribute --&gt;</span></span>
<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetA"</span> camelEndpointUri=<span class="code-quote">"direct:EndpointA"</span> expectReply=<span class="code-quote">"false"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetB"</span> camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> replyChannel=<span class="code-quote">"channelC"</span> expectReply=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetD"</span> camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> expectReply=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"myProcessor"</span> class=<span class="code-quote">"org.apache.camel.component.spring.integration.MyProcessor"</span>/&gt;</span>
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camelSourceContext"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:OneWay"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:EndpointB"</span> /&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
    	   <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:TwoWay"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:EndpointC"</span> /&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- camelSource will redirect the message coming for direct:EndpointB to the spring requestChannel channelA --&gt;</span></span>

<span class="code-tag">&lt;camel-si:camelSource id=<span class="code-quote">"camelSourceA"</span> camelEndpointUri=<span class="code-quote">"direct:EndpointB"</span> requestChannel=<span class="code-quote">"channelA"</span> expectReply=<span class="code-quote">"false"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelSourceContext<span class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelSource&gt;</span>

&lt;!-- camelSource will redirect the message coming for direct:EndpointC to the spring requestChannel channelB
 then it will pull the response from channelC and put the response message back to direct:EndpointC --&gt;

<span class="code-tag">&lt;camel-si:camelSource id=<span class="code-quote">"camelSourceB"</span> camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> requestChannel=<span class="code-quote">"channelB"</span> replyChannel=<span class="code-quote">"channelC"</span> expectReply=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelSourceContext<span class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelSource&gt;</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-StreamComponent"></a>Stream Component</h2>

<p>The <b>stream:</b> component provides access to the <tt>System.in</tt>, <tt>System.out</tt> and <tt>System.err</tt> streams as well as allowing streaming of file and URL.</p>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
stream:in[?options]
stream:out[?options]
stream:err[?options]
stream:header[?options]
</pre>
</div></div>

<p>In addition, the <tt>file</tt> and <tt>url</tt> endpoint URIs are supported in <b>Camel 2.0</b>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
stream:file?fileName=/foo/bar.txt
stream:url[?options]
</pre>
</div></div>

<p>If the <tt>stream:header</tt> URI is specified, the <tt>stream</tt> header is used to find the stream to write to. This option is available only for stream producers (that is, it cannot appear in <tt>from()</tt>).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Initial delay in milliseconds before consuming or producing the stream. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <em>JVM Default</em> </td>
<td class='confluenceTd'>  As of 1.4, you can configure the encoding (is a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" rel="nofollow">charset name</a>) to use text-based streams (for example, message body is a <tt>String</tt> object). If not provided, Camel uses the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()" rel="nofollow">JVM default Charset</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>promptMessage</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Message prompt to use when reading from <tt>stream:in</tt>; for example, you could set this to <tt>Enter a command:</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>promptMessageDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Optional delay in milliseconds before showing the message prompt. Can be used during system startup to avoid message prompts being written while other logging is done to the system out. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>promptDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Optional delay in milliseconds before showing the message prompt. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>promptInitialDelay</tt> </td>
<td class='confluenceTd'> <tt>2000</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Initial delay in milliseconds before showing the message prompt. This delay occurs only once. Can be used during system startup to avoid message prompts being written while other logging is done to the system out. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> When using the <tt>stream:file</tt> URI format, this option specifies the filename to stream to/from. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scanStream</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> To be used for continuously reading a stream such as the unit <tt>tail</tt> command. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scanStreamDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Delay in milliseconds between read attempts when using <tt>scanStream</tt>. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Messagecontent"></a>Message content</h3>

<p>The <b>stream:</b> component supports either <tt>String</tt> or <tt>byte[]</tt> for writing to streams. Just add either <tt>String</tt> or <tt>byte[]</tt> content to the <tt>message.in.body</tt>.<br/>
The special <tt>stream:header</tt> URI is used for custom output streams. Just add a <tt>java.io.OutputStream</tt> object to <tt>message.in.header</tt> in the key <tt>header</tt>.<br/>
See samples for an example.</p>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>In the following sample we route messages from the <tt>direct:in</tt> endpoint to the <tt>System.out</tt> stream:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Test
<span class="code-keyword">public</span> void testStringContent() <span class="code-keyword">throws</span> Exception {
    template.sendBody(<span class="code-quote">"direct:in"</span>, <span class="code-quote">"Hello Text World\n"</span>);
}

@Test
<span class="code-keyword">public</span> void testBinaryContent() {
    template.sendBody(<span class="code-quote">"direct:in"</span>, <span class="code-quote">"Hello Bytes World\n"</span>.getBytes());
}

<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            from(<span class="code-quote">"direct:in"</span>).to(<span class="code-quote">"stream:out"</span>);
        }
    };
}
</pre>
</div></div>

<p>The following sample demonstrates how the header type can be used to determine which stream to use. In the sample we use our own output stream, <tt>MyOutputStream</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">private</span> OutputStream mystream = <span class="code-keyword">new</span> MyOutputStream();
<span class="code-keyword">private</span> <span class="code-object">StringBuffer</span> sb = <span class="code-keyword">new</span> <span class="code-object">StringBuffer</span>();

@Test
<span class="code-keyword">public</span> void testStringContent() {
    template.sendBody(<span class="code-quote">"direct:in"</span>, <span class="code-quote">"Hello"</span>);
    <span class="code-comment">// StreamProducer appends \n in text mode
</span>    assertEquals(<span class="code-quote">"Hello\n"</span>, sb.toString());
}

@Test
<span class="code-keyword">public</span> void testBinaryContent() {
    template.sendBody(<span class="code-quote">"direct:in"</span>, <span class="code-quote">"Hello"</span>.getBytes());
    <span class="code-comment">// StreamProducer is in binary mode so no \n is appended
</span>    assertEquals(<span class="code-quote">"Hello"</span>, sb.toString());
}

<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            from(<span class="code-quote">"direct:in"</span>).setHeader(<span class="code-quote">"stream"</span>, constant(mystream)).
                to(<span class="code-quote">"stream:header"</span>);
        }
    };
}

<span class="code-keyword">private</span> class MyOutputStream <span class="code-keyword">extends</span> OutputStream {

    <span class="code-keyword">public</span> void write(<span class="code-object">int</span> b) <span class="code-keyword">throws</span> IOException {
        sb.append((<span class="code-object">char</span>)b);
    }
}
</pre>
</div></div>

<p>The following sample demonstrates how to continuously read a file stream (analogous to the UNIX <tt>tail</tt> command):</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"stream:file?fileName=/server/logs/server.log?scanStream=<span class="code-keyword">true</span>&amp;scanStreamDelay=1000"</span>).to(<span class="code-quote">"bean:logService?method=parseLogLine"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-StringTemplate"></a>String Template</h2>

<p>The <b>string-template:</b> component allows you to process a message using a <a href="http://www.stringtemplate.org/" rel="nofollow">String Template</a>. This can be ideal when using <a href="/confluence/display/CAMEL/Templating" title="Templating">Templating</a> to generate responses for requests.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
string-template:templateName[?options]
</pre>
</div></div>

<p>Where <b>templateName</b> is the classpath-local URI of the template to invoke; or the complete URL of the remote template.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentCache</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> New option in Camel 1.4. Cache for the resource content when its loaded. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Headers"></a>Headers</h3>
<p>Camel will store a reference to the resource in the message header with key, <tt>org.apache.camel.stringtemplate.resource</tt>. The Resource is an <tt>org.springframework.core.io.Resource</tt> object.</p>

<h3><a name="BookComponentAppendix-Hotreloading"></a>Hot reloading</h3>
<p>The string template resource is by default hot-reloadable for both file and classpath resources (expanded jar). If you set <tt>contentCache=true</tt>, Camel loads the resource only once and hot-reloading is not possible. This scenario can be used in production when the resource never changes.</p>

<h3><a name="BookComponentAppendix-StringTemplateAttributes"></a>StringTemplate Attributes</h3>
<p>Camel will provide exchange information as attributes (just a <tt>java.util.Map</tt>) to the string template. The Exchange is transfered as:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> key </th>
<th class='confluenceTh'> value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>exchange</tt> </td>
<td class='confluenceTd'> The Exchange itself. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headers</tt> </td>
<td class='confluenceTd'> The headers of the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelContext</tt> </td>
<td class='confluenceTd'> The Camel Context. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>in</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>body</tt> </td>
<td class='confluenceTd'> The In message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>out</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>response</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>For example you could use a string template as follows in order to formulate a response to a message:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"string-template:com/acme/MyResponse.tm"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-TheEmailSample"></a>The Email Sample</h3>
<p>In this sample we want to use a string template to send an order confirmation email. The email template is laid out in <tt>StringTemplate</tt> as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Dear $headers.lastName$, $headers.firstName$

Thanks <span class="code-keyword">for</span> the order of $headers.item$.

Regards Camel Riders Bookstore
$body$
</pre>
</div></div>

<p>And the java code is as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">private</span> Exchange createLetter() {
    Exchange exchange = context.getEndpoint(<span class="code-quote">"direct:a"</span>).createExchange();
    Message msg = exchange.getIn();
    msg.setHeader(<span class="code-quote">"firstName"</span>, <span class="code-quote">"Claus"</span>);
    msg.setHeader(<span class="code-quote">"lastName"</span>, <span class="code-quote">"Ibsen"</span>);
    msg.setHeader(<span class="code-quote">"item"</span>, <span class="code-quote">"Camel in Action"</span>);
    msg.setBody(<span class="code-quote">"PS: Next beer is on me, James"</span>);
    <span class="code-keyword">return</span> exchange;
}

@Test
<span class="code-keyword">public</span> void testVelocityLetter() <span class="code-keyword">throws</span> Exception {
    MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived(<span class="code-quote">"Dear Ibsen, Claus! Thanks <span class="code-keyword">for</span> the order of Camel in Action. Regards Camel Riders Bookstore PS: Next beer is on me, James"</span>);

    template.send(<span class="code-quote">"direct:a"</span>, createLetter());

    mock.assertIsSatisfied();
}

<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            from(<span class="code-quote">"direct:a"</span>).to(<span class="code-quote">"string-template:org/apache/camel/component/stringtemplate/letter.tm"</span>).to(<span class="code-quote">"mock:result"</span>);
        }
    };
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-SQLComponent"></a>SQL Component</h2>

<p>The <b>sql:</b> component allows you to work with databases using JDBC queries. The difference between this component and <a href="/confluence/display/CAMEL/JDBC" title="JDBC">JDBC</a> component is that in case of SQL the query is a property of the endpoint and it uses message payload as parameters passed to the query.</p>

<p>This component uses <tt>spring-jdbc</tt> behind the scenes for the actual SQL handling.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>The SQL component can only be used to define producer endpoints. In other words, you cannot define an SQL endpoint in a <tt>from()</tt> statement.</p></td></tr></table></div>

<p>The SQL component uses the following endpoint URI notation:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sql:select * from table where id=# order by name[?options]
</pre>
</div></div>

<p>Notice that the standard <tt>?</tt> symbol that denotes the parameters to an SQL query is substituted with the <tt>#</tt> symbol, because the <tt>?</tt> symbol is used to specify options for the endpoint.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>dataSourceRef</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5.1/2.0:</b> Reference to a <tt>DataSource</tt> to look up in the registry. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>template.&lt;xxx&gt;</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets additional options on the Spring <tt>JdbcTemplate</tt> that is used behind the scenes to execute the queries. For instance, <tt>template.maxRows=10</tt>. For detailed documentation, see the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html" rel="nofollow">JdbcTemplate javadoc</a> documentation. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Treatmentofthemessagebody"></a>Treatment of the message body</h3>

<p>The SQL component tries to convert the message body to an object of <tt>java.util.Iterator</tt> type and then uses this iterator to fill the query parameters (where each query parameter is represented by a <tt>#</tt> symbol in the endpoint URI). If the message body is not an array or collection, the conversion results in an iterator that iterates over only one object, which is the body itself.</p>

<p>For example, if the message body is an instance of <tt>java.util.List</tt>, the first item in the list is substituted into the first occurrence of <tt>#</tt> in the SQL query, the second item in the list is substituted into the second occurrence of <tt>#</tt>, and so on.</p>

<h3><a name="BookComponentAppendix-Resultofthequery"></a>Result of the query</h3>

<p>For <tt>select</tt> operations, the result is an instance of <tt>List&lt;Map&lt;String, Object&gt;&gt;</tt> type, as returned by the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html#queryForList(java.lang.String,%20java.lang.Object%91%93)" rel="nofollow">JdbcTemplate.queryForList()</a> method. For <tt>update</tt> operations, the result is the number of updated rows, returned as an <tt>Integer</tt>.</p>

<h3><a name="BookComponentAppendix-Headervalues"></a>Header values</h3>

<p>When performing <tt>update</tt> operations, the SQL Component stores the update count in the following message headers:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>SqlProducer.UPDATE_COUNT</tt> </td>
<td class='confluenceTd'> Camel 1.x: The number of rows updated for <tt>update</tt> operations, returned as an <tt>Integer</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSqlUpdateCount</tt> </td>
<td class='confluenceTd'> Camel 2.0: The number of rows updated for <tt>update</tt> operations, returned as an <tt>Integer</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSqlRowCount</tt> </td>
<td class='confluenceTd'> Camel 2.0: The number of rows returned for <tt>select</tt> operations, returned as an <tt>Integer</tt> object. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-ConfigurationinCamel1.5.0orlower"></a>Configuration in Camel 1.5.0 or lower</h3>

<p>The SQL component must be configured before it can be used. In Spring, you can configure it as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"sql"</span> class=<span class="code-quote">"org.apache.camel.component.sql.SqlComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"dataSource"</span> ref=<span class="code-quote">"myDS"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myDS"</span> class=<span class="code-quote">"org.springframework.jdbc.datasource.DriverManagerDataSource"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"driverClassName"</span> value=<span class="code-quote">"com.mysql.jdbc.Driver"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"url"</span> value=<span class="code-quote">"jdbc:mysql://localhost:3306/ds"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"username"</span> value=<span class="code-quote">"username"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"password"</span> /&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfigurationinCamel1.5.1orhigher"></a>Configuration in Camel 1.5.1 or higher</h3>
<p>You can now set a reference to a <tt>DataSource</tt> in the URI directly:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
sql:select * from table where id=# order by name?dataSourceRef=myDS
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>
<p>In the sample below we execute a query and retrieve the result as a <tt>List</tt> of rows, where each row is a <tt>Map&lt;String, Object</tt> and the key is the column name. </p>

<p>First, we set up a table to use for our sample. As this is based on an unit test, we do it java code:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// <span class="code-keyword">this</span> is the database we create with some initial data <span class="code-keyword">for</span> our unit test
</span>jdbcTemplate.execute(<span class="code-quote">"create table projects (id integer primary key,"</span>
                     + <span class="code-quote">"project varchar(10), license varchar(5))"</span>);
jdbcTemplate.execute(<span class="code-quote">"insert into projects values (1, 'Camel', 'ASF')"</span>);
jdbcTemplate.execute(<span class="code-quote">"insert into projects values (2, 'AMQ', 'ASF')"</span>);
jdbcTemplate.execute(<span class="code-quote">"insert into projects values (3, 'Linux', 'XXX')"</span>);
</pre>
</div></div>

<p>Then we configure our route and our <tt>sql</tt> component. Notice that we use a <tt>direct</tt> endpoint in front of the <tt>sql</tt> endpoint. This allows us to send an exchange to the <tt>direct</tt> endpoint with the URI, <tt>direct:simple</tt>, which is much easier for the client to use than the long <tt>sql:</tt> URI. Note that the <tt>DataSource</tt> is looked up up in the registry, so we can use standard Spring XML to configure our <tt>DataSource</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:simple"</span>)
    .to(<span class="code-quote">"sql:select * from projects where license = # order by id?dataSourceRef=jdbc/myDataSource"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>And then we fire the message into the <tt>direct</tt> endpoint that will route it to our <tt>sql</tt> component that queries the database.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
mock.expectedMessageCount(1);

<span class="code-comment">// send the query to direct that will route it to the sql where we will execute the query
</span><span class="code-comment">// and bind the parameters with the data from the body. The body only contains one value
</span><span class="code-comment">// in <span class="code-keyword">this</span> <span class="code-keyword">case</span> (XXX) but <span class="code-keyword">if</span> we should use multi values then the body will be iterated
</span><span class="code-comment">// so we could supply a List&lt;<span class="code-object">String</span>&gt; instead containing each binding value.
</span>template.sendBody(<span class="code-quote">"direct:simple"</span>, <span class="code-quote">"XXX"</span>);

mock.assertIsSatisfied();

<span class="code-comment">// the result is a List
</span>List received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());

<span class="code-comment">// and each row in the list is a Map
</span>Map row = assertIsInstanceOf(Map.class, received.get(0));

<span class="code-comment">// and we should be able the get the project from the map that should be Linux
</span>assertEquals(<span class="code-quote">"Linux"</span>, row.get(<span class="code-quote">"PROJECT"</span>));
</pre>
</div></div>

<p>We could configure the <tt>DataSource</tt> in Spring XML as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
 <span class="code-tag">&lt;jee:jndi-lookup id=<span class="code-quote">"myDS"</span> jndi-name=<span class="code-quote">"jdbc/myDataSource"</span>/&gt;</span> 
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/JDBC" title="JDBC">JDBC</a></li>
</ul>

<h2><a name="BookComponentAppendix-TestComponent"></a>Test Component</h2>

<a href="/confluence/display/CAMEL/Testing" title="Testing">Testing</a> of distributed and asynchronous processing is notoriously difficult. The <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a>, <a href="/confluence/display/CAMEL/Test" title="Test">Test</a> and <a href="/confluence/display/CAMEL/DataSet" title="DataSet">DataSet</a> endpoints work great with the <a href="/confluence/display/CAMEL/Testing" title="Testing">Camel Testing Framework</a> to simplify your unit and integration testing using <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise Integration Patterns">Enterprise Integration Patterns</a> and Camel's large range of <a href="/confluence/display/CAMEL/Components" title="Components">Components</a> together with the powerful <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a>.

<p>The <b>test</b> component extends the <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> component to support pulling messages from another endpoint on startup to set the expected message bodies on the underlying <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> endpoint. That is, you use the test endpoint in a route and messages arriving on it will be implicitly compared to some expected messages extracted from some other location.</p>

<p>So you can use, for example, an expected set of message bodies as files. This will then set up a properly configured <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> endpoint, which is only valid if the received messages match the number of expected messages and their message payloads are equal.</p>


<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
test:expectedMessagesEndpointUri
</pre>
</div></div>

<p>Where <b>expectedMessagesEndpointUri</b> refers to some other <a href="/confluence/display/CAMEL/Component" title="Component">Component</a> URI that the expected message bodies are pulled from before starting the test. </p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>

<p>For example, you could write a test case as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"seda:someEndpoint"</span>).
  to(<span class="code-quote">"test:file:<span class="code-comment">//data/expectedOutput?noop=<span class="code-keyword">true</span>"</span>);</span>
</pre>
</div></div>

<p>If your test then invokes the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#assertIsSatisfied(org.apache.camel.CamelContext)" rel="nofollow">MockEndpoint.assertIsSatisfied(camelContext) method</a>, your test case will perform the necessary assertions.</p>

<p>Here is a <a href="http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/test/TestEndpointTest.java?view=markup" rel="nofollow">real example test case using Mock and Spring</a> along with its <a href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/test/TestEndpointTest-context.xml" rel="nofollow">Spring XML</a>.</p>

<p>To see how you can set other expectations on the test endpoint, see the <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> component.</p>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Spring+Testing" title="Spring Testing">Spring Testing</a></li>
</ul>

<h2><a name="BookComponentAppendix-TimerComponent"></a>Timer Component</h2>

<p>The <b>timer:</b> component is used to generate message exchanges when a timer fires You can only consume events from this endpoint.  </p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
timer:name[?options]
</pre>
</div></div> 

<p>Where <tt>name</tt> is the name of the <tt>Timer</tt> object, which is created and shared across endpoints. So if you use the same name for all your timer endpoints, only one <tt>Timer</tt> object and thread will be used.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<p><b>Note:</b> The IN body of the generated exchange is <tt>null</tt>. So <tt>exchange.getIn().getBody()</tt> returns <tt>null</tt>.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Advanced Scheduler</b><br /><p>See also the <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a> component that supports much more advanced scheduling.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>time</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A <tt>java.util.Date</tt> the <b>first</b> event should be generated. If using the URI, the pattern expected is: <tt>yyyy-MM-dd HH:mm:ss</tt> or <tt>yyyy-MM-dd'T'HH:mm:ss</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> Allows you to specify a custom <tt>Date</tt> pattern to use for setting the time option using URI syntax. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>period</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> If greater than 0, generate periodic events every <tt>period</tt> milliseconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> The number of milliseconds to wait before the first event is generated. Should not be used in conjunction with the <tt>time</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fixedRate</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Events take place at approximately regular intervals, separated by the specified period. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>daemon</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether or not the thread associated with the timer endpoint runs as a daemon. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-ExchangeProperties"></a>Exchange Properties</h3>
<p>When the timer is fired, it adds the following information as properties to the <tt>Exchange</tt>:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.timer.name</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The value of the <tt>name</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.timer.time</tt> </td>
<td class='confluenceTd'> <tt>Date</tt> </td>
<td class='confluenceTd'> The value of the <tt>time</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.timer.period</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The value of the <tt>period</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.timer.firedTime</tt> </td>
<td class='confluenceTd'> <tt>Date</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5</b>: The time when the consumer fired. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>When the timer is fired, it adds the following information as headers to the IN message</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>firedTime</tt> </td>
<td class='confluenceTd'> <tt>java.util.Date</tt> </td>
<td class='confluenceTd'> Camel 1.5: The time when the consumer fired </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Sample"></a>Sample</h3>

<p>To set up a route that generates an event every 60 seconds:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   from(<span class="code-quote">"timer:<span class="code-comment">//foo?fixedRate=<span class="code-keyword">true</span>&amp;period=60000"</span>).to(<span class="code-quote">"bean:myBean?method=someMethodName"</span>);</span>
</pre>
</div></div>

<p>The above route will generate an event and then invoke the <tt>someMethodName</tt> method on the bean called <tt>myBean</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> such as JNDI or <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a>.</p>

<p>And the route in Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"timer://foo?fixedRate=true&amp;amp;period=60000"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myBean?method=someMethodName"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a></li>
</ul>


<h2><a name="BookComponentAppendix-ValidationComponent"></a>Validation Component</h2>

<p>The Validation component performs XML validation of the message body using the JAXP Validation API and based on any of the supported XML schema languages, which defaults to <a href="http://www.w3.org/XML/Schema" rel="nofollow">XML Schema</a> </p>

<p>Note that the <a href="/confluence/display/CAMEL/Jing" title="Jing">Jing</a> component also supports the following useful schema languages:</p>

<ul>
	<li><a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG Compact Syntax</a></li>
	<li><a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a></li>
</ul>


<p>The <a href="/confluence/display/CAMEL/MSV" title="MSV">MSV</a> component also supports <a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a>.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
validator:someLocalOrRemoteResource
</pre>
</div></div>

<p>Where <b>someLocalOrRemoteResource</b> is some URL to a local resource on the classpath or a full URL to a remote resource or resource on the file system which contains the XSD to validate against. For example:</p>

<ul>
	<li><tt>msv:org/foo/bar.xsd</tt></li>
	<li><tt>msv:<a href="file:../foo/bar.xsd" rel="nofollow">file:../foo/bar.xsd</a></tt></li>
	<li><tt>msv:<a href="http://acme.com/cheese.xsd" rel="nofollow">http://acme.com/cheese.xsd</a></tt></li>
	<li><tt>validator:com/mypackage/myschema.xsd</tt></li>
</ul>


<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>useDom</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether <tt>DOMSource</tt>/<tt>DOMResult</tt> or <tt>SaxSource</tt>/<tt>SaxResult</tt> should be used by the validator. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>

<p>The following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml" rel="nofollow">example</a> shows how to configure a route from endpoint <b>direct:start</b> which then goes to one of two endpoints, either <b>mock:valid</b> or <b>mock:invalid</b> based on whether or not the XML matches the given schema (which is supplied on the classpath).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;doTry&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"validator:org/apache/camel/component/validator/schema.xsd"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:valid"</span>/&gt;</span>
            <span class="code-tag">&lt;doCatch&gt;</span>
                <span class="code-tag">&lt;exception&gt;</span>org.apache.camel.ValidationException<span class="code-tag">&lt;/exception&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:invalid"</span>/&gt;</span>
            <span class="code-tag">&lt;/doCatch&gt;</span>
            <span class="code-tag">&lt;doFinally&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:finally"</span>/&gt;</span>
            <span class="code-tag">&lt;/doFinally&gt;</span>
        <span class="code-tag">&lt;/doTry&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<h2><a name="BookComponentAppendix-Velocity"></a>Velocity</h2>

<p>The <b>velocity:</b> component allows you to process a message using an <a href="http://velocity.apache.org/" rel="nofollow">Apache Velocity</a> template. This can be ideal when using <a href="/confluence/display/CAMEL/Templating" title="Templating">Templating</a> to generate responses for requests.</p>

<h3><a name="BookComponentAppendix-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
velocity:templateName[?options]
</pre>
</div></div>

<p>Where <b>templateName</b> is the classpath-local URI of the template to invoke; or the complete URL of the remote template (eg: <a href="file://folder/myfile.vm" rel="nofollow">file://folder/myfile.vm</a>).</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>loaderCache</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Velocity based file loader cache. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentCache</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> New option in Camel 1.4: Cache for the resource content when it is loaded. By default, it's <tt>false</tt> in Camel 1.x. By default, it's <tt>true</tt> in Camel 2.x. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> New option in Camel 1.6: Character encoding of the resource content. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>propertiesFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> New option in Camel 2.1: The URI of the properties file which is used for VelocityEngine initialization. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>

<p>The velocity component sets a couple headers on the message (you can't set these yourself and from Camel 2.1 velocity component will not set these headers which will cause some side effect on the dynamic template support):</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.velocity.resource</tt> </td>
<td class='confluenceTd'> Camel 1.x: The resource as an <tt>org.springframework.core.io.Resource</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.velocity.resourceUri</tt> </td>
<td class='confluenceTd'> Camel 1.x: The <b>templateName</b> as a <tt>String</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelVelocityResource</tt> </td>
<td class='confluenceTd'> Camel 2.0: The resource as an <tt>org.springframework.core.io.Resource</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelVelocityResourceUri</tt> </td>
<td class='confluenceTd'> Camel 2.0: The <b>templateName</b> as a <tt>String</tt> object. </td>
</tr>
</tbody></table>

<p>In Camel 1.4 headers set during the Velocity evaluation are returned to the message and added as headers. Then its kinda possible to return values from Velocity to the Message.</p>

<p>For example, to set the header value of <tt>fruit</tt> in the Velocity template <tt>.tm</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$in.setHeader('fruit', 'Apple')
</pre>
</div></div>

<p>The <tt>fruit</tt> header is now accessible from the <tt>message.out.headers</tt>.</p>

<h3><a name="BookComponentAppendix-VelocityContext"></a>Velocity Context</h3>
<p>Camel will provide exchange information in the Velocity context (just a <tt>Map</tt>). The <tt>Exchange</tt> is transfered as:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> key </th>
<th class='confluenceTh'> value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>exchange</tt> </td>
<td class='confluenceTd'> The <tt>Exchange</tt> itself. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headers</tt> </td>
<td class='confluenceTd'> The headers of the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelContext</tt> </td>
<td class='confluenceTd'> The Camel Context intance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>in</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>body</tt> </td>
<td class='confluenceTd'> The In message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>out</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>response</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Hotreloading"></a>Hot reloading</h3>
<p>The Velocity template resource is, by default, hot reloadable for both file and classpath resources (expanded jar). If you set <tt>contentCache=true</tt>, Camel will only load the resource once, and thus hot reloading is not possible. This scenario can be used in production, when the resource never changes.</p>

<h3><a name="BookComponentAppendix-Dynamictemplates"></a>Dynamic templates</h3>
<p><b>Available as of Camel 2.1</b><br/>
Camel provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> CamelVelocityResourceUri </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> A URI for the template resource to use instead of the endpoint configured. </td>
</tr>
<tr>
<td class='confluenceTd'> CamelVelocityTemplate </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The template to use instead of the endpoint configured. </td>
</tr>
</tbody></table>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>

<p>For example you could use something like</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"velocity:com/acme/MyResponse.vm"</span>);
</pre>
</div></div>

<p>To use a Velocity template to formulate a response to a message for InOut message exchanges (where there is a <tt>JMSReplyTo</tt> header).</p>

<p>If you want to use InOnly and consume the message and send it to another destination, you could use the following route:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  to(<span class="code-quote">"velocity:com/acme/MyResponse.vm"</span>).
  to(<span class="code-quote">"activemq:Another.Queue"</span>);
</pre>
</div></div>

<p>And to use the content cache, e.g. for use in production, where the <tt>.vm</tt> template never changes:</p>

<div class="code panel" style="border-