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 Wed, 20 Feb 2013 16:39:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Book+Component+Appendix">Book Component Appendix</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~leonid.kof">Leonid Kof</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{include:SNMP} <br>{include:SpringIntegration} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{include:Spring LDAP} <br></td></tr>
            <tr><td class="diff-unchanged" >{include:Spring Web Services} <br>{include:Stream} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div id="chapter-component-appendix" class="chapter"><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/" class="external-link" 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" class="external-link" rel="nofollow">Apache ActiveMQ</a>. </p>

<p>This component is based on <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>

<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>Transacted and caching</b><br />See section <em>Transactions and Cache Levels</em> below on <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> page if you are using transactions with <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as it can impact performance.</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">
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>This <a href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java" class="external-link" 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://activemq.apache.org/maven/5.5.0/activemq-camel/apidocs/org/apache/activemq/camel/component/ActiveMQComponent.html#activeMQComponent%28java.lang.String%29" class="external-link" rel="nofollow"><tt>activeMQComponent()</tt> method</a> while specifying the <a href="http://activemq.apache.org/configuring-transports.html" class="external-link" 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>

   &lt;bean id=<span class="code-quote">"activemq"</span> 
      class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;
      <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 ActiveMQ broker using Camel it's recommended to use a pooled connection factory to efficiently handle  pooling of JMS connections, sessions and producers. This is documented on the <a href="http://activemq.apache.org/spring-support.html" class="external-link" rel="nofollow">ActiveMQ Spring Support </a> page.</p>

<p>You can grab ActiveMQ's <tt>org.apache.activemq.pool.PooledConnectionFactory</tt> 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.apache.activemq<span class="code-tag">&lt;/groupId&gt;</span>
   <span class="code-tag">&lt;artifactId&gt;</span>activemq-pool<span class="code-tag">&lt;/artifactId&gt;</span>
   <span class="code-tag">&lt;version&gt;</span>5.6.0<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">
&lt;bean id=<span class="code-quote">"jmsConnectionFactory"</span> 
   class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;
   <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span class="code-quote">"tcp://localhost:61616"</span> /&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

&lt;bean id=<span class="code-quote">"pooledConnectionFactory"</span> 
   class=<span class="code-quote">"org.apache.activemq.pool.PooledConnectionFactory"</span> init-method=<span class="code-quote">"start"</span> destroy-method=<span class="code-quote">"stop"</span>&gt;
   <span class="code-tag">&lt;property name=<span class="code-quote">"maxConnections"</span> value=<span class="code-quote">"8"</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;/bean&gt;</span>

&lt;bean id=<span class="code-quote">"jmsConfig"</span> 
   class=<span class="code-quote">"org.apache.camel.component.jms.JmsConfiguration"</span>&gt;
   <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span class="code-quote">"pooledConnectionFactory"</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>

&lt;bean id=<span class="code-quote">"activemq"</span> 
    class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;
    <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>

<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>Notice the <b>init</b> and <b>destroy</b> methods on the pooled connection factory. This is important to ensure the connection pool is properly started and shutdown.</td></tr></table></div>

<p>The <tt>PooledConnectionFactory</tt> will then create a connection pool with up to 8 connections in use at the same time. Each connection can be shared by many sessions. There is an option named <tt>maxActive</tt> you can use to configure the maximum number of sessions per connection; the default value is <tt>500</tt>. From <b>ActiveMQ 5.7</b> onwards the option has been renamed to better reflect its purpose, being named as <tt>maxActiveSessionPerConnection</tt>. Notice the <tt>concurrentConsumers</tt> is set to a higher value than <tt>maxConnections</tt> is. This is okay, as each consumer is using a session, and as a session can share the same connection, we are in the safe. In this example we can have 8 * 500 = 4000 active sessions at the same time.</p>

<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-UsingActiveMQDestinationOptions"></a>Using ActiveMQ Destination Options</h3>
<p><b>Available as of ActiveMQ 5.6</b></p>

<p>You can configure the <a href="http://activemq.apache.org/destination-options.html" class="external-link" rel="nofollow">Destination Options</a> in the endpoint uri, using the "destination." prefix. For example to mark a consumer as exclusive, and set its prefetch size to 50, you can do 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 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;to uri=<span class="code-quote">"activemq:queue:foo"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use consumer.exclusive ActiveMQ destination option, notice we have to prefix with destination. --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:foo?destination.consumer.exclusive=true&amp;amp;destination.consumer.prefetchSize=50"</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-ConsumingAdvisoryMessages"></a>Consuming Advisory Messages</h3>

<p>ActiveMQ can generate <a href="http://activemq.apache.org/advisory-message.html" class="external-link" rel="nofollow">Advisory messages </a> which are put in topics that you can consume. Such messages can help you send alerts in case you detect slow consumers or to build statistics (number of messages/produced per day, etc.) The following Spring DSL example shows you how to read messages from a topic.</p>

<p>The below route starts by reading the topic <em>ActiveMQ.Advisory.Connection</em>. To watch another topic, simply change the name according to the name provided in ActiveMQ Advisory Messages documentation. The parameter mapJmsMessage=false allows for converting the org.apache.activemq.command.ActiveMqMessage object from the jms queue.  Next, the body received is converted into a String for the purposes of this example and a carriage return is added. Finally, the string is added to a file</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:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=<span class="code-keyword">false</span>"</span> /&gt;
   &lt;convertBodyTo type=<span class="code-quote">"java.lang.<span class="code-object">String</span>"</span>/&gt;
   &lt;transform&gt;
      &lt;simple&gt;${in.body}&amp;#13;&lt;/simple&gt;
   &lt;/transform&gt;
   &lt;to uri=<span class="code-quote">"file:<span class="code-comment">//data/activemq/?fileExist=Append&amp;amp;fileName=advisoryConnection-${date:now:yyyyMMdd}.txt"</span> /&gt;
</span>&lt;/route&gt;
</pre>
</div></div>

<p>If you consume a message on a queue, you should see the following files under the data/activemq folder :</p>

<p>advisoryConnection-20100312.txt<br/>
advisoryProducer-20100312.txt</p>

<p>and containing string:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ActiveMQMessage {commandId = 0, responseRequired = <span class="code-keyword">false</span>, 
messageId = ID:dell-charles-3258-1268399815140
-1:0:0:0:221, originalDestination = <span class="code-keyword">null</span>, originalTransactionId = <span class="code-keyword">null</span>,
producerId = ID:dell-charles-3258-1268399815140-1:0:0:0, 
destination = topic:<span class="code-comment">//ActiveMQ.Advisory.Connection, transactionId = <span class="code-keyword">null</span>, 
</span>expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 1268403383468, 
brokerOutTime = 1268403383468, correlationId = <span class="code-keyword">null</span>, replyTo = <span class="code-keyword">null</span>, 
persistent = <span class="code-keyword">false</span>, type = Advisory, priority = 0, groupID = <span class="code-keyword">null</span>, groupSequence = 0, 
targetConsumerId = <span class="code-keyword">null</span>, compressed = <span class="code-keyword">false</span>, userID = <span class="code-keyword">null</span>, content = <span class="code-keyword">null</span>, 
marshalledProperties = org.apache.activemq.util.ByteSequence@17e2705, 
dataStructure = ConnectionInfo {commandId = 1, responseRequired = <span class="code-keyword">true</span>, 
connectionId = ID:dell-charles-3258-1268399815140-2:50, 
clientId = ID:dell-charles-3258-1268399815140-14:0, userName = , password = *****, 
brokerPath = <span class="code-keyword">null</span>, brokerMasterConnector = <span class="code-keyword">false</span>, manageable = <span class="code-keyword">true</span>, 
clientMaster = <span class="code-keyword">true</span>}, redeliveryCounter = 0, size = 0, properties = 
{originBrokerName=master, originBrokerId=ID:dell-charles-3258-1268399815140-0:0, 
originBrokerURL=vm:<span class="code-comment">//master}, readOnlyProperties = <span class="code-keyword">true</span>, readOnlyBody = <span class="code-keyword">true</span>, 
</span>droppable = <span class="code-keyword">false</span>}
</pre>
</div></div>

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

<p>You will need this dependency</p>
<ul class="alternate" type="square">
	<li><tt>activemq-camel</tt></li>
</ul>


<p><a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> is an extension of the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component released with the <a href="http://activemq.apache.org" class="external-link" rel="nofollow">ActiveMQ project</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.activemq&lt;/groupId&gt;
  &lt;artifactId&gt;activemq-camel&lt;/artifactId&gt;
  &lt;version&gt;5.6.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-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 the 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 one 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</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-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" class="external-link" rel="nofollow">DefaultExchange</a> objects with the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#getIn()" class="external-link" rel="nofollow">in message</a> :</p>
<ul>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Message.html#getHeader(java.lang.String)" class="external-link" rel="nofollow">header</a> "journal" : set to the endpoint uri of the journal the message came from</li>
	<li><a href="http://camel.apache.org/maven/current//camel-core/apidocs/org/apache/camel/Message.html#getHeader(java.lang.String)" class="external-link" 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" class="external-link" rel="nofollow">Location</a> which identifies where the recored was stored on disk</li>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Message.html#getBody()" class="external-link" rel="nofollow">body</a> : set to <a href="http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/util/ByteSequence.html" class="external-link" 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://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html" class="external-link" 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" class="external-link" 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 <b>amqp:</b> component supports the <a href="http://www.amqp.org/" class="external-link" rel="nofollow">AMQP protocol</a> using the Client API of the <a href="http://qpid.apache.org/" class="external-link" rel="nofollow">Qpid</a> project.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-amqp<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>${camel.version}<span class="code-tag">&lt;/version&gt;</span> <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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-SQSComponent"></a>SQS Component</h2>
<p><b>Available as of Camel 2.6</b></p>

<p>The sqs component supports sending and receiving messages to <a href="http://aws.amazon.com/sqs" class="external-link" rel="nofollow">Amazon's SQS</a> service.</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>Prerequisites</b><br />You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SQS. More information are available at <a href="http://aws.amazon.com/sqs" class="external-link" rel="nofollow">Amazon SQS</a>.</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">
aws-sqs:<span class="code-comment">//queue-name[?options]</span>
</pre>
</div></div>
<p>The queue will be created if they don't already exists.<br/>
You can append query options to the URI in the following format, ?options=value&amp;option2=value&amp;...</p>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Context </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'>amazonSQSClient </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Reference to a <tt>com.amazonaws.services.sqs.AmazonSQSClient</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
<tr>
<td class='confluenceTd'>accessKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Amazon AWS Access Key </td>
</tr>
<tr>
<td class='confluenceTd'>secretKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Amazon AWS Secret Key </td>
</tr>
<tr>
<td class='confluenceTd'>amazonSQSEndpoint </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> The region with which the AWS-SQS client wants to work with. </td>
</tr>
<tr>
<td class='confluenceTd'>attributeNames </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> A list of attributes to set in the <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>defaultVisibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> The visibility timeout (in seconds) to set in the <tt>com.amazonaws.services.sqs.model.CreateQueueRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>deleteAfterRead </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> Delete message from SQS after it has been read </td>
</tr>
<tr>
<td class='confluenceTd'>maxMessagesPerPoll</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> The maximum number of messages which can be received in one poll to set in the <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>visibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>. This only make sense if its different from <tt>defaultVisibilityTimeout</tt>. It changes the queue visibility timeout attribute permanently. </td>
</tr>
<tr>
<td class='confluenceTd'>messageVisibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>. It does <b>NOT</b> change the queue visibility timeout attribute permanently. </td>
</tr>
<tr>
<td class='confluenceTd'> extendMessageVisibility </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> If enabled then a scheduled background task will keep extending the message visibility on SQS. This is needed if it taks a long time to process the message. If set to true <tt>defaultVisibilityTimeout</tt> must be set.  See details at <a href="http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryChangeMessageVisibility.html" class="external-link" rel="nofollow">Amazon docs</a>. </td>
</tr>
<tr>
<td class='confluenceTd'>maximumMessageSize </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The maximumMessageSize (in bytes) an SQS message can contain for this queue, to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>messageRetentionPeriod </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue, to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>policy </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The policy for this queue to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'>delaySeconds </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> Delay sending messages for a number of seconds. </td>
</tr>
<tr>
<td class='confluenceTd'>waitTimeSeconds </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Duration in seconds (0 to 20) that the ReceiveMessage action call will wait until a message is in the queue to include in the response. </td>
</tr>
<tr>
<td class='confluenceTd'>receiveMessageWaitTimeSeconds </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait. </td>
</tr>
</tbody></table>
</div>
</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>Required SQS component options</b><br />You have to provide the amazonSQSClient in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> or your accessKey and secretKey to access the <a href="http://aws.amazon.com/sqs" class="external-link" rel="nofollow">Amazon's SQS</a>.</td></tr></table></div>

<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>

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

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<h4><a name="BookComponentAppendix-MessageheaderssetbytheSQSproducer"></a>Message headers set by the SQS producer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>CamelAwsSqsMD5OfBody</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The MD5 checksum of the Amazon SQS message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMessageId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The Amazon SQS message ID. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-MessageheaderssetbytheSQSconsumer"></a>Message headers set by the SQS consumer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>CamelAwsSqsMD5OfBody</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The MD5 checksum of the Amazon SQS message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMessageId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The Amazon SQS message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsReceiptHandle</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>  The Amazon SQS message receipt handle. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsAttributes</tt> </td>
<td class='confluenceTd'> <tt>Map&lt;String, String&gt;</tt> </td>
<td class='confluenceTd'> The Amazon SQS message attributes. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-AdvancedAmazonSQSClientconfiguration"></a>Advanced AmazonSQSClient configuration</h4>
<p>If your Camel Application is running behind a firewall or if you need to have more control over the AmazonSQSClient configuration, you can create your own instance:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
AWSCredentials awsCredentials = <span class="code-keyword">new</span> BasicAWSCredentials(<span class="code-quote">"myAccessKey"</span>, <span class="code-quote">"mySecretKey"</span>);

ClientConfiguration clientConfiguration = <span class="code-keyword">new</span> ClientConfiguration();
clientConfiguration.setProxyHost(<span class="code-quote">"http:<span class="code-comment">//myProxyHost"</span>);
</span>clientConfiguration.setProxyPort(8080);

AmazonSQSClient client = <span class="code-keyword">new</span> AmazonSQSClient(awsCredentials, clientConfiguration);
</pre>
</div></div>

<p>and refer to it in your Camel aws-sqs component configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"aws-sqs:<span class="code-comment">//MyQueue?amazonSQSClient=#amazonSQSClient&amp;delay=5000&amp;maxMessagesPerPoll=5"</span>)
</span>.to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Dependencies"></a>Dependencies</h3>
<p>Maven users will need to add the following dependency to their pom.xml.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>pom.xml</b></div><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.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-aws<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>${camel-version}<span class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>where <tt>${camel-version</tt>} must be replaced by the actual version of Camel (2.6 or higher).</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/AWS" title="AWS">AWS Component</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 poll the feed every 60 seconds by default.<br/>
<b>Note:</b> The component currently only supports polling (consuming) feeds.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-atom<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>throttleEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Sets whether all entries identified in a single feed poll should be delivered immediately. If <tt>true</tt>, only one entry is processed per <tt>consumer.delay</tt>. Only applicable when <tt>splitEntries</tt> is set to <tt>true</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" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>
</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-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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAtomFeed</tt> </td>
<td class='confluenceTd'> When consuming the <tt>org.apache.abdera.model.Feed</tt> object is set to this header. </td>
</tr>
</tbody></table>
</div>
</div>

<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-keyword">protected</span> CamelContext createCamelContext() <span class="code-keyword">throws</span> Exception {

    <span class="code-comment">// First we register a blog service in our bean registry
</span>    SimpleRegistry registry = <span class="code-keyword">new</span> SimpleRegistry();
    registry.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(registry);

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

    <span class="code-keyword">return</span> context;
}

/**
 * This is the route builder where we create our routes using the Camel DSL
 */
<span class="code-keyword">protected</span> RouteBuilder createMyRoutes() <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">// create and start Camel
</span>    context = createCamelContext();
    context.start();

    <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 at least two good blog entries from the feed
</span>    mock.expectedMinimumMessageCount(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();

    <span class="code-comment">// stop Camel after use
</span>    context.stop();
}

/**
 * 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>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/RSS" title="RSS">RSS</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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 from the bean that will be invoked. If not provided, Camel will try to determine the method itself. In case of ambiguity an exception will be thrown. See <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> for more details. From <b>Camel 2.8</b> onwards you can specify type qualifiers to pin-point the exact method to use for overloaded methods. From <b>Camel 2.9</b> onwards you can specify parameter values directly in the method syntax. See more details at <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a>. </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'> 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>
</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-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, by registering 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/current/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html" class="external-link" 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 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-JavaDSLbeansyntax"></a>Java DSL bean syntax</h3>

<p>Java DSL comes with syntactic sugar for the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component. Instead of specifying the bean explicitly as the endpoint (i.e. <tt>to("bean:beanName")</tt>) you can use the following syntax:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// Send message to the bean endpoint
</span><span class="code-comment">// and invoke method resolved using Bean Binding.
</span>from(<span class="code-quote">"direct:start"</span>).beanRef(<span class="code-quote">"beanName"</span>);

<span class="code-comment">// Send message to the bean endpoint
</span><span class="code-comment">// and invoke given method.
</span>from(<span class="code-quote">"direct:start"</span>).beanRef(<span class="code-quote">"beanName"</span>, <span class="code-quote">"methodName"</span>);
</pre>
</div></div>

<p>Instead of passing name of the reference to the bean (so that Camel will lookup for it in the registry), you can specify the bean itself:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// Send message to the given bean instance.
</span>from(<span class="code-quote">"direct:start"</span>).bean(<span class="code-keyword">new</span> ExampleBean());

<span class="code-comment">// Explicit selection of bean method to be invoked.
</span>from(<span class="code-quote">"direct:start"</span>).bean(<span class="code-keyword">new</span> ExampleBean(), <span class="code-quote">"methodName"</span>);

<span class="code-comment">// Camel will create the instance of bean and cache it <span class="code-keyword">for</span> you.
</span>from(<span class="code-quote">"direct:start"</span>).bean(ExampleBean.class);
</pre>
</div></div>

<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/Class" title="Class">Class</a> component</li>
	<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-BeanValidationComponent"></a>Bean Validation Component</h2>

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

<p>The Validation component performs bean validation of the message body using the Java Bean Validation API (<a href="http://jcp.org/en/jsr/detail?id=303" class="external-link" rel="nofollow">JSR 303</a>). Camel uses the reference implementation, which is <a href="http://docs.jboss.org/hibernate/validator/4.3/reference/en-US/html_single/" class="external-link" rel="nofollow">Hibernate Validator</a>.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-bean-validator<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
bean-validator:something[?options]
</pre>
</div></div>

<p>or</p>

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

<p>Where <b>something</b> must be present to provide a valid url<br/>
You can append query options to the URI in the following format, ?option=value&amp;option=value&amp;...</p>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>group</tt> </td>
<td class='confluenceTd'> <tt>javax.validation.groups.Default</tt> </td>
<td class='confluenceTd'> The custom validation group to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageInterpolator</tt> </td>
<td class='confluenceTd'> <tt>org.hibernate.validator.engine.<br class="atl-forced-newline" />ResourceBundleMessageInterpolator</tt> </td>
<td class='confluenceTd'> Reference to a custom <tt>javax.validation.MessageInterpolator</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>traversableResolver</tt> </td>
<td class='confluenceTd'> <tt>org.hibernate.validator.engine.resolver.<br class="atl-forced-newline" />DefaultTraversableResolver</tt> </td>
<td class='confluenceTd'> Reference to a custom <tt>javax.validation.TraversableResolver</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>constraintValidatorFactory</tt> </td>
<td class='confluenceTd'> <tt>org.hibernate.validator.engine.<br class="atl-forced-newline" />ConstraintValidatorFactoryImpl</tt> </td>
<td class='confluenceTd'> Reference to a custom <tt>javax.validation.ConstraintValidatorFactory</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-ServiceMix4%2FOSGiDeployment."></a>ServiceMix4/OSGi Deployment.</h3>

<p>The bean-validator when deployed in an OSGi environment requires a little help to accommodate the resource loading specified in JSR303, this was fixed in Servicemix-Specs 1.6-SNAPSHOT.</p>

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

<p>Assumed we have a java bean with the following annotations</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Car.java</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class Car {

    @NotNull
    <span class="code-keyword">private</span> <span class="code-object">String</span> manufacturer;

    @NotNull
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    <span class="code-keyword">private</span> <span class="code-object">String</span> licensePlate;
    
    <span class="code-comment">// getter and setter
</span>}
</pre>
</div></div>

<p>and an interface definition for our custom validation group</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>OptionalChecks.java</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> OptionalChecks {
}
</pre>
</div></div>

<p>with the following Camel route, only the <b>@NotNull</b> constraints on the attributes manufacturer and licensePlate will be validated (Camel uses the default group <tt>javax.validation.groups.Default</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">"bean-validator:<span class="code-comment">//x"</span>)
</span>.to(<span class="code-quote">"mock:end"</span>)
</pre>
</div></div>

<p>If you want to check the constraints from the group <tt>OptionalChecks</tt>, you have to define the route like this</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">"bean-validator:<span class="code-comment">//x?group=OptionalChecks"</span>)
</span>.to(<span class="code-quote">"mock:end"</span>)
</pre>
</div></div>

<p>If you want to check the constraints from both groups, you have to define a new interface first</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>AllChecks.java</b></div><div class="codeContent panelContent">
<pre class="code-java">
@GroupSequence({Default.class, OptionalChecks.class})
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> AllChecks {
}
</pre>
</div></div>

<p>and then your route definition should looks like this</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">"bean-validator:<span class="code-comment">//x?group=AllChecks"</span>)
</span>.to(<span class="code-quote">"mock:end"</span>)
</pre>
</div></div>

<p>And if you have to provide your own message interpolator, traversable resolver and constraint validator factory, you have to write a route like this</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"myMessageInterpolator"</span> class=<span class="code-quote">"my.ConstraintValidatorFactory"</span> /&gt;
&lt;bean id=<span class="code-quote">"myTraversableResolver"</span> class=<span class="code-quote">"my.TraversableResolver"</span> /&gt;
&lt;bean id=<span class="code-quote">"myConstraintValidatorFactory"</span> class=<span class="code-quote">"my.ConstraintValidatorFactory"</span> /&gt;

from(<span class="code-quote">"direct:start"</span>)
.to("bean-validator:<span class="code-comment">//x?group=AllChecks&amp;messageInterpolator=#myMessageInterpolator
</span>&amp;traversableResolver=#myTraversableResolver&amp;constraintValidatorFactory=#myConstraintValidatorFactory")
.to(<span class="code-quote">"mock:end"</span>)
</pre>
</div></div>

<p>It's also possible to describe your constraints as XML and not as Java annotations. In this case, you have to provide the file <tt>META-INF/validation.xml</tt> which could looks like this</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>validation.xml</b></div><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;validation-config
	xmlns=<span class="code-quote">"http:<span class="code-comment">//jboss.org/xml/ns/javax/validation/configuration"</span>
</span>	xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema-instance"</span>
</span>	xsi:schemaLocation=<span class="code-quote">"http:<span class="code-comment">//jboss.org/xml/ns/javax/validation/configuration"</span>&gt;
</span>	&lt;<span class="code-keyword">default</span>-provider&gt;org.hibernate.validator.HibernateValidator&lt;/<span class="code-keyword">default</span>-provider&gt;
	&lt;message-interpolator&gt;org.hibernate.validator.engine.ResourceBundleMessageInterpolator&lt;/message-interpolator&gt;
	&lt;traversable-resolver&gt;org.hibernate.validator.engine.resolver.DefaultTraversableResolver&lt;/traversable-resolver&gt;
	&lt;constraint-validator-factory&gt;org.hibernate.validator.engine.ConstraintValidatorFactoryImpl&lt;/constraint-validator-factory&gt;
	
	&lt;constraint-mapping&gt;/constraints-car.xml&lt;/constraint-mapping&gt;
&lt;/validation-config&gt;
</pre>
</div></div>

<p>and the <tt>constraints-car.xml</tt> file</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>constraints-car.xml</b></div><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;constraint-mappings xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema-instance"</span>
</span>	xsi:schemaLocation=<span class="code-quote">"http:<span class="code-comment">//jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"</span>
</span>	xmlns=<span class="code-quote">"http:<span class="code-comment">//jboss.org/xml/ns/javax/validation/mapping"</span>&gt;
</span>	&lt;<span class="code-keyword">default</span>-<span class="code-keyword">package</span>&gt;org.apache.camel.component.bean.validator&lt;/<span class="code-keyword">default</span>-<span class="code-keyword">package</span>&gt;
	
	&lt;bean class=<span class="code-quote">"CarWithoutAnnotations"</span> ignore-annotations=<span class="code-quote">"<span class="code-keyword">true</span>"</span>&gt;
		&lt;field name=<span class="code-quote">"manufacturer"</span>&gt;
			&lt;constraint annotation=<span class="code-quote">"javax.validation.constraints.NotNull"</span> /&gt;
		&lt;/field&gt;
		
		&lt;field name=<span class="code-quote">"licensePlate"</span>&gt;
			&lt;constraint annotation=<span class="code-quote">"javax.validation.constraints.NotNull"</span> /&gt;
			
			&lt;constraint annotation=<span class="code-quote">"javax.validation.constraints.Size"</span>&gt;
				&lt;groups&gt;
					&lt;value&gt;org.apache.camel.component.bean.validator.OptionalChecks&lt;/value&gt;
				&lt;/groups&gt;
				&lt;element name=<span class="code-quote">"min"</span>&gt;5&lt;/element&gt;
				&lt;element name=<span class="code-quote">"max"</span>&gt;14&lt;/element&gt;
			&lt;/constraint&gt;
		&lt;/field&gt;
	&lt;/bean&gt;
&lt;/constraint-mappings&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-BrowseComponent"></a>Browse Component</h2>

<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, use the processors defined for the cache component.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-cache<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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=#beanRef&amp;...</tt></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 number 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 class="atl-forced-newline" />
 element never expires. </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 class="atl-forced-newline" />
 Is used only 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>false</tt> </td>
<td class='confluenceTd'> Whether the disk store persists between restarts of the Virtual Machine. </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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheManagerFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> If you want to use a custom factory which instantiates and creates the EHCache <tt>net.sf.ehcache.CacheManager</tt>. <br class="atl-forced-newline" />  <br class="atl-forced-newline" />  <em>Type:</em> abstract org.apache.camel.component.cache.CacheManagerFactory </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eventListenerRegistry</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Sets a list of EHCache <tt>net.sf.ehcache.event.CacheEventListener</tt> for all new caches&#45; no need to define it per cache in EHCache xml config anymore. <br class="atl-forced-newline" />  <br class="atl-forced-newline" />  <em>Type:</em> org.apache.camel.component.cache.CacheEventListenerRegistry </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLoaderRegistry</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Sets a list of <tt>org.apache.camel.component.cache.CacheLoaderWrapper</tt> that extends EHCache <tt>net.sf.ehcache.loader.CacheLoader</tt> for all new caches&#45; no need to define it per cache in EHCache xml config anymore. <br class="atl-forced-newline" />  <br class="atl-forced-newline" />  <em>Type:</em> org.apache.camel.component.cache.CacheLoaderRegistry </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>key</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> To configure using a cache key by default. If a key is provided in the message header, then the key from the header takes precedence. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>operation</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> To configure using an cache operation by default. If an operation in the message header, then the operation from the header takes precedence. </td>
</tr>
</tbody></table>
</div>
</div>

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

<h4><a name="BookComponentAppendix-MessageHeadersuptoCamel2.7"></a>Message Headers up to Camel 2.7</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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. Valid options are
<ul class="alternate" type="square">
	<li>GET</li>
	<li>CHECK</li>
	<li>ADD</li>
	<li>UPDATE</li>
	<li>DELETE</li>
	<li>DELETEALL<br class="atl-forced-newline" />
<tt>GET</tt> and <tt>CHECK</tt> requires <b>Camel 2.3</b> onwards. </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>
</div>
</div>

<h4><a name="BookComponentAppendix-MessageHeadersCamel2.8%5C"></a>Message Headers Camel 2.8&#43;</h4>

<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>Header changes in Camel 2.8</b><br />The header names and supported values have changed to be prefixed with 'CamelCache' and use mixed case.  This makes them easier to identify and keep separate from other headers.  The CacheConstants variable names remain unchanged, just their values have been changed.  Also, these headers are now removed from the exchange after the cache operation is performed.</td></tr></table></div>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelCacheOperation</tt> </td>
<td class='confluenceTd'> The operation to be performed on the cache. The valid options are
<ul class="alternate" type="square">
	<li>CamelCacheGet</li>
	<li>CamelCacheCheck</li>
	<li>CamelCacheAdd</li>
	<li>CamelCacheUpdate</li>
	<li>CamelCacheDelete</li>
	<li>CamelCacheDeleteAll</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelCacheKey</tt> </td>
<td class='confluenceTd'> The cache key used to store the Message in the cache. The cache key is optional if the CamelCacheOperation is CamelCacheDeleteAll </td>
</tr>
</tbody></table>
</div>
</div>

<p>The <tt>CamelCacheAdd</tt> and <tt>CamelCacheUpdate</tt> operations support additional headers: </p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>CamelCacheTimeToLive</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Time to live in seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelCacheTimeToIdle</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Time to idle in seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelCacheEternal</tt> </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Whether the content is eternal. </td>
</tr>
</tbody></table>
</div>
</div>


<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 CamelCacheGet/CamelCacheUpdate/CamelCacheDelete/CamelCacheDeleteAll). 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 CamelCacheDeleteAll operation, the Message Exchange Header CamelCacheKey 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(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD))
     .setHeader(CacheConstants.CACHE_KEY, 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(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_UPDATE))
     .setHeader(CacheConstants.CACHE_KEY, 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(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_DELETE))
     .setHeader(CacheConstants.CACHE_KEY<span class="code-quote">", constant("</span>Ralph_Waldo_Emerson"))
     .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(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_DELETEALL))
     .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(CacheConstants.CACHE_OPERATION);
           <span class="code-object">String</span> key = (<span class="code-object">String</span>) exchange.getIn().getHeader(CacheConstants.CACHE_KEY);
           <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(CacheConstants.CACHE_KEY).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(CacheConstants.CACHE_KEY).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(CacheConstants.CACHE_KEY).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>

<h4><a name="BookComponentAppendix-Example7%3AGettinganentryfromtheCache"></a>Example 7: Getting an entry from the Cache</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
    <span class="code-comment">// Prepare headers
</span>    .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET))
    .setHeader(CacheConstants.CACHE_KEY, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>)).
    .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>).
</span>    <span class="code-comment">// Check <span class="code-keyword">if</span> entry was not found
</span>    .choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNull()).
        <span class="code-comment">// If not found, get the payload and put it to cache
</span>        .to(<span class="code-quote">"cxf:bean:someHeavyweightOperation"</span>).
        .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD))
        .setHeader(CacheConstants.CACHE_KEY, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>))
        .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>    .end()
    .to(<span class="code-quote">"direct:nextPhase"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example8%3ACheckingforanentryintheCache"></a>Example 8: Checking for an entry in the Cache</h4>

<p>Note: The CHECK command tests existence of an entry in the cache but doesn't place a message in the body.</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>)
    <span class="code-comment">// Prepare headers
</span>    .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_CHECK))
    .setHeader(CacheConstants.CACHE_KEY, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>)).
    .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>).
</span>    <span class="code-comment">// Check <span class="code-keyword">if</span> entry was not found
</span>    .choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNull()).
        <span class="code-comment">// If not found, get the payload and put it to cache
</span>        .to(<span class="code-quote">"cxf:bean:someHeavyweightOperation"</span>).
        .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD))
        .setHeader(CacheConstants.CACHE_KEY, constant(<span class="code-quote">"Ralph_Waldo_Emerson"</span>))
        .to(<span class="code-quote">"cache:<span class="code-comment">//TestCache1"</span>)
</span>    .end();
</pre>
</div></div>


<h3><a name="BookComponentAppendix-ManagementofEHCache"></a>Management of EHCache</h3>

<p><a href="http://ehcache.org/" class="external-link" rel="nofollow">EHCache</a> has its own statistics and management from <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a>.</p>

<p>Here's a snippet on how to expose them via JMX in a Spring application context:</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">"ehCacheManagementService"</span> class=<span class="code-quote">"net.sf.ehcache.management.ManagementService"</span> init-method=<span class="code-quote">"init"</span> lazy-init=<span class="code-quote">"false"</span>&gt;</span>
  <span class="code-tag">&lt;constructor-arg&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"net.sf.ehcache.CacheManager"</span> factory-method=<span class="code-quote">"getInstance"</span>/&gt;</span>
  <span class="code-tag">&lt;/constructor-arg&gt;</span>
  <span class="code-tag">&lt;constructor-arg&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.springframework.jmx.support.JmxUtils"</span> factory-method=<span class="code-quote">"locateMBeanServer"</span>/&gt;</span>
  <span class="code-tag">&lt;/constructor-arg&gt;</span>
  <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"true"</span>/&gt;</span>
  <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"true"</span>/&gt;</span>
  <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"true"</span>/&gt;</span>
  <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"true"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Of course you can do the same thing in straight Java:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ManagementService.registerMBeans(CacheManager.getInstance(), mbeanServer, <span class="code-keyword">true</span>, <span class="code-keyword">true</span>, <span class="code-keyword">true</span>, <span class="code-keyword">true</span>);
</pre>
</div></div>

<p>You can get cache hits, misses, in-memory hits, disk hits, size stats this way. You can also change CacheConfiguration parameters on the fly.</p>

<h3><a name="BookComponentAppendix-CachereplicationCamel2.8%5C"></a>Cache replication Camel 2.8&#43;</h3>

<p>The Camel Cache component is able to distribute a cache across server nodes using several different replication mechanisms including: RMI, JGroups, JMS and Cache Server.</p>


<p>There are two different ways to make it work:</p>

<p><b>1.</b> You can configure <tt>ehcache.xml</tt> manually</p>

<p>OR</p>

<p><b>2.</b> You can configure these three options:</p>
<ul class="alternate" type="square">
	<li>cacheManagerFactory</li>
	<li>eventListenerRegistry</li>
	<li>cacheLoaderRegistry</li>
</ul>



<p>Configuring Camel Cache replication using the first option is a bit of hard work as you have to configure all caches separately. So in a situation when the all names of caches are not known, using <tt>ehcache.xml</tt> is not a good idea.</p>

<p>The second option is much better when you want to use many different caches as you do not need to define options per cache. This is because replication options are set per <tt>CacheManager</tt> and per <tt>CacheEndpoint</tt>. Also it is the only way when cache names are not know at the development phase.</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>It might be useful to read the <a href="http://ehcache.org/documentation" class="external-link" rel="nofollow">EHCache manual</a> to get a better understanding of the Camel Cache replication mechanism.</td></tr></table></div>

<h4><a name="BookComponentAppendix-Example%3AJMScachereplication"></a>Example: JMS cache replication</h4>

<p>JMS replication is the most powerful and secured replication method. Used together with Camel Cache replication makes it also rather simple.<br/>
An example is available on <a href="/confluence/display/CAMEL/cacheReplicationJMSExample" title="cacheReplicationJMSExample">a separate page</a>.</p>
<h2><a name="BookComponentAppendix-ClassComponent"></a>Class Component</h2>
<p><b>Available as of Camel 2.4</b></p>

<p>The <b>class:</b> component binds beans to Camel message exchanges. It works in the same way as the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component but instead of looking up beans from a <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> it creates the bean based on the class name.</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">
class:className[?options]
</pre>
</div></div>
<p>Where <b>className</b> is the fully qualified class name to create and use as bean.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>multiParameterArray</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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>
</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-Using"></a>Using</h3>

<p>You simply use the <b>class</b> component just as the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component but by specifying the fully qualified classname instead.<br/>
For example to use the <tt>MyFooBean</tt> you have to do as follows:</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">"class:org.apache.camel.component.bean.MyFooBean"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>You can also specify which method to invoke on the <tt>MyFooBean</tt>, for example <tt>hello</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">"class:org.apache.camel.component.bean.MyFooBean?method=hello"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<h2><a name="BookComponentAppendix-Settingpropertiesonthecreatedinstance"></a>Setting properties on the created instance</h2>

<p>In the endpoint uri you can specify properties to set on the created instance, for example if it has a <tt>setPrefix</tt> method:</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">"class:org.apache.camel.component.bean.MyPrefixBean?prefix=Bye"</span>)
        .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>And you can also use the <tt>#</tt> syntax to refer to properties to be looked up in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</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">"class:org.apache.camel.component.bean.MyPrefixBean?cool=#foo"</span>)
        .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>
<p>Which will lookup a bean from the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> with the id <tt>foo</tt> and invoke the <tt>setCool</tt> method on the created instance of the <tt>MyPrefixBean</tt> class.</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>See more</b><br />See more details at the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component as the <b>class</b> component works in much the same way.</td></tr></table></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/Bean" title="Bean">Bean</a></li>
	<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-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" class="external-link" rel="nofollow">jetty</a> implementation of the <a href="http://docs.codehaus.org/display/JETTY/Cometd+%28aka+Bayeux%29" class="external-link" 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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-cometd<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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" class="external-link" 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath. Classpath is required for OSGI deployment where the resources are packaged in the jar. Notice this option has been renamed to <tt>baseResource</tt> from <b>Camel 2.7</b> onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>baseResource</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.7:</b> The root directory for the web resources or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath. Classpath is required for OSGI deployment where the resources are packaged in the jar </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>
<tr>
<td class='confluenceTd'> sslContextParameters </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="http://camel.apache.org/registry.html" class="external-link" rel="nofollow">Registry</a>.&nbsp; This reference overrides any configured SSLContextParameters at the component level.&nbsp; See <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Using the JSSE Configuration Utility</a>. <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>crossOriginFilterOn</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> If <tt>true</tt>, the server will support for cross-domain filtering </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowedOrigins</tt> </td>
<td class='confluenceTd'> <tt>*</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> The origins domain that support to cross, if the <tt>crosssOriginFilterOn</tt> is <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filterPath</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.10:</b> The filterPath will be used by the CrossOriginFilter, if the <tt>crosssOriginFilterOn</tt> is <tt>true</tt> </td>
</tr>
</tbody></table>
</div>

</div>

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

<p>Here is some examples on How to pass the parameters</p>

<p>For file (for webapp resources located in the Web Application directory &#45;-&gt; cometd://localhost:8080?resourceBase=file./webapp<br/>
For classpath (when by example the web resources are packaged inside the webapp folder &#45;-&gt; cometd://localhost:8080?resourceBase=classpath:webapp</p>

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

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

<p>You can configure custom <tt>SecurityPolicy</tt> and <tt>Extension</tt>'s to the <tt>CometdComponent</tt> which allows you to use authentication as <a href="http://cometd.org/documentation/howtos/authentication" class="external-link" rel="nofollow">documented here</a></p>


<h3><a name="BookComponentAppendix-SettingupSSLforCometdComponent"></a>Setting up SSL for Cometd Component</h3>

<h4><a name="BookComponentAppendix-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h4>

<p>As of Camel 2.9, the Cometd component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp; This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels.&nbsp; The following examples demonstrate how to use the utility with the Cometd component.</p>

<h5><a name="BookComponentAppendix-Programmaticconfigurationofthecomponent"></a>Programmatic configuration of the component</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
KeyStoreParameters ksp = <span class="code-keyword">new</span> KeyStoreParameters();
ksp.setResource(<span class="code-quote">"/users/home/server/keystore.jks"</span>);
ksp.setPassword(<span class="code-quote">"keystorePassword"</span>);

KeyManagersParameters kmp = <span class="code-keyword">new</span> KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword(<span class="code-quote">"keyPassword"</span>);

TrustManagersParameters tmp = <span class="code-keyword">new</span> TrustManagersParameters();
tmp.setKeyStore(ksp);

SSLContextParameters scp = <span class="code-keyword">new</span> SSLContextParameters();
scp.setKeyManagers(kmp);
scp.setTrustManagers(tmp);

CometdComponent commetdComponent = getContext().getComponent(<span class="code-quote">"cometds"</span>, CometdComponent.class);
commetdComponent.setSslContextParameters(scp);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-SpringDSLbasedconfigurationofendpoint"></a>Spring DSL based configuration of endpoint</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
...
  &lt;camel:sslContextParameters
      id=<span class="code-quote">"sslContextParameters"</span>&gt;
    &lt;camel:keyManagers
        keyPassword=<span class="code-quote">"keyPassword"</span>&gt;
      &lt;camel:keyStore
          resource=<span class="code-quote">"/users/home/server/keystore.jks"</span>
          password=<span class="code-quote">"keystorePassword"</span>/&gt;
    <span class="code-tag">&lt;/camel:keyManagers&gt;</span>
    <span class="code-tag">&lt;camel:trustManagers&gt;</span>
      &lt;camel:keyStore
          resource=<span class="code-quote">"/users/home/server/keystore.jks"</span>
          password=<span class="code-quote">"keystorePassword"</span>/&gt;
    <span class="code-tag">&lt;/camel:keyManagers&gt;</span>
  <span class="code-tag">&lt;/camel:sslContextParameters&gt;</span>...
...
  <span class="code-tag">&lt;to uri=<span class="code-quote">"cometds://127.0.0.1:443/service/test?baseResource=file:./target/test-classes/webapp&amp;timeout=240000&amp;interval=0&amp;maxInterval=30000&amp;multiFrameInterval=1500&amp;jsonCommented=true&amp;logLevel=2&amp;sslContextParameters=#sslContextParameters"</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>

<h2><a name="BookComponentAppendix-ContextComponent"></a>Context Component</h2>

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

<p>The <b>context</b> component allows you to create new Camel Components from a CamelContext with a number of routes which is then treated as a black box, allowing you to refer to the local endpoints within the component from other CamelContexts.</p>

<p>It is similar to the <a href="/confluence/display/CAMEL/Routebox" title="Routebox">Routebox</a> component in idea, though the Context component tries to be really simple for end users; just a simple convention over configuration approach to refer to local endpoints inside the CamelContext Component.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-context<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
context:camelContextId:localEndpointName[?options]
</pre>
</div></div>

<p>Or you can omit the "context:" prefix.</p>

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

<ul>
	<li><b>camelContextId</b> is the ID you used to register the CamelContext into the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</li>
	<li><b>localEndpointName</b> can be a valid Camel URI evaluated within the black box CamelContext. Or it can be a logical name which is mapped to any local endpoints. For example if you locally have endpoints like <b>direct:invoices</b> and <b>seda:purchaseOrders</b> inside a CamelContext of id <b>supplyChain</b>, then you can just use the URIs <b>supplyChain:invoices</b> or <b>supplyChain:purchaseOrders</b> to omit the physical endpoint kind and use pure logical URIs.</li>
</ul>


<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-Example"></a>Example</h3>

<p>In this example we'll create a black box context, then we'll use it from another CamelContext.</p>

<h4><a name="BookComponentAppendix-Definingthecontextcomponent"></a>Defining the context component</h4>

<p>First you need to create a CamelContext, add some routes in it, start it and then register the CamelContext into the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> (JNDI, Spring, Guice or OSGi etc).</p>

<p>This can be done in the usual Camel way from this <a href="http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&amp;view=markup" class="external-link" rel="nofollow">test case</a> (see the createRegistry() method); this example shows Java and JNDI being used...</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// lets create our black box as a camel context and a set of routes
</span>DefaultCamelContext blackBox = <span class="code-keyword">new</span> DefaultCamelContext(registry);
blackBox.setName(<span class="code-quote">"blackBox"</span>);
blackBox.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
    @Override
    <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// receive purchase orders, lets process it in some way then send an invoice
</span>        <span class="code-comment">// to our invoice endpoint
</span>        from(<span class="code-quote">"direct:purchaseOrder"</span>).
          setHeader(<span class="code-quote">"received"</span>).constant(<span class="code-quote">"<span class="code-keyword">true</span>"</span>).
          to(<span class="code-quote">"direct:invoice"</span>);
    }
});
blackBox.start();

registry.bind(<span class="code-quote">"accounts"</span>, blackBox);
</pre>
</div></div>

<p>Notice in the above route we are using pure local endpoints (<b>direct</b> and <b>seda</b>). Also note we expose this CamelContext using the <b>accounts</b> ID. We can do the same thing in Spring via</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">"accounts"</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:purchaseOrder"</span>/&gt;</span>
    ...
    <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:invoice"</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-Usingthecontextcomponent"></a>Using the context component</h4>

<p>Then in another CamelContext we can then refer to this "accounts black box" by just sending to <b>accounts:purchaseOrder</b> and consuming from <b>accounts:invoice</b>.</p>

<p>If you prefer to be more verbose and explicit you could use <b>context:accounts:purchaseOrder</b> or even <b>context:accounts:direct://purchaseOrder</b> if you prefer. But using logical endpoint URIs is preferred as it hides the implementation detail and provides a simple logical naming scheme.</p>

<p>For example if we wish to then expose this accounts black box on some middleware (outside of the black box) we can do things like...</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"><span class="code-comment">&lt;!-- consume from an ActiveMQ into the black box --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:Accounts.PurchaseOrders"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"accounts:purchaseOrders"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
  <span class="code-tag">&lt;route&gt;</span> 
    <span class="code-tag"><span class="code-comment">&lt;!-- lets send invoices from the black box to a different ActiveMQ Queue --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"accounts:invoice"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:UK.Accounts.Invoices"</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-Namingendpoints"></a>Naming endpoints</h4>

<p>A context component instance can have many public input and output endpoints that can be accessed from outside it's CamelContext. When there are many it is recommended that you use logical names for them to hide the middleware as shown above.</p>

<p>However when there is only one input, output or error/dead letter endpoint in a component we recommend using the common posix shell names <b>in</b>, <b>out</b> and <b>err</b></p>
<h2><a name="BookComponentAppendix-CryptocomponentforDigitalSignatures"></a>Crypto component for Digital Signatures</h2>
<p><b>Available as of Camel 2.3</b></p>

<p>With Camel cryptographic endpoints and Java's Cryptographic extension it is easy to create Digital Signatures for <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>s. Camel provides a pair of flexible endpoints which get used in concert to create a signature for an exchange in one part of the exchange's workflow and then verify the signature in a later part of the workflow.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-crypto<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

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

<p>Digital signatures make use of Asymmetric Cryptographic techniques to sign messages. From a (very) high level, the algorithms use pairs of complimentary keys with the special property that data encrypted with one key can only be decrypted with the other. One, the private key, is closely guarded and used to 'sign' the message while the other, public key, is shared around to anyone interested in verifying the signed messages. Messages are signed by using the private key to encrypting a digest of the message. This encrypted digest is transmitted along with the message. On the other side the verifier recalculates the message digest and uses the public key to decrypt the the digest in the signature. If both digests match the verifier knows only the holder of the private key could have created the signature. </p>

<p>Camel uses the Signature service from the Java Cryptographic Extension to do all the heavy cryptographic lifting required to create exchange signatures. The following are some excellent resources for explaining the mechanics of Cryptography, Message digests and Digital Signatures and how to leverage them with the JCE.</p>

<ul class="alternate" type="square">
	<li>Bruce Schneier's Applied Cryptography</li>
	<li>Beginning Cryptography with Java by David Hook</li>
	<li>The ever insightful Wikipedia <a href="http://en.wikipedia.org/wiki/Digital_signature" class="external-link" rel="nofollow">Digital_signatures</a></li>
</ul>


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

<p>As mentioned Camel provides a pair of crypto endpoints to create and verify signatures</p>

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

<ul>
	<li><tt>crypto:sign</tt> creates the signature and stores it in the Header keyed by the constant <tt>Exchange.SIGNATURE</tt>, i.e. <tt>"CamelDigitalSignature"</tt>.</li>
	<li><tt>crypto:verify</tt> will read in the contents of this header and do the verification calculation.</li>
</ul>


<p>In order to correctly function, the sign and verify process needs a pair of keys to be shared, signing requiring a <tt>PrivateKey</tt> and verifying a <tt>PublicKey</tt> (or a <tt>Certificate</tt> containing one). Using the JCE it is very simple to generate these key pairs but it is usually most secure to use a KeyStore to house and share your keys. The DSL is very flexible about how keys are supplied and provides a number of mechanisms. </p>

<p>Note a <tt>crypto:sign</tt> endpoint is typically defined in one route and the complimentary <tt>crypto:verify</tt> in another, though for simplicity in the examples they appear one after the other. It goes without saying that both signing and verifying should be configured identically.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>algorithm</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>DSA</tt> </td>
<td class='confluenceTd'> The name of the JCE Signature algorithm that will be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alias</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> An alias name that will be used to select a key from the keystore. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <tt>2048</tt> </td>
<td class='confluenceTd'> the size of the buffer used in the signature process. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>certificate</tt> </td>
<td class='confluenceTd'> <tt>Certificate</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A Certificate used to verify the signature of the exchange's payload. Either this or a Public Key is required. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keystore</tt> </td>
<td class='confluenceTd'> <tt>KeyStore</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A reference to a JCE Keystore that stores keys and certificates used to sign and verify. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>provider</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The name of the JCE Security Provider that should be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>privateKey</tt> </td>
<td class='confluenceTd'> <tt>PrivatKey</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The private key used to sign the exchange's payload. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>publicKey</tt> </td>
<td class='confluenceTd'> <tt>PublicKey</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The public key used to verify the signature of the exchange's payload. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>secureRandom</tt> </td>
<td class='confluenceTd'> <tt>secureRandom</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A reference to a <tt>SecureRandom</tt> object that will be used to initialize the Signature service. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>char[]</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password for the keystore. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>clearHeaders</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Remove camel crypto headers from Message after a verify operation (value can be <tt>"true"</tt>/<tt>"false"</tt>). </td>
</tr>
</tbody></table>
</div>
</div>

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

<h4><a name="BookComponentAppendix-1%29Rawkeys"></a>1) Raw keys</h4>
<p>The most basic way to way to sign and verify an exchange is with a KeyPair as follows. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:keypair"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//basic?privateKey=#myPrivateKey"</span>, <span class="code-quote">"crypto:verify://basic?publicKey=#myPublicKey"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>The same can be achieved with the <a href="/confluence/display/CAMEL/Spring+XML+Extensions" title="Spring XML Extensions">Spring XML Extensions</a> using references to keys </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:keypair"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://basic?privateKey=#myPrivateKey"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://basic?publicKey=#myPublicKey"</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>

<h4><a name="BookComponentAppendix-2%29KeyStoresandAliases."></a>2) KeyStores and Aliases.</h4>
<p>The JCE provides a very versatile keystore concept for housing pairs of private keys and certificates, keeping them encrypted and password protected. They can be retrieved by applying an alias to the retrieval APIs. There are a number of ways to get keys and Certificates into a keystore, most often this is done with the external 'keytool' application. <a href="http://www.exampledepot.com/egs/java.security.cert/CreateCert.html" class="external-link" rel="nofollow">This</a> is a good example of using keytool to create a KeyStore with a self signed Cert and Private key.</p>

<p>The examples use a Keystore with a key and cert aliased by 'bob'. The password for the keystore and the key is 'letmein'</p>

<p>The following shows how to use a Keystore via the Fluent builders, it also shows how to load and initialize the keystore.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:keystore"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//keystore?keystore=#keystore&amp;alias=bob&amp;password=letmein"</span>, <span class="code-quote">"crypto:verify://keystore?keystore=#keystore&amp;alias=bob"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>Again in Spring a ref is used to lookup an actual keystore instance. </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:keystore"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://keystore?keystore=#keystore&amp;amp;alias=bob&amp;amp;password=letmein"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://keystore?keystore=#keystore&amp;amp;alias=bob"</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>

<h4><a name="BookComponentAppendix-3%29ChangingJCEProviderandAlgorithm"></a>3) Changing JCE Provider and Algorithm</h4>
<p>Changing the Signature algorithm or the Security provider is a simple matter of specifying their names. You will need to also use Keys that are compatible with the algorithm you choose.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyPairGenerator keyGen = KeyPairGenerator.getInstance(<span class="code-quote">"RSA"</span>);
keyGen.initialize(512, <span class="code-keyword">new</span> SecureRandom());
keyPair = keyGen.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();

<span class="code-comment">// we can set the keys explicitly on the endpoint instances.
</span>context.getEndpoint(<span class="code-quote">"crypto:sign:<span class="code-comment">//rsa?algorithm=MD5withRSA"</span>, DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
</span>context.getEndpoint(<span class="code-quote">"crypto:verify:<span class="code-comment">//rsa?algorithm=MD5withRSA"</span>, DigitalSignatureEndpoint.class).setPublicKey(publicKey);
</span>from(<span class="code-quote">"direct:algorithm"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//rsa?algorithm=MD5withRSA"</span>, <span class="code-quote">"crypto:verify://rsa?algorithm=MD5withRSA"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:provider"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//provider?privateKey=#myPrivateKey&amp;provider=SUN"</span>, <span class="code-quote">"crypto:verify://provider?publicKey=#myPublicKey&amp;provider=SUN"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>or</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:algorithm"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://rsa?algorithm=MD5withRSA&amp;amp;privateKey=#rsaPrivateKey"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://rsa?algorithm=MD5withRSA&amp;amp;publicKey=#rsaPublicKey"</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>
<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:provider"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://provider?privateKey=#myPrivateKey&amp;amp;provider=SUN"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://provider?publicKey=#myPublicKey&amp;amp;provider=SUN"</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>

<h4><a name="BookComponentAppendix-4%29ChangingtheSignatureMesasgeHeader"></a>4) Changing the Signature Mesasge Header</h4>
<p>It may be desirable to change the message header used to store the signature. A different header name can be specified in the route definition as follows</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:signature-header"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//another?privateKey=#myPrivateKey&amp;signatureHeader=AnotherDigitalSignature"</span>,
</span>                                   <span class="code-quote">"crypto:verify:<span class="code-comment">//another?publicKey=#myPublicKey&amp;signatureHeader=AnotherDigitalSignature"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>or</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:signature-header"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://another?privateKey=#myPrivateKey&amp;amp;signatureHeader=AnotherDigitalSignature"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://another?publicKey=#myPublicKey&amp;amp;signatureHeader=AnotherDigitalSignature"</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>

<h4><a name="BookComponentAppendix-5%29Changingthebuffersize"></a>5) Changing the buffersize</h4>
<p>In case you need to update the size of the buffer...</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:buffersize"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//buffer?privateKey=#myPrivateKey&amp;buffersize=1024"</span>, <span class="code-quote">"crypto:verify://buffer?publicKey=#myPublicKey&amp;buffersize=1024"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>or</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:buffersize"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://buffer?privateKey=#myPrivateKey&amp;amp;buffersize=1024"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://buffer?publicKey=#myPublicKey&amp;amp;buffersize=1024"</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>

<h4><a name="BookComponentAppendix-6%29SupplyingKeysdynamically."></a>6) Supplying Keys dynamically.</h4>
<p>When using a Recipient list or similar EIP the recipient of an exchange can vary dynamically. Using the same key across all recipients may be neither feasible nor desirable. It would be useful to be able to specify signature keys dynamically on a per-exchange basis. The exchange could then be dynamically enriched with the key of its target recipient prior to signing. To facilitate this the signature mechanisms allow for keys to be supplied dynamically via the message headers below </p>

<ul>
	<li><tt>Exchange.SIGNATURE_PRIVATE_KEY</tt>, <tt>"CamelSignaturePrivateKey"</tt></li>
	<li><tt>Exchange.SIGNATURE_PUBLIC_KEY_OR_CERT</tt>, <tt>"CamelSignaturePublicKeyOrCert"</tt></li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:headerkey-sign"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//alias"</span>);
</span>from(<span class="code-quote">"direct:headerkey-verify"</span>).to(<span class="code-quote">"crypto:verify:<span class="code-comment">//alias"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>or</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:headerkey-sign"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://headerkey"</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:headerkey-verify"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://headerkey"</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>

<p>Even better would be to dynamically supply a keystore alias. Again the alias can be supplied in a message header</p>
<ul>
	<li><tt>Exchange.KEYSTORE_ALIAS</tt>, <tt>"CamelSignatureKeyStoreAlias"</tt></li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:alias-sign"</span>).to(<span class="code-quote">"crypto:sign:<span class="code-comment">//alias?keystore=#keystore"</span>);
</span>from(<span class="code-quote">"direct:alias-verify"</span>).to(<span class="code-quote">"crypto:verify:<span class="code-comment">//alias?keystore=#keystore"</span>, <span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>or</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:alias-sign"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:sign://alias?keystore=#keystore"</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:alias-verify"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"crypto:verify://alias?keystore=#keystore"</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>

<p>The header would be set as follows</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Exchange unsigned = getMandatoryEndpoint(<span class="code-quote">"direct:alias-sign"</span>).createExchange();
unsigned.getIn().setBody(payload);
unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_ALIAS, <span class="code-quote">"bob"</span>);
unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, <span class="code-quote">"letmein"</span>.toCharArray());
template.send(<span class="code-quote">"direct:alias-sign"</span>, unsigned);
Exchange signed = getMandatoryEndpoint(<span class="code-quote">"direct:alias-sign"</span>).createExchange();
signed.getIn().copyFrom(unsigned.getOut());
signed.getIn().setHeader(KEYSTORE_ALIAS, <span class="code-quote">"bob"</span>);
template.send(<span class="code-quote">"direct:alias-verify"</span>, signed);
</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/Crypto" title="Crypto">Crypto</a> Crypto is also available as a <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data Format</a></li>
</ul>

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

<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>When using CXF as a consumer, the <a href="/confluence/display/CAMEL/CXF+Bean+Component" title="CXF Bean Component">CXF Bean Component</a> allows you to factor out how message payloads are received from their processing as a RESTful or SOAP web service. This has the potential of using a multitude of transports to consume web services. The bean component's configuration is also simpler and provides the fastest method to implement web services using Camel and CXF.</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>When using CXF in streaming modes (see DataFormat option), then also read about <a href="/confluence/display/CAMEL/Stream+caching" title="Stream caching">Stream caching</a>.</td></tr></table></div> 

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

<div>
<ul>
    <li><a href='#CXF-CXFComponent'>CXF Component</a></li>
<ul>
    <li><a href='#CXF-URIformat'>URI format</a></li>
    <li><a href='#CXF-Options'>Options</a></li>
<ul>
    <li><a href='#CXF-Thedescriptionsofthedataformats'>The descriptions of the dataformats</a></li>
<ul>
    <li><a href='#CXF-HowtoenableCXF%27sLoggingOutInterceptorinMESSAGEmode'>How to enable CXF's LoggingOutInterceptor in MESSAGE mode</a></li>
</ul>
    <li><a href='#CXF-DescriptionofrelayHeadersoption'>Description of relayHeaders option</a></li>
<ul>
    <li><a href='#CXF-AvailableonlyinPOJOmode'>Available only in POJO mode</a></li>
    <li><a href='#CXF-ChangessinceRelease2.0'>Changes since Release 2.0</a></li>
</ul>
</ul>
    <li><a href='#CXF-ConfiguretheCXFendpointswithSpring'>Configure the CXF endpoints with Spring</a></li>
    <li><a href='#CXF-ConfiguringtheCXFEndpointswithApacheAriesBlueprint.'>Configuring the CXF Endpoints with Apache Aries Blueprint.</a></li>
    <li><a href='#CXF-Howtomakethecamelcxfcomponentuselog4jinsteadofjava.util.logging'>How to make the camel-cxf component use log4j instead of java.util.logging</a></li>
    <li><a href='#CXF-Howtoletcamelcxfresponsemessagewithxmlstartdocument'>How to let camel-cxf response message with xml start document</a></li>
    <li><a href='#CXF-HowtoconsumeamessagefromacamelcxfendpointinPOJOdataformat'>How to consume a message from a camel-cxf endpoint in POJO data format</a></li>
    <li><a href='#CXF-HowtopreparethemessageforthecamelcxfendpointinPOJOdataformat'>How to prepare the message for the camel-cxf endpoint in POJO data format</a></li>
    <li><a href='#CXF-HowtodealwiththemessageforacamelcxfendpointinPAYLOADdataformat'>How to deal with the message for a camel-cxf endpoint in PAYLOAD data format</a></li>
    <li><a href='#CXF-HowtogetandsetSOAPheadersinPOJOmode'>How to get and set SOAP headers in POJO mode</a></li>
    <li><a href='#CXF-HowtogetandsetSOAPheadersinPAYLOADmode'>How to get and set SOAP headers in PAYLOAD mode</a></li>
    <li><a href='#CXF-SOAPheadersarenotavailableinMESSAGEmode'>SOAP headers are not available in MESSAGE mode</a></li>
    <li><a href='#CXF-HowtothrowaSOAPFaultfromCamel'>How to throw a SOAP Fault from Camel</a></li>
    <li><a href='#CXF-Howtopropagateacamelcxfendpoint%27srequestandresponsecontext'>How to propagate a camel-cxf endpoint's request and response context</a></li>
    <li><a href='#CXF-AttachmentSupport'>Attachment Support</a></li>
    <li><a href='#CXF-StreamingSupportinPAYLOADmode'>Streaming Support in PAYLOAD mode</a></li>
    <li><a href='#CXF-SeeAlso'>See Also</a></li>
</ul>
</ul></div>

<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 />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" class="external-link" rel="nofollow">WHICH-JARS</a></tt> text file.</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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Required </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>wsdlURL</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> The location of the WSDL. It is obtained from endpoint address by default. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: <a href="file://local/wsdl/hello.wsdl" class="external-link" rel="nofollow">file://local/wsdl/hello.wsdl</a> or <tt>wsdl/hello.wsdl</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClass</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> The name of the SEI (Service Endpoint Interface) class. This class can have, but does not require, JSR181 annotations. <br class="atl-forced-newline" /> This option is only required by POJO mode. If the wsdlURL option is provided, serviceClass is not required for PAYLOAD and MESSAGE mode. When wsdlURL option is used without serviceClass, the serviceName and portName (endpointName for Spring configuration) options <b>MUST</b> be provided. It is possible to use <tt>&#35;</tt> notation to reference a <tt>serviceClass</tt> object instance from the registry. E.g. <tt>serviceClass=#beanName</tt>. The <tt>serviceClass</tt> for a CXF producer (that is, the <tt>to</tt> endpoint) should be a Java interface.<br class="atl-forced-newline" /> <b>Since 2.8,</b> it is possible to omit both wsdlURL and serviceClass options for PAYLOAD and MESSAGE mode. When they are omitted, arbitrary XML elements can be put in CxfPayload's body in PAYLOAD mode to facilitate CXF Dispatch Mode. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> Please be advised that the <b>referenced object cannot be a Proxy</b> (Spring AOP Proxy is OK) as it relies on <tt>Object.getClass().getName()</tt> method for non Spring AOP Proxy. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: <tt>org.apache.camel.Hello</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> The service name this service is implementing, it maps to the <tt>wsdl:service@name</tt>. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <b>Required</b> for camel-cxf consumer since camel-2.2.0 or if more than one <tt>serviceName</tt> is present in WSDL. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: {http:­//org.apache.camel}ServiceName </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>portName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> The port name this service is implementing, it maps to the <tt>wsdl:port@name</tt>. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <b>Required</b> for camel-cxf consumer since camel-2.2.0 or if more than one <tt>portName</tt> is present under <tt>serviceName</tt>. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: {http:­//org.apache.camel}PortName </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>dataFormat</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> The data type messages supported by the CXF endpoint. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>POJO</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>POJO</tt>, <tt>PAYLOAD</tt>, <tt>MESSAGE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayHeaders</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Please see the <b>Description of</b> <tt><b>relayHeaders</b></tt> <b>option</b> section for this option.  Should a CXF endpoint relay headers along the route. Currently only available when <tt>dataFormat=POJO</tt> <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>true</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>true</tt>, <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wrapped</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Which kind of operation that CXF  endpoint producer will invoke <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>true</tt>, <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wrappedStyle</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <b>New in 2.5.0</b> The WSDL style that describes how parameters are represented in the SOAP body. If the value is false, CXF will chose the document-literal unwrapped style, If the value is true, CXF will chose the document-literal wrapped style <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>Null</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>true</tt>, <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Will set the default bus when CXF endpoint create a bus by itself <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>true</tt>, <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> A default bus created by CXF Bus Factory. 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 class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: <tt>bus=#busName</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxfBinding</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> 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> (use an instance of <tt>org.apache.camel.component.cxf.DefaultCxfBinding</tt>). <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: <tt>cxfBinding=#bindingName</tt> <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> 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> (use an instance of <tt>org.apache.camel.component.cxf.CxfHeaderFilterStrategy</tt>). <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Example</em>: <tt>headerFilterStrategy=#strategyName</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>loggingFeatureEnabled</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.3. This option enables CXF Logging Feature which writes inbound and outbound SOAP messages to log. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>loggingFeatureEnabled</tt><tt>=true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultOperationName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.4, this option will set the default operationName that will be used by the CxfProducer which invokes the remote service. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>null</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>defaultOperationName</tt><tt>=greetMe</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultOperationNamespace</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.4. This option will set the default operationNamespace that will be used by the CxfProducer which invokes the remote service. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>null</tt> <br class="atl-forced-newline" /> <em>Example</em>: <tt>defaultOperationNamespace</tt><tt>=</tt><tt><a href="http://apache.org/hello_world_soap_http" class="external-link" rel="nofollow">http://apache.org/hello_world_soap_http</a></tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>synchronous</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.5. This option will let cxf endpoint decide to use sync or async API to do the underlying work. The default value is false which means camel-cxf endpoint will try to use async API by default. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> <br class="atl-forced-newline" /> <em>Example</em>: synchronous=true </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>publishedEndpointUrl</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.5. This option can override the endpointUrl that published from the WSDL which can be accessed with service address url plus ?wsdl. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Default</em>: <tt>null</tt> <br class="atl-forced-newline" /> <em>Example</em>: publshedEndpointUrl=<a href="http://example.com/service" class="external-link" rel="nofollow">http://example.com/service</a> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>properties.XXX</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Allows to set custom properties to CXF in the endpoint uri. For example setting <tt>properties.mtom-enabled=true</tt> to enable MTOM. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowStreaming</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.8.2.   This option controls whether the CXF component, when running in PAYLOAD mode (see below), will DOM parse the incoming messages into DOM Elements or keep the payload as a javax.xml.transform.Source object that would allow streaming in some cases. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>skipFaultLogging</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> New in 2.11. This option controls whether the PhaseInterceptorChain skips logging the Fault that it catches. </td>
</tr>
</tbody></table>
</div>


<p>The <tt>serviceName</tt> and <tt>portName</tt> are <a href="http://en.wikipedia.org/wiki/QName" class="external-link" rel="nofollow">QNames</a>, so if you provide them be sure to prefix them with their {namespace} as shown in the examples above.</p>

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

<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<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. It is not suppose to touch or change Stream, some of the CXF interceptor will be removed if you are using this kind of DataFormat so you can't see any soap headers after the camel-cxf consumer and JAX-WS handler is not supported. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CXF_MESSAGE</tt> </td>
<td class='confluenceTd'> New in <b>Camel 2.8.2</b>, <tt>CXF_MESSAGE</tt> allows for invoking the full capabilities of CXF interceptors by converting the message from the transport layer into a raw SOAP message</td>
</tr>
</tbody></table>
</div>


<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></div>

<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">"target/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:${CXFTestSupport.port2}/LoggingInterceptorInMessageModeTest/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-AvailableonlyinPOJOmode"></a>Available 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" class="external-link" 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>.  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.common.header.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.common.header.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.common.header.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>.
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Required </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayHeaders</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> All message headers will be processed by Message Header Filters <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Type</em>: <tt>boolean</tt> <br class="atl-forced-newline" /> <em>Default</em>: <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayAllMessageHeaders</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> All message headers will be propagated (without processing by Message Header Filters) <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Type</em>: <tt>boolean</tt> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowFilterNamespaceClash</tt> </td>
<td class='confluenceTd'> No </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 <br class="atl-forced-newline" /> <br class="atl-forced-newline" /> <em>Type</em>: <tt>boolean</tt> <br class="atl-forced-newline" /> <em>Default</em>: <tt>false</tt> </td>
</tr>
</tbody></table>
</div>


<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-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>
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
     &lt;cxf:cxfEndpoint id=<span class="code-quote">"routerEndpoint"</span> address=<span class="code-quote">"http://localhost:9003/CamelContext/RouterPort"</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://localhost:9000/SoapContext/SoapPort"</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>
     	<span class="code-keyword">xmlns:s</span>=<span class="code-quote">"http://apache.org/hello_world_soap_http"</span> /&gt;
     <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;route&gt;</span>
         <span class="code-tag">&lt;from uri=<span class="code-quote">"cxf:bean:routerEndpoint"</span> /&gt;</span>
         <span class="code-tag">&lt;to uri=<span class="code-quote">"cxf:bean:serviceEndpoint"</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>

<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>
<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<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>
</div>


<p>It also supports many child elements:</p>
<div class='table-wrap'>
<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>
</div>
</div></li>
</ul>


<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" class="external-link" 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-ConfiguringtheCXFEndpointswithApacheAriesBlueprint."></a>Configuring the CXF Endpoints with Apache Aries Blueprint. </h3>

<p>Since camel 2.8 there is support for utilizing aries blueprint dependency injection for your CXF endpoints.<br/>
The schema utilized is very similar to the spring schema so the transition is fairly transparent.</p>

<p>Example</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">

&lt;blueprint xmlns=<span class="code-quote">"http://www.osgi.org/xmlns/blueprint/v1.0.0"</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:cm</span>=<span class="code-quote">"http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"</span>
           <span class="code-keyword">xmlns:camel-cxf</span>=<span class="code-quote">"http://camel.apache.org/schema/blueprint/cxf"</span>
	   <span class="code-keyword">xmlns:cxfcore</span>=<span class="code-quote">"http://cxf.apache.org/blueprint/core"</span>
           xsi:schemaLocation=<span class="code-quote">"http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"</span>&gt;

      &lt;camel-cxf:cxfEndpoint id=<span class="code-quote">"routerEndpoint"</span>
                     address=<span class="code-quote">"http://localhost:9001/router"</span>
                     serviceClass=<span class="code-quote">"org.apache.servicemix.examples.cxf.HelloWorld"</span>&gt;
        <span class="code-tag">&lt;camel-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;/camel-cxf:properties&gt;</span>
     <span class="code-tag">&lt;/camel-cxf:cxfEndpoint&gt;</span>

     &lt;camel-cxf:cxfEndpoint id=<span class="code-quote">"serviceEndpoint"</span>
			address=<span class="code-quote">"http://localhost:9000/SoapContext/SoapPort"</span>
                     serviceClass=<span class="code-quote">"org.apache.servicemix.examples.cxf.HelloWorld"</span>&gt;
    <span class="code-tag">&lt;/camel-cxf:cxfEndpoint&gt;</span>

    <span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/blueprint"</span>&gt;</span>
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"routerEndpoint"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"log:request"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;/blueprint&gt;</span>

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

<p>Currently the endpoint element is the first supported CXF namespacehandler.</p>

<p>You can also use the bean references just as in spring</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">

&lt;blueprint xmlns=<span class="code-quote">"http://www.osgi.org/xmlns/blueprint/v1.0.0"</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:cm</span>=<span class="code-quote">"http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"</span>
           <span class="code-keyword">xmlns:jaxws</span>=<span class="code-quote">"http://cxf.apache.org/blueprint/jaxws"</span>
           <span class="code-keyword">xmlns:cxf</span>=<span class="code-quote">"http://cxf.apache.org/blueprint/core"</span>
           <span class="code-keyword">xmlns:camel</span>=<span class="code-quote">"http://camel.apache.org/schema/blueprint"</span>
           <span class="code-keyword">xmlns:camelcxf</span>=<span class="code-quote">"http://camel.apache.org/schema/blueprint/cxf"</span>
           xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
             http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
             "&gt;

    &lt;camelcxf:cxfEndpoint id=<span class="code-quote">"reportIncident"</span>
                     address=<span class="code-quote">"/camel-example-cxf-blueprint/webservices/incident"</span>
                     wsdlURL=<span class="code-quote">"META-INF/wsdl/report_incident.wsdl"</span>
                     serviceClass=<span class="code-quote">"org.apache.camel.example.reportincident.ReportIncidentEndpoint"</span>&gt;
    <span class="code-tag">&lt;/camelcxf:cxfEndpoint&gt;</span>

    <span class="code-tag">&lt;bean id=<span class="code-quote">"reportIncidentRoutes"</span> class=<span class="code-quote">"org.apache.camel.example.reportincident.ReportIncidentRoutes"</span> /&gt;</span>

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

<span class="code-tag">&lt;/blueprint&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-Howtoletcamelcxfresponsemessagewithxmlstartdocument"></a>How to let camel-cxf response message with xml start document</h3>

<p>If you are using some soap client such as PHP, you will get this kind of error, because CXF doesn't add the XML start document "&lt;?xml version="1.0" encoding="utf-8"?&gt;"</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Error:sendSms: SoapFault exception: [Client] looks like we got no XML document in [...]
</pre>
</div></div>
<p>To resolved this issue, you just need to tell StaxOutInterceptor to write the XML start document for you.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">public class WriteXmlDeclarationInterceptor extends AbstractPhaseInterceptor<span class="code-tag">&lt;SoapMessage&gt;</span> {
    public WriteXmlDeclarationInterceptor() {
        super(Phase.PRE_STREAM);
        addBefore(StaxOutInterceptor.class.getName());
    }

    public void handleMessage(SoapMessage message) throws Fault {
        message.put(<span class="code-quote">"org.apache.cxf.stax.force-start-document"</span>, Boolean.TRUE);        
    }

}
</pre>
</div></div>
<p>You can add a customer interceptor like this and configure it into you camel-cxf endpont</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:${CXFTestSupport.port2}/CXFGreeterRouterTest/CamelContext/RouterPort"</span>
 		serviceClass=<span class="code-quote">"org.apache.hello_world_soap_http.GreeterImpl"</span>
 		skipFaultLogging=<span class="code-quote">"true"</span>&gt;
     <span class="code-tag">&lt;cxf:outInterceptors&gt;</span>
         <span class="code-tag"><span class="code-comment">&lt;!-- This interceptor will force the CXF server send the XML start document to client --&gt;</span></span>
         <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.WriteXmlDeclarationInterceptor"</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"><span class="code-comment">&lt;!-- Set the publishedEndpointUrl which could override the service address from generated WSDL as you want --&gt;</span></span>
 	    <span class="code-tag">&lt;entry key=<span class="code-quote">"publishedEndpointUrl"</span> value=<span class="code-quote">"http://www.simple.com/services/test"</span> /&gt;</span>
 	<span class="code-tag">&lt;/cxf:properties&gt;</span>
<span class="code-tag">&lt;/cxf:cxfEndpoint&gt;</span>
</pre>
</div></div>
<p>Or adding a message header for it like this if you are using <b>Camel 2.4</b>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
 <span class="code-comment">// set up the response context which force start document
</span> Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; map = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
 map.put(<span class="code-quote">"org.apache.cxf.stax.force-start-document"</span>, <span class="code-object">Boolean</span>.TRUE);
 exchange.getOut().setHeader(Client.RESPONSE_CONTEXT, map);
</pre>
</div></div>


<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" class="external-link" 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> Logger LOG = LoggerFactory.getLogger(PersonProcessor.class);

    @SuppressWarnings(<span class="code-quote">"unchecked"</span>)
    <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" class="external-link" 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>If you 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&lt;?, ?&gt;)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/>
<tt>Message.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(simpleEndpointURI + <span class="code-quote">"&amp;dataFormat=PAYLOAD"</span>).to(<span class="code-quote">"log:info"</span>).process(<span class="code-keyword">new</span> Processor() {
                @SuppressWarnings(<span class="code-quote">"unchecked"</span>)
                <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;Source&gt; inElements = requestPayload.getBodySources();
                    List&lt;Source&gt; outElements = <span class="code-keyword">new</span> ArrayList&lt;Source&gt;();
                    <span class="code-comment">// You can use a customer toStringConverter to turn a CxfPayLoad message into <span class="code-object">String</span> as you want                        
</span>                    <span class="code-object">String</span> request = exchange.getIn().getBody(<span class="code-object">String</span>.class);
                    XmlConverter converter = <span class="code-keyword">new</span> XmlConverter();
                    <span class="code-object">String</span> documentString = ECHO_RESPONSE;
                    
                    Element in = <span class="code-keyword">new</span> XmlConverter().toDOMElement(inElements.get(0));
                    <span class="code-comment">// Just check the element namespace
</span>                    <span class="code-keyword">if</span> (!in.getNamespaceURI().equals(ELEMENT_NAMESPACE)) {
                        <span class="code-keyword">throw</span> <span class="code-keyword">new</span> IllegalArgumentException(<span class="code-quote">"Wrong element namespace"</span>);
                    }
                    <span class="code-keyword">if</span> (in.getLocalName().equals(<span class="code-quote">"echoBoolean"</span>)) {
                        documentString = ECHO_BOOLEAN_RESPONSE;
                        checkRequest(<span class="code-quote">"ECHO_BOOLEAN_REQUEST"</span>, request);
                    } <span class="code-keyword">else</span> {
                        documentString = ECHO_RESPONSE;
                        checkRequest(<span class="code-quote">"ECHO_REQUEST"</span>, request);
                    }
                    Document outDocument = converter.toDOMDocument(documentString);
                    outElements.add(<span class="code-keyword">new</span> DOMSource(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, <span class="code-keyword">null</span>);
                    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>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 = CastUtils.<span class="code-keyword">cast</span>((List&lt;?&gt;)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>

<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>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(getRouterEndpointURI()).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;Source&gt; elements = payload.getBodySources();
        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());
        
        Element el = <span class="code-keyword">new</span> XmlConverter().toDOMElement(elements.get(0));
        elements.set(0, <span class="code-keyword">new</span> DOMSource(el));
        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>                el.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(getServiceEndpointURI());
</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>Same for using POJO data format. You can set the SOAPFault on the out body and also indicate it's a fault by calling Message.setFault(true):</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>).onException(SoapFault.class).maximumRedeliveries(0).handled(<span class="code-keyword">true</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 {
            SoapFault fault = exchange
                .getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
            exchange.getOut().setFault(<span class="code-keyword">true</span>);
            exchange.getOut().setBody(fault);
        }

    }).end().to(serviceURI);
</pre>
</div></div>

<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" class="external-link" 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 </p>
<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>

<p><b>Payload Mode:</b> MTOM is supported since 2.1.  Attachments can be retrieved by Camel Message APIs mentioned above.  SOAP with Attachment (SwA) is supported and attachments can be retrieved since 2.5. SwA is the default (same as setting the CXF endpoint property "mtom_enabled" to false).&nbsp;</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:${CXFTestSupport.port1}/CxfMtomRouterPayloadModeTest/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;Source&gt; elements = <span class="code-keyword">new</span> ArrayList&lt;Source&gt;();
        elements.add(<span class="code-keyword">new</span> DOMSource(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, <span class="code-keyword">null</span>);
        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 oute = <span class="code-keyword">new</span> XmlConverter().toDOMElement(out.getBody().get(0));
Element ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:DetailResponse/ns:photo/xop:Include"</span>, oute,
</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>, oute,
</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>        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 body = <span class="code-keyword">new</span> XmlConverter().toDOMElement(in.getBody().get(0));
        Element ele = (Element)xu.getValue(<span class="code-quote">"<span class="code-comment">//ns:Detail/ns:photo/xop:Include"</span>, body,
</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>        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>, body,
</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>        assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);

        DataHandler dr = exchange.getIn().getAttachment(photoId);
        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);
        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;Source&gt; elements = <span class="code-keyword">new</span> ArrayList&lt;Source&gt;();
        elements.add(<span class="code-keyword">new</span> DOMSource(DOMUtils.readXml(<span class="code-keyword">new</span> StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement()));
        CxfPayload&lt;SoapHeader&gt; sbody = <span class="code-keyword">new</span> CxfPayload&lt;SoapHeader&gt;(<span class="code-keyword">new</span> ArrayList&lt;SoapHeader&gt;(),
            elements, <span class="code-keyword">null</span>);
        exchange.getOut().setBody(sbody);
        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>


<h3><a name="BookComponentAppendix-StreamingSupportinPAYLOADmode"></a>Streaming Support in PAYLOAD mode</h3>

<p>In 2.8.2, the camel-cxf component now supports streaming of incoming messages when using PAYLOAD mode.  Previously, the incoming messages would have been completely DOM parsed.  For large messages, this is time consuming and uses a significant amount of memory.   Starting in 2.8.2, the incoming messages can remain as a javax.xml.transform.Source while being routed and, if nothing modifies the payload, can then be directly streamed out to the target destination.   For common "simple proxy" use cases (example:  from("cxf:...").to("cxf:...")), this can provide very significant performance increases as well as significantly lowered memory requirements. </p>

<p>However, there are cases where streaming may not be appropriate or desired.   Due to the streaming nature, invalid incoming XML may not be caught until later in the processing chain.   Also, certain actions may require the message to be DOM parsed anyway (like WS-Security or message tracing and such) in which case the advantages of the streaming is limited.   At this point, there are two ways to control the streaming:</p>

<ul>
	<li>Endpoint property:  you can add "allowStreaming=false" as an endpoint property to turn the streaming on/off.</li>
</ul>


<ul>
	<li>Component property: the CxfComponent object also has an allowStreaming property that can set the default for endpoints created from that component.</li>
</ul>


<ul>
	<li>Global system property: you can add a system property of "org.apache.camel.component.cxf.streaming" to "false" to turn if off.   That sets the global default, but setting the endpoint property above will override this value for that endpoint.</li>
</ul>





<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-CXFBeanComponent"></a>CXF Bean Component</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>

<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><tt>CxfBeanEndpoint</tt> is a <tt>ProcessorEndpoint</tt> so it has no consumers.  It works similarly to a Bean component.</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <tt>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'> <tt>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>
<tr>
<td class='confluenceTd'> <tt>populateFromClass</tt><br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> Since 2.3, the wsdlLocation annotated in the POJO is ignored (by default) unless this option is set to&nbsp; <tt>false.</tt> Prior to 2.3, the wsdlLocation annotated in the POJO is always honored and it is not possible to ignore.<br class="atl-forced-newline" /> </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>providers</tt> </td>
<td class='confluenceTd'> Since 2.5, setting the providers for the CXFRS endpoint. </td>
<td class='confluenceTd'><tt>providers=#providerRef1,#providerRef2</tt></td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>null</tt></td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-Headers"></a>Headers</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 class="atl-forced-newline" />
(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" class="external-link" 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 class="atl-forced-newline" /> </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> Out <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> 200 <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>
</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>Currently, CXF Bean component has (only) been tested with Jetty HTTP component it can understand headers from Jetty HTTP component without requiring conversion.</td></tr></table></div>

<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 ref=<span class="code-quote">"ep1"</span> /&gt;</span>
	<span class="code-tag">&lt;to uri=<span class="code-quote">"cxfbean:customerServiceBean"</span> /&gt;</span>
	<span class="code-tag">&lt;to uri=<span class="code-quote">"mock:endpointA"</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>

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

<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>When using CXF as a consumer, the <a href="/confluence/display/CAMEL/CXF+Bean+Component" title="CXF Bean Component">CXF Bean Component</a> allows you to factor out how message payloads are received from their processing as a RESTful or SOAP web service. This has the potential of using a multitude of transports to consume web services. The bean component's configuration is also simpler and provides the fastest method to implement web services using Camel and CXF.</td></tr></table></div>

<p>The <b>cxfrs:</b> component provides integration with <a href="http://incubator.apache.org/cxf/" class="external-link" 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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
   <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
   <span class="code-tag">&lt;artifactId&gt;</span>camel-cxf<span class="code-tag">&lt;/artifactId&gt;</span>
   <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>  <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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?resourceClasses=org.apache.camel.rs.Example
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>resourceClasses</tt> </td>
<td class='confluenceTd'> The resource classes which you want to export as REST service. Multiple classes can be separated by comma. </td>
<td class='confluenceTd'> <tt>resourceClasses =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>resourceClass</tt> </td>
<td class='confluenceTd'> <b>Deprecated</b>: Use <tt>resourceClasses</tt> The resource class which you want to export as REST service. </td>
<td class='confluenceTd'> <tt>resourceClass =org.apache.camel.rs.Example1</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 class="atl-forced-newline" />
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>
<tr>
<td class='confluenceTd'> synchronous </td>
<td class='confluenceTd'> New in 2.5, this option will let CxfRsConsumer decide to use sync or async API to do the underlying work. The default value is false which means it will try to use async API by default. </td>
<td class='confluenceTd'> synchronous=true </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> false </td>
</tr>
<tr>
<td class='confluenceTd'> throwExceptionOnFailure </td>
<td class='confluenceTd'> New in 2.6, this option tells the CxfRsProducer to inspect return codes and will generate an Exception if the return code is larger than 207. </td>
<td class='confluenceTd'> throwExceptionOnFailure=true </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxClientCacheSize</tt> </td>
<td class='confluenceTd'> New in 2.6, you can set a IN message header CamelDestinationOverrideUrl to dynamically override the target destination Web Service or REST Service defined in your routes.&nbsp; The implementation caches CXF clients or ClientFactoryBean in CxfProvider and CxfRsProvider.&nbsp; This option allows you to configure the maximum size of the cache. <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> maxClientCacheSize=5 </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> 10 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> New in 2.9.0. Will set the default bus when CXF endpoint create a bus by itself </td>
<td class='confluenceTd'> <tt>setDefaultBus=true</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.9.0. A default bus created by CXF Bus Factory. 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>. </td>
<td class='confluenceTd'> <tt>bus=#busName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
</tbody></table>
</div>
</div>

<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 provide 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" class="external-link" rel="nofollow">schema file</a> and <a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" class="external-link" rel="nofollow">CXF REST user guide</a> for more information.</p>

<h3><a name="BookComponentAppendix-HowtoconfiguretheRESTendpointinCamel"></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" class="external-link" 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.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">&lt;bean class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>/&gt;</span>

  <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:${CXFTestSupport.port2}/CxfRsRouterTest/rest"</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"><span class="code-comment">&lt;!--  bean id=<span class="code-quote">"jsonProvider"</span> class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.JSONProvider"</span>/--&gt;</span></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:${CXFTestSupport.port1}/CxfRsRouterTest/route"</span>
    serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span> 
    loggingFeatureEnabled=<span class="code-quote">"true"</span> loggingSizeLimit=<span class="code-quote">"20"</span> skipFaultLogging=<span class="code-quote">"true"</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:${CXFTestSupport.port2}/CxfRsRouterTest/rest"</span>
    serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span>
    loggingFeatureEnabled=<span class="code-quote">"true"</span> skipFaultLogging=<span class="code-quote">"true"</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-HowtoconsumetheRESTrequestinCamel"></a>How to consume the REST request in Camel</h3>

<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" class="external-link" rel="nofollow">CXF JAXRS front end</a> implements the <a href="https://jsr311.dev.java.net/" class="external-link" 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" class="external-link" 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 of a CXFRS route...</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">private</span> <span class="code-keyword">static</span> <span class="code-keyword">final</span> <span class="code-object">String</span> CXF_RS_ENDPOINT_URI = <span class="code-quote">"cxfrs:<span class="code-comment">//http://localhost:"</span> + CXT + <span class="code-quote">"/<span class="code-keyword">rest</span>?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource"</span>;
</span>
<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-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> path = inMessage.getHeader(Exchange.HTTP_PATH, <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 = inMessage.getBody(<span class="code-object">String</span>.class);
                        <span class="code-keyword">if</span> (<span class="code-quote">"/customerservice/customers/126"</span>.equals(path)) {                            
                            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> {
                            <span class="code-keyword">if</span> (<span class="code-quote">"/customerservice/customers/400"</span>.equals(path)) {
                                <span class="code-comment">// We <span class="code-keyword">return</span> the remote client IP address <span class="code-keyword">this</span> time
</span>                                org.apache.cxf.message.Message cxfMessage = inMessage.getHeader(CxfConstants.CAMEL_CXF_MESSAGE, org.apache.cxf.message.Message.class);
                                ServletRequest request = (ServletRequest) cxfMessage.get(<span class="code-quote">"HTTP.REQUEST"</span>);
                                <span class="code-object">String</span> remoteAddress = request.getRemoteAddr();
                                Response r = Response.status(200).entity(<span class="code-quote">"The remoteAddress is "</span> + remoteAddress).build();
                                exchange.getOut().setBody(r);
                                <span class="code-keyword">return</span>;
                            }
                            <span class="code-keyword">if</span> (<span class="code-quote">"/customerservice/customers/123"</span>.equals(path)) {
                                <span class="code-comment">// send a customer response back
</span>                                Response r = Response.status(200).entity(<span class="code-quote">"customer response back!"</span>).build();
                                exchange.getOut().setBody(r);
                                <span class="code-keyword">return</span>;
                            }
                            <span class="code-keyword">if</span> (<span class="code-quote">"/customerservice/customers/456"</span>.equals(path)) {
                                Response r = Response.status(404).entity(<span class="code-quote">"Can't found the customer with uri "</span> + path).build();
                                <span class="code-keyword">throw</span> <span class="code-keyword">new</span> WebApplicationException(r);
                            } <span class="code-keyword">else</span> {
                                <span class="code-keyword">throw</span> <span class="code-keyword">new</span> RuntimeCamelException(<span class="code-quote">"Can't found the customer with uri "</span> + path);
                            }
                        }
                    }
                    <span class="code-keyword">if</span> (<span class="code-quote">"updateCustomer"</span>.equals(operationName)) {
                        assertEquals(<span class="code-quote">"Get a wrong customer message header"</span>, <span class="code-quote">"header1;header2"</span>, inMessage.getHeader(<span class="code-quote">"test"</span>));
                        <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">"PUT"</span>, httpMethod);
                        Customer customer = inMessage.getBody(Customer.class);
                        assertNotNull(<span class="code-quote">"The customer should not be <span class="code-keyword">null</span>."</span>, customer);
                        <span class="code-comment">// Now you can <span class="code-keyword">do</span> what you want on the customer object
</span>                        assertEquals(<span class="code-quote">"Get a wrong customer name."</span>, <span class="code-quote">"Mary"</span>, customer.getName());
                        <span class="code-comment">// set the response back
</span>                        exchange.getOut().setBody(Response.ok().build());
                    }
                    
                }
                
            });
        }
    };
}
</pre>
</div></div>

<p>And the corresponding resource class used to configure the endpoint...</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>note about the resource class</b><br />This class is used to configure the JAXRS properties ONLY.  The methods will NOT be executed during the routing of messages to the endpoint, the route itself is responsible for ALL processing instead.</td></tr></table></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Path(<span class="code-quote">"/customerservice/"</span>)
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> CustomerServiceResource {

    @GET
    @Path(<span class="code-quote">"/customers/{id}/"</span>)
    Customer getCustomer(@PathParam(<span class="code-quote">"id"</span>) <span class="code-object">String</span> id);

    @PUT
    @Path(<span class="code-quote">"/customers/"</span>)
    Response updateCustomer(Customer customer);
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-HowtoinvoketheRESTservicethroughcamelcxfrsproducer"></a>How to invoke the REST service through camel-cxfrs producer</h3>

<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" class="external-link" rel="nofollow">CXF JAXRS front end</a> implements <a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-ProxybasedAPI" class="external-link" 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" class="external-link" 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();
        setupDestinationURL(inMessage);
        <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 a customer header
</span>        inMessage.setHeader(<span class="code-quote">"key"</span>, <span class="code-quote">"value"</span>);
        <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>);
assertEquals(<span class="code-quote">"Get a wrong response code"</span>, 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals(<span class="code-quote">"Get a wrong header value"</span>, <span class="code-quote">"value"</span>, exchange.getOut().getHeader(<span class="code-quote">"key"</span>));
</pre>
</div></div>
<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" class="external-link" rel="nofollow">CXF JAXRS front end</a> also provides <a href="http://cxf.apache.org/docs/jax-rs.html#JAX-RS-HTTPcentricclients" class="external-link" 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();
        setupDestinationURL(inMessage);
        <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">// set a customer header
</span>        inMessage.setHeader(<span class="code-quote">"key"</span>, <span class="code-quote">"value"</span>);
        <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>);
assertEquals(<span class="code-quote">"Get a wrong response code"</span>, 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals(<span class="code-quote">"Get a wrong header value"</span>, <span class="code-quote">"value"</span>, exchange.getOut().getHeader(<span class="code-quote">"key"</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.<br/>
<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:"</span> + getPort2() + <span class="code-quote">"/"</span> + getClass().getSimpleName() + <span class="code-quote">"/testQuery?httpClientAPI=<span class="code-keyword">true</span>&amp;q1=12&amp;q2=13"</span></span>
</pre>
</div></div>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 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/current/camel-core/apidocs/org/apache/camel/component/dataset/DataSet.html" class="external-link" 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/current/camel-core/apidocs/org/apache/camel/component/dataset/DataSet.html" class="external-link" 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
<tr>
<td class='confluenceTd'> <tt>minRate</tt> </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> Wait until the DataSet contains at least this number of messages </td>
</tr>
</tbody></table>
</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-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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</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/Spring+Testing" title="Spring Testing">Spring Testing</a></li>
</ul>

<h2><a name="BookComponentAppendix-Db4oComponent"></a>Db4o Component</h2>
<p><b>Available as of Camel 2.5</b></p>

<p>The <b>db4o:</b> component allows you to work with <a href="http://www.db4o.com" class="external-link" rel="nofollow">db4o</a> NoSQL database. The camel-db4o library is provided by the <a href="http://code.google.com/p/camel-extra/" class="external-link" 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 POJO object to the db4o endpoint adds and saves object into the database. The body of the message is assumed to be a POJO that has to be saved into the db40 database store.</p>

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

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

<p>If you do not wish to delete the object when it has been processed, you can specify <tt>consumeDelete=false</tt> on the URI. This will result in the POJO being processed each poll.</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">
db4o:className[?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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>consumeDelete</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>	Option for <tt>Db4oConsumer</tt> only. Specifies whether or not the entity is deleted after it is consumed.</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" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>
</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-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 />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.</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 />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>.</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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</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-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-DNS"></a>DNS</h2>
<p><b>Available as of Camel 2.7</b></p>

<p>This is an additional component for Camel to run DNS queries, using DNSJava. The component is a thin layer on top of <a href="http://www.xbill.org/dnsjava/" class="external-link" rel="nofollow">DNSJava</a>.<br/>
The component offers the following operations:</p>
<ul class="alternate" type="square">
	<li>ip, to resolve a domain by its ip</li>
	<li>lookup, to lookup information about the domain</li>
	<li>dig, to run DNS queries</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>Requires SUN JVM</b><br />The DNSJava library requires running on the SUN JVM.<br/>
If you use Apache ServiceMix or Apache Karaf, you'll need to adjust the <tt>etc/jre.properties</tt> file, to add <tt>sun.net.spi.nameservice</tt> to the list of Java platform packages exported. The server will need restarting before this change takes effect.</td></tr></table></div>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-dns<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

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

<p>The URI scheme for a DNS component is as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
dns:<span class="code-comment">//operation</span>
</pre>
</div></div>

<p>This component only supports producers.</p>

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

<p>None.</p>

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

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Operations </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> dns.domain </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> ip </td>
<td class='confluenceTd'> The domain name. Mandatory. </td>
</tr>
<tr>
<td class='confluenceTd'> dns.name </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> lookup </td>
<td class='confluenceTd'> The name to lookup. Mandatory. </td>
</tr>
<tr>
<td class='confluenceTd'> dns.type </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'>  lookup, dig </td>
<td class='confluenceTd'> The type of the lookup. Should match the values of <tt>org.xbill.dns.Type</tt>. Optional. </td>
</tr>
<tr>
<td class='confluenceTd'> dns.class </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> lookup, dig</td>
<td class='confluenceTd'> he DNS class of the lookup. Should match the values of <tt>org.xbill.dns.DClass</tt>. Optional. </td>
</tr>
<tr>
<td class='confluenceTd'> dns.query </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> dig </td>
<td class='confluenceTd'> The query itself. Mandatory. </td>
</tr>
<tr>
<td class='confluenceTd'> dns.server </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> dig </td>
<td class='confluenceTd'> The server in particular for the query. If none is given, the default one specified by the OS will be used. Optional. </td>
</tr>
</tbody></table>
</div>
</div>

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

<h4><a name="BookComponentAppendix-IPlookup"></a>IP lookup</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route id=<span class="code-quote">"IPCheck"</span>&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">"dns:ip"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>This looks up a domain's IP. For example, www.example.com resolves to 192.0.32.10.<br/>
The IP address to lookup must be provided in the header with key <tt>"dns.domain"</tt>.</p>

<h4><a name="BookComponentAppendix-DNSlookup"></a>DNS lookup</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route id=<span class="code-quote">"IPCheck"</span>&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">"dns:lookup"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>This returns a set of DNS records associated with a domain.<br/>
The name to lookup must be provided in the header with key <tt>"dns.name"</tt>.</p>

<h4><a name="BookComponentAppendix-DNSDig"></a>DNS Dig</h4>
<p>Dig is a Unix command-line utility to run DNS queries.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route id=<span class="code-quote">"IPCheck"</span>&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">"dns:dig"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>The query must be provided in the header with key <tt>"dns.query"</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-EJBComponent"></a>EJB Component</h2>
<p><b>Available as of Camel 2.4</b></p>

<p>The <b>ejb:</b> component binds EJBs to Camel message exchanges.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-ejb<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
ejb:ejbName[?options]
</pre>
</div></div>
<p>Where <b>ejbName</b> can be any string which is used to look up the EJB in the Application Server JNDI <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a></p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>multiParameterArray</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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>
</div>
</div>

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

<p>The <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a> component extends the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component in which most of the details from the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component applies to this component as well.</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-Examples"></a>Examples</h3>

<p>In the following examples we use the Greater EJB which is defined as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>GreaterLocal.java</b></div><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span class="code-keyword">interface</span> GreaterLocal {

    <span class="code-object">String</span> hello(<span class="code-object">String</span> name);

    <span class="code-object">String</span> bye(<span class="code-object">String</span> name);

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

<p>And the implementation</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>GreaterImpl.java</b></div><div class="codeContent panelContent">
<pre class="code-java">@Stateless
<span class="code-keyword">public</span> class GreaterImpl <span class="code-keyword">implements</span> GreaterLocal {

    <span class="code-keyword">public</span> <span class="code-object">String</span> hello(<span class="code-object">String</span> name) {
        <span class="code-keyword">return</span> <span class="code-quote">"Hello "</span> + name;
    }

    <span class="code-keyword">public</span> <span class="code-object">String</span> bye(<span class="code-object">String</span> name) {
        <span class="code-keyword">return</span> <span class="code-quote">"Bye "</span> + name;
    }

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

<h4><a name="BookComponentAppendix-UsingJavaDSL"></a>Using Java DSL</h4>

<p>In this example we want to invoke the <tt>hello</tt> method on the EJB. Since this example is based on an unit test using Apache OpenEJB we have to set a <tt>JndiContext</tt> on the <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a> component with the OpenEJB settings.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Override
<span class="code-keyword">protected</span> CamelContext createCamelContext() <span class="code-keyword">throws</span> Exception {
    CamelContext answer = <span class="code-keyword">new</span> DefaultCamelContext();

    <span class="code-comment">// enlist EJB component using the JndiContext
</span>    EjbComponent ejb = answer.getComponent(<span class="code-quote">"ejb"</span>, EjbComponent.class);
    ejb.setContext(createEjbContext());

    <span class="code-keyword">return</span> answer;
}

<span class="code-keyword">private</span> <span class="code-keyword">static</span> Context createEjbContext() <span class="code-keyword">throws</span> NamingException {
    <span class="code-comment">// here we need to define our context factory to use OpenEJB <span class="code-keyword">for</span> our testing
</span>    Properties properties = <span class="code-keyword">new</span> Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, <span class="code-quote">"org.apache.openejb.client.LocalInitialContextFactory"</span>);

    <span class="code-keyword">return</span> <span class="code-keyword">new</span> InitialContext(properties);
}
</pre>
</div></div>

<p>Then we are ready to use the EJB in the Camel route:</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>)
    <span class="code-comment">// invoke the greeter EJB using the local <span class="code-keyword">interface</span> and invoke the hello method
</span>    .to(<span class="code-quote">"ejb:GreaterImplLocal?method=hello"</span>)
    .to(<span class="code-quote">"mock:result"</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>In a real application server</b><br />In a real application server you most likely do not have to setup a <tt>JndiContext</tt> on the <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a> component as it will create a default <tt>JndiContext</tt> on the same JVM as the application server, which usually allows it to access the JNDI registry and lookup the <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a>s.<br/>
However if you need to access a application server on a remote JVM or the likes, you have to prepare the properties beforehand.</td></tr></table></div>

<h4><a name="BookComponentAppendix-UsingSpringXML"></a>Using Spring XML</h4>

<p>And this is the same example using Spring XML instead:</p>

<p>Again since this is based on an unit test we need to setup the <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a> component:</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;!-- setup Camel EJB component --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"ejb"</span> class=<span class="code-quote">"org.apache.camel.component.ejb.EjbComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"properties"</span> ref=<span class="code-quote">"jndiProperties"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- use OpenEJB context factory --&gt;</span></span>
<span class="code-tag">&lt;p:properties id=<span class="code-quote">"jndiProperties"</span>&gt;</span>
    <span class="code-tag">&lt;prop key=<span class="code-quote">"java.naming.factory.initial"</span>&gt;</span>org.apache.openejb.client.LocalInitialContextFactory<span class="code-tag">&lt;/prop&gt;</span>
<span class="code-tag">&lt;/p:properties&gt;</span>
</pre>
</div></div>

<p>Before we are ready to use <a href="/confluence/display/CAMEL/EJB" title="EJB">EJB</a> in the Camel routes:</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;to uri=<span class="code-quote">"ejb:GreaterImplLocal?method=hello"</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>



<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" title="Bean">Bean</a></li>
	<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-Esper"></a>Esper</h2>

<p>The Esper component supports the <a href="http://esper.codehaus.org" class="external-link" 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/" class="external-link" 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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" class="external-link" 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" class="external-link" rel="nofollow">Esper EQL expression</a> as a String to filter events </td>
</tr>
</tbody></table>
</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-Demo"></a>Demo</h3>

<p>There is a <a href="http://code.google.com/p/camel-extra/wiki/EsperDemo" class="external-link" 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/" class="external-link" 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" class="external-link" 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>

<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-FileComponent"></a>File Component</h2>

<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 />Camel supports only 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.</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 />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 and <tt>doneFileName</tt> option that you can use. See also the section <em>Consuming files from folders where others drop files directly</em>.</td></tr></table></div>

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

<h4><a name="BookComponentAppendix-Common"></a>Common</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 the files should be written to. </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>. From <b>Camel 2.11</b> onwards the producers support the <tt>CamelOverruleFileName</tt> header which takes precedence over any existing <tt>CamelFileName</tt> header; the <tt>CamelOverruleFileName</tt> is a header that is used only once, and makes it easier as this avoids to temporary store <tt>CamelFileName</tt> and have to restore it afterwards. </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>
<tr>
<td class='confluenceTd'> <tt>charset</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> this option is used to specify the encoding of the file, and camel will set the Exchange property with <tt>Exchange.CHARSET_NAME</tt> with the value of this option. You can use this on the consumer, to specify the encodings of the files, which allow Camel to know the charset it should load the file content in case the file content is being accessed. Likewise when writing a file, you can use this option to specify which charset to write the file as well. See further below for a examples and more important details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>copyAndDeleteOnRenameFail</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9</b>: whether to fallback and do a copy and delete file, in case the file could not be renamed directly. This option is not available for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-Consumer"></a>Consumer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'>&nbsp;</td>
<td class='confluenceTd'> Controls if fixed delay or fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. In <b>Camel 2.7.x</b> or older the default value is <tt>false</tt>. From <b>Camel 2.8</b> onwards the default value is <tt>true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>runLoggingLevel</tt> </td>
<td class='confluenceTd'> <tt>TRACE</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. </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'> <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>) used 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'> <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>) used 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'> <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>) used to dynamically set a different target directory when moving files after processing (configured via <tt>move</tt> defined above) failed. For example, to move files into a <tt>.error</tt> subdirectory use: <tt>.error</tt>. Note: When moving the files to the “fail” location Camel will <b>handle</b> the error and will not 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>antInclude</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Ant style filter inclusion, for example <tt>antInclude=&#42;</tt><tt><b>/</b></tt><tt>.txt</tt>. Multiple inclusions may be specified in comma-delimited format. See <a href="#BookComponentAppendix-FilteringusingANTpathmatcher">below</a> for more details about ant path filters. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>antExclude</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Ant style filter exclusion. If both <tt>antInclude</tt> and <tt>antExclude</tt> are used, <tt>antExclude</tt> takes precedence over <tt>antInclude</tt>. Multiple exclusions may be specified in comma-delimited format. See <a href="#BookComponentAppendix-FilteringusingANTpathmatcher">below</a> for more details about ant path filters. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>antFilterCaseSensitive</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Ant style filter which is case sensitive or not. </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>idempotentKey</tt> </td>
<td class='confluenceTd'> <tt>Expression</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use a custom idempotent key. By default the absolute path of the file is used. You can use the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>, for example to use the file name and file size, you can do: 
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">idempotentKey=${file:name}-${file:size}</pre>
</div></div>
<p>. </p></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idempotentRepository</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable repository <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html" class="external-link" rel="nofollow">org.apache.camel.spi.IdempotentRepository</a> which 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'> A pluggable in-progress repository <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html" class="external-link" rel="nofollow">org.apache.camel.spi.IdempotentRepository</a>. 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. 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" class="external-link" 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 class="atl-forced-newline" />
This option provides the build in strategies: <br class="atl-forced-newline" />  <tt>markerFile</tt> Camel creates a marker file and then holds a lock on it. This option is <b>not</b> available for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component. <br class="atl-forced-newline" />  <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. The option <tt>readLockCheckInterval</tt> can be used to set the check frequency. This option is <b>only</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component from <b>Camel 2.8</b> onwards. Notice that from <b>Camel 2.10.1</b> onwards the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> option <tt>fastExistsCheck</tt> can be enabled to speedup this readLock strategy, if the FTP server support the LIST operation with a full file name (some servers may not). <br class="atl-forced-newline" />  <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. This approach should be avoided when accessing a remote file system via a mount/share unless that file system supports distributed file locks. <br class="atl-forced-newline" />  <tt>rename</tt> is for using a try to rename the file as a test if we can get exclusive read-lock. <br class="atl-forced-newline" />  <tt>none</tt> is for no read locks at all. <br class="atl-forced-newline" />
Notice from <b>Camel 2.10</b> onwards the read locks <tt>changed</tt>, <tt>fileLock</tt> and <tt>rename</tt> will also use a <tt>markerFile</tt> as well, to ensure not picking up files that may be in process by another Camel consumer running on another node (eg cluster). This is only supported by the file component (not the ftp component). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLockTimeout</tt> </td>
<td class='confluenceTd'> <tt>10000</tt> </td>
<td class='confluenceTd'> Optional timeout in millis 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. Starting with <b>Camel 2.1</b> the default value is 10000. Currently <tt>fileLock</tt>, <tt>changed</tt> and <tt>rename</tt> support the timeout. <b>Notice:</b> For <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> the default <tt>readLockTimeout</tt> value is <tt>20000</tt> instead of <tt>10000</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLockCheckInterval</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Interval in millis for the read-lock, if supported by the read lock. This interval is used for sleeping between attempts to acquire the read lock. For example when using the <tt>changed</tt> read lock, you can set a higher interval period to cater for <em>slow writes</em>. The default of 1 sec. may be <em>too fast</em> if the producer is very slow writing the file. For <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> the default <tt>readLockCheckInterval</tt> is <tt>5000</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLockMinLength</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10.1:</b> This option applied only for <tt>readLock=changed</tt>. This option allows you to configure a minimum file length. By default Camel expects the file to contain data, and thus the default value is 1. You can set this option to zero, to allow consuming zero-length files. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>directoryMustExist</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Similar to <tt>startingDirectoryMustExist</tt> but this applies during polling recursive sub directories. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>doneFileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> If provided, Camel will only consume files if a <em>done</em> file exists. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders. The <em>done</em> file is <b>always</b> expected in the same folder as the original file. See <em>using done file</em> and <em>writing done file</em> sections for examples. </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>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> 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. See more details at <a href="/confluence/display/CAMEL/Batch+Consumer" title="Batch Consumer">Batch Consumer</a>. <b>Notice:</b> If this option is in use then the <a href="/confluence/display/CAMEL/File2" title="File2">File</a> and <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> components will limit <b>before</b> any sorting. For example if you have 100000 files and use <tt>maxMessagesPerPoll=500</tt>, then only the first 500 files will be picked up, and then sorted. You can use the <tt>eagerMaxMessagesPerPoll</tt> option and set this to <tt>false</tt> to allow to scan all files first and then sort afterwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eagerMaxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> Allows for controlling whether the limit from <tt>maxMessagesPerPoll</tt> is eager or not. If eager then the limit is during the scanning of files. Where as <tt>false</tt> would scan all files, and then perform sorting. Setting this option to <tt>false</tt> allows for sorting all files first, and then limit the poll. Mind that this requires a higher memory usage as all file details are in memory to perform the sorting. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>minDepth</tt> </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> <b>Camel 2.8</b>: The minimum depth to start processing when recursively processing a directory. Using <tt>minDepth=1</tt> means the base directory. Using <tt>minDepth=2</tt> means the first sub directory. This option is supported by <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> consumer from <b>Camel 2.8.2, 2.9</b> onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxDepth</tt> </td>
<td class='confluenceTd'> <tt>Integer.MAX_VALUE</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The maximum depth to traverse when recursively processing a directory. This option is supported by <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> consumer from <b>Camel 2.8.2, 2.9</b> onwards. </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>startingDirectoryMustExist</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Whether the starting directory must exist. Mind that the <tt>autoCreate</tt> option is default enabled, which means the starting directory is normally auto created if it doesn't exist. You can disable <tt>autoCreate</tt> and enable this to ensure the starting directory must exist. Will thrown an exception if the directory doesn't exist. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pollStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.apache.camel.PollingConsumerPollStrategy</tt> allowing you to provide your custom implementation to control error handling usually occurred during the <tt>poll</tt> operation <b>before</b> an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> have been created and being routed in Camel. In other words the error occurred while the polling was gathering information, for instance access to a file network failed so Camel cannot access it to scan for files. The default implementation will log the caused exception at <tt>WARN</tt> level and ignore it. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendEmptyMessageWhenIdle</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.bridgeErrorHandler</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Allows for bridging the consumer to the Camel routing <a href="/confluence/display/CAMEL/Error+Handler" title="Error Handler">Error Handler</a>, which mean any exceptions occurred while trying to pickup files, or the likes, will now be processed as a message and handled by the routing <a href="/confluence/display/CAMEL/Error+Handler" title="Error Handler">Error Handler</a>. By default the consumer will use the <tt>org.apache.camel.spi.ExceptionHandler</tt> to deal with exceptions, that by default will be logged at WARN/ERROR level and ignored. See further below on this page fore more details, at section <em>How to use the Camel error handler to deal with exceptions triggered outside the routing engine</em>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scheduledExecutorService</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. This option allows you to share a thread pool among multiple file consumers. </td>
</tr>
</tbody></table>
</div>
</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-Producer"></a>Producer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>, <b>Ignore</b>, and <tt><b>Move</b></tt>. <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. The <tt>Move</tt> option requires <b>Camel 2.10.1</b> onwards, and the corresponding <tt>moveExisting</tt> option to be configured as well. The option <tt>eagerDeleteTargetFile</tt> can be used to control what to do if an moving the file, and there exists already an existing file, otherwise causing the move operation to fail. The <tt>Move</tt> option will move any existing files, before writing the target file. </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>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>moveExisting</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10.1:</b> <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>) used to compute file name to use when <tt>fileExist=Move</tt> is configured. To move files into a <tt>backup</tt> subdirectory just enter <tt>backup</tt>. This option only supports the following <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> tokens: "file:name", "file:name.ext", "file:name.noext", "file:onlyname", "file:onlyname.noext", "file:ext", and "file:parent". Notice the "file:parent" is not supported by the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component, as the FTP component can only move any existing files to a relative directory based on current dir as base. </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>
<tr>
<td class='confluenceTd'> <tt>eagerDeleteTargetFile</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Whether or not to eagerly delete any existing target file. This option only applies when you use <tt>fileExists=Override</tt> and the <tt>tempFileName</tt> option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment, just before the temp file is being renamed to the target filename. From <b>Camel 2.10.1</b> onwards this option is also used to control whether to delete any existing files when <tt>fileExist=Move</tt> is enabled, and an existing file exists. If this option is false, then an exception will be thrown if an existing file existed, if its true, then the existing file is deleted before the move operation. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>doneFileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> If provided, then Camel will write a 2nd <em>done</em> file when the original file has been written. The <em>done</em> file will be empty. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders. The <em>done</em> file will <b>always</b> be written in the same folder as the original file. See <em>writing done file</em> section for examples. </td>
</tr>
<tr>
<td class='confluenceTd'><tt>allowNullBody</tt> </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.10.1:</b> Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created, when set to false, and attempting to send a null body to the file component, a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the `fileExist` option is set to 'Override', then the file will be truncated, and if set to `append` the file will remain unchanged. </td>
</tr>
</tbody></table>
</div>
</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.</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>&#45;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>${</tt><tt><a href="file:parent" class="external-link" rel="nofollow">file:parent</a></tt><tt>}/.done/${</tt><tt><a href="file:onlyname" class="external-link" 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/${</tt><tt><a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a></tt><tt>}-${date:now:yyyyMMddHHmmssSSS}.${</tt><tt><a href="file:ext" class="external-link" rel="nofollow">file: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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
<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>CamelOverruleFileName</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Is used for overruling <tt>CamelFileName</tt> header and use the value instead (but only once, as the producer will remove this header after writing the file). The value can be only be a String. Notice that if the option <tt>fileName</tt> has been configured, then this is still being evaluated. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-Fileconsumeronly"></a>File consumer only</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>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>
</div>
</div>

<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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<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/Aggregator2" title="Aggregator2">Aggregator2</a> aggregate this number of files.</p>

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

<p><b>Available as of Camel 2.9.3</b><br/>
The charset option allows for configuring an encoding of the files on both the consumer and producer endpoints. For example if you read utf-8 files, and want to convert the files to iso-8859-1, 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">"file:inbox?charset=utf-8"</span>)
  .to(<span class="code-quote">"file:outbox?charset=iso-8859-1"</span>)
</pre>
</div></div>

<p>You can also use the <tt>convertBodyTo</tt> in the route. In the example below we have still input files in utf-8 format, but we want to convert the file content to a byte array in iso-8859-1 format. And then let a bean process the data. Before writing the content to the outbox folder using the current charset.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:inbox?charset=utf-8"</span>)
  .convertBodyTo(<span class="code-object">byte</span>[].class, <span class="code-quote">"iso-8859-1"</span>)
  .to(<span class="code-quote">"bean:myBean"</span>)
  .to(<span class="code-quote">"file:outbox"</span>);
</pre>
</div></div>

<p>If you omit the charset on the consumer endpoint, then Camel does not know the charset of the file, and would by default use "UTF-8". However you can configure a JVM system property to override and use a different default encoding with the key <tt>org.apache.camel.default.charset</tt>.</p>

<p>In the example below this could be a problem if the files is not in UTF-8 encoding, which would be the default encoding for read the files.<br/>
In this example when writing the files, the content has already been converted to a byte array, and thus would write the content directly as is (without any further encodings).</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:inbox"</span>)
  .convertBodyTo(<span class="code-object">byte</span>[].class, <span class="code-quote">"iso-8859-1"</span>)
  .to(<span class="code-quote">"bean:myBean"</span>)
  .to(<span class="code-quote">"file:outbox"</span>);
</pre>
</div></div>

<p>You can also override and control the encoding dynamic when writing files, by setting a property on the exchange with the key <tt>Exchange.CHARSET_NAME</tt>. For example in the route below we set the property with a value from a message header.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:inbox"</span>)
  .convertBodyTo(<span class="code-object">byte</span>[].class, <span class="code-quote">"iso-8859-1"</span>)
  .to(<span class="code-quote">"bean:myBean"</span>)
  .setProperty(Exchange.CHARSET_NAME, header(<span class="code-quote">"someCharsetHeader"</span>))
  .to(<span class="code-quote">"file:outbox"</span>);
</pre>
</div></div>

<p>We suggest to keep things simpler, so if you pickup files with the same encoding, and want to write the files in a specific encoding, then favor to use the <tt>charset</tt> option on the endpoints.</p>

<p>Notice that if you have explicit configured a <tt>charset</tt> option on the endpoint, then that configuration is used, regardless of the <tt>Exchange.CHARSET_NAME</tt> property.</p>

<p>If you have some issues then you can enable DEBUG logging on <tt>org.apache.camel.component.file</tt>, and Camel logs when it reads/write a file using a specific charset.<br/>
For example the route below will log the following:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:inbox?charset=utf-8"</span>)
  .to(<span class="code-quote">"file:outbox?charset=iso-8859-1"</span>)
</pre>
</div></div>
<p>And the logs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
DEBUG GenericFileConverter           - Read file /Users/davsclaus/workspace/camel/camel-core/target/charset/input/input.txt with charset utf-8
DEBUG FileOperations                 - Using Reader to write file: target/charset/output.txt with charset: iso-8859-1
</pre>
</div></div>

<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. You may also want to look at the <tt>doneFileName</tt> option, which uses a marker file (done) to signal when a file is done and ready to be consumed.</p>


<h3><a name="BookComponentAppendix-Usingdonefiles"></a>Using done files</h3>

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

<p>See also section <em>writing done files</em> below.</p>

<p>If you want only to consume files when a done file exists, then you can use the <tt>doneFileName</tt> option on the endpoint.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:bar?doneFileName=done"</span>);
</pre>
</div></div>
<p>Will only consume files from the bar folder, if a file name done exists in the same directory as the target files. Camel will automatically delete the done file when it's done consuming the files. From Camel <b>2.9.3</b> onwards Camel will not automatic delete the done file if <tt>noop=true</tt> is configured.</p>

<p>However its more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the <tt>doneFileName</tt> option. Currently Camel supports the following two dynamic tokens: <tt><a href="file:name" class="external-link" rel="nofollow">file:name</a></tt> and <tt><a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a></tt> which must be enclosed in ${ }. The consumer only supports the static part of the done file name as either prefix or suffix (not both).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:bar?doneFileName=${file:name}.done"</span>);
</pre>
</div></div>

<p>In this example only files will be polled if there exists a done file with the name <em>file name</em>.done. For example</p>
<ul class="alternate" type="square">
	<li><tt>hello.txt</tt> &#45; is the file to be consumed</li>
	<li><tt>hello.txt.done</tt> &#45; is the associated done file</li>
</ul>


<p>You can also use a prefix for the done file, such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:bar?doneFileName=ready-${file:name}"</span>);
</pre>
</div></div>
<ul class="alternate" type="square">
	<li><tt>hello.txt</tt> &#45; is the file to be consumed</li>
	<li><tt>ready-hello.txt</tt> &#45; is the associated done file</li>
</ul>




<h3><a name="BookComponentAppendix-Writingdonefiles"></a>Writing done files</h3>

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

<p>After you have written af file you may want to write an additional <em>done</em> file as a kinda of marker, to indicate to others that the file is finished and has been written. To do that you can use the <tt>doneFileName</tt> option on the file producer endpoint.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"file:bar?doneFileName=done"</span>);
</pre>
</div></div>
<p>Will simply create a file named <tt>done</tt> in the same directory as the target file.</p>

<p>However its more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the <tt>doneFileName</tt> option. Currently Camel supports the following two dynamic tokens: <tt><a href="file:name" class="external-link" rel="nofollow">file:name</a></tt> and <tt><a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a></tt> which must be enclosed in ${ }.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"file:bar?doneFileName=done-${file:name}"</span>);
</pre>
</div></div>
<p>Will for example create a file named <tt>done-foo.txt</tt> if the target file was <tt>foo.txt</tt> in the same directory as the target file.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"file:bar?doneFileName=${file:name}.done"</span>);
</pre>
</div></div>
<p>Will for example create a file named <tt>foo.txt.done</tt> if the target file was <tt>foo.txt</tt> in the same directory as the target file.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"file:bar?doneFileName=${file:name.noext}.done"</span>);
</pre>
</div></div>
<p>Will for example create a file named <tt>foo.done</tt> if the target file was <tt>foo.txt</tt> in the same directory as the target file.</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>

<h4><a name="BookComponentAppendix-Readfromadirectoryandwritetoanotherdirectoryusingaoverruledynamicname"></a>Read from a directory and write to another directory using a overrule dynamic name</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?overruleFile=copy-of-${file:name}"</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-Readingrecursivelyfromadirectoryandwritingtoanother"></a>Reading recursively from a directory and writing to 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-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 process 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> <span class="code-keyword">static</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>Camel uses the absolute file name as the idempotent key, to detect duplicate files. From <b>Camel 2.11</b> onwards you can customize this key by using an expression in the idempotentKey option. For example to use both the name and the file size as the key</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;idempotentKey=${file:name}-${file-size}"</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>By default Camel uses a in memory based store for keeping track of consumed files, it uses a least recently used cache 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 stores the key in separate lines in the file. By default, the file store has a size limit of 1mb. When the file grows larger Camel will truncate the file store, rebuilding the content by flushing the 1st level cache into 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 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 <tt>idempotentRepository</tt> 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 built 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&lt;T&gt; <span class="code-keyword">implements</span> GenericFileFilter&lt;T&gt; {
    <span class="code-keyword">public</span> <span class="code-object">boolean</span> accept(GenericFile&lt;T&gt; file) {
        <span class="code-comment">// we want all directories
</span>        <span class="code-keyword">if</span> (file.isDirectory()) {
            <span class="code-keyword">return</span> <span class="code-keyword">true</span>;
        }
        <span class="code-comment">// we dont accept any files starting with skip in the name
</span>        <span class="code-keyword">return</span> !file.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 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">"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>
<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>New options from Camel 2.10 onwards</b><br />There are now <tt>antInclude</tt> and <tt>antExclude</tt> options to make it easy to specify ANT style include/exclude without having to define the filter. See the URI options above for more information.</td></tr></table></div>

<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" class="external-link" 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>&#42;</tt> matches zero or more characters</li>
	<li><tt>&#42;&#42;</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&lt;T&gt; <span class="code-keyword">implements</span> Comparator&lt;GenericFile&lt;T&gt;&gt; {
    <span class="code-keyword">public</span> <span class="code-object">int</span> compare(GenericFile&lt;T&gt; o1, GenericFile&lt;T&gt; 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 />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>.</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:length
</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 has 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>abort()</tt> method (Camel 2.10) special logic can be executed in case the <tt>begin</tt> operation returned <tt>false</tt>, for example to cleanup resources etc.</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-Usingfilter"></a>Using filter</h3>

<p>The <tt>filter</tt> option allows you to implement a custom filter in Java code by implementing the <tt>org.apache.camel.component.file.GenericFileFilter</tt> interface. This interface has an <tt>accept</tt> method that returns a boolean. Return <tt>true</tt> to include the file, and <tt>false</tt> to skip the file. From Camel 2.10 onwards, there is a <tt>isDirectory</tt> method on <tt>GenericFile</tt> whether the file is a directory. This allows you to filter unwanted directories, to avoid traversing down unwanted directories.</p>

<p>For example to skip any directories which starts with <tt>"skip"</tt> in the name, can 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> class MyDirectoryFilter&lt;T&gt; <span class="code-keyword">implements</span> GenericFileFilter&lt;T&gt; {

    <span class="code-keyword">public</span> <span class="code-object">boolean</span> accept(GenericFile&lt;T&gt; file) {
        <span class="code-comment">// remember the name due unit testing (should not be needed in regular use-cases)
</span>        names.add(file.getFileName());
        
        <span class="code-comment">// we dont accept any files within directory starting with skip in the name
</span>        <span class="code-keyword">if</span> (file.isDirectory() &amp;&amp; file.getFileName().startsWith(<span class="code-quote">"skip"</span>)) {
            <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
        }

        <span class="code-keyword">return</span> <span class="code-keyword">true</span>;
    }

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

<h3><a name="BookComponentAppendix-HowtousetheCamelerrorhandlertodealwithexceptionstriggeredoutsidetheroutingengine"></a>How to use the Camel error handler to deal with exceptions triggered outside the routing engine</h3>

<p>The file and ftp consumers, will by default try to pickup files. Only if that is successful then a Camel <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> can be created and passed in the Camel routing engine.<br/>
When the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is processed by the routing engine, then the Camel <a href="/confluence/display/CAMEL/Error+handling+in+Camel" title="Error handling in Camel">Error Handling</a> takes over (eg the onException / errorHandler in the routes).<br/>
However outside the scope of the routing engine, any exceptions handling is component specific. Camel offers a <tt>org.apache.camel.spi.ExceptionHandler</tt> that allows components<br/>
to use that as a pluggable hook for end users to use their own implementation. Camel offers a default <tt>LoggingExceptionHandler</tt> that will log the exception at ERROR/WARN level.<br/>
For the file and ftp components this would be the case. However if you want to bridge the <tt>ExceptionHandler</tt> so it uses the Camel <a href="/confluence/display/CAMEL/Error+handling+in+Camel" title="Error handling in Camel">Error Handling</a>, then<br/>
you need to implement a custom <tt>ExceptionHandler</tt> that will handle the exception by creating a Camel <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> and send it to the routing engine; then the error handling of the routing engine can get triggered.</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>Easier with Camel 2.10</b><br />The new option consumer.bridgeErrorHandler can be set to true, to make this even easier. See further below</td></tr></table></div>

<p>Here is such an example based upon an unit test.</p>

<p>First we have a custom <tt>ExceptionHandler</tt> where you can see we deal with the exception by sending it to a Camel <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> named "direct:file-error":</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>MyExceptionHandler</b></div><div class="codeContent panelContent">
<pre class="code-java">/**
 * Custom {@link ExceptionHandler} to be used on the file consumer, to send
 * exceptions to a Camel route, to let Camel deal with the error.
 */
<span class="code-keyword">private</span> <span class="code-keyword">static</span> class MyExceptionHandler <span class="code-keyword">implements</span> ExceptionHandler {

    <span class="code-keyword">private</span> ProducerTemplate template;

    /**
     * We use a producer template to send a message to the Camel route
     */
    <span class="code-keyword">public</span> void setTemplate(ProducerTemplate template) {
        <span class="code-keyword">this</span>.template = template;
    }

    @Override
    <span class="code-keyword">public</span> void handleException(Throwable exception) {
        handleException(exception.getMessage(), exception);
    }

    @Override
    <span class="code-keyword">public</span> void handleException(<span class="code-object">String</span> message, Throwable exception) {
        handleException(exception.getMessage(), <span class="code-keyword">null</span>, exception);
    }

    @Override
    <span class="code-keyword">public</span> void handleException(<span class="code-keyword">final</span> <span class="code-object">String</span> message, <span class="code-keyword">final</span> Exchange originalExchange, <span class="code-keyword">final</span> Throwable exception) {
        <span class="code-comment">// send the message to the special direct:file-error endpoint, which will trigger exception handling
</span>        <span class="code-comment">//
</span>        template.send(<span class="code-quote">"direct:file-error"</span>, <span class="code-keyword">new</span> Processor() {
            @Override
            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                <span class="code-comment">// set an exception on the message from the start so the error handling is triggered
</span>                exchange.setException(exception);
                exchange.getIn().setBody(message);
            }
        });
    }
}
</pre>
</div></div>

<p>Then we have a Camel route that uses the Camel routing error handler, which is the <tt>onException</tt> where we handle any IOException being thrown.<br/>
We then send the message to the same "direct:file-error" endpoint, where we handle it by transforming it to a message, and then being sent to a <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> endpoint.<br/>
This is just for testing purpose. You can handle the exception in any custom way you want, such as using a <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> or sending an email etc.</p>

<p>Notice how we configure our custom <tt>MyExceptionHandler</tt> by using the <tt>consumer.exceptionHandler</tt> option to refer to <tt>&#35;myExceptionHandler</tt> which is a id of the bean registered in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. If using Spring XML or OSGi Blueprint, then that would be a &lt;bean id="myExceptionHandler" class="com.foo.MyExceptionHandler"/&gt;:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Camel route with routing engine error handling</b></div><div class="codeContent panelContent">
<pre class="code-java">@Override
<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() {
        @Override
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// to handle any IOException being thrown
</span>            onException(IOException.class)
                .handled(<span class="code-keyword">true</span>)
                .log(<span class="code-quote">"IOException occurred due: ${exception.message}"</span>)
                <span class="code-comment">// as we handle the exception we can send it to direct:file-error,
</span>                <span class="code-comment">// where we could send out alerts or whatever we want
</span>                .to(<span class="code-quote">"direct:file-error"</span>);

            <span class="code-comment">// special route that handles file errors
</span>            from(<span class="code-quote">"direct:file-error"</span>)
                .log(<span class="code-quote">"File error route triggered to deal with exception ${exception?.class}"</span>)
                <span class="code-comment">// as <span class="code-keyword">this</span> is based on unit test just transform a message and send it to a mock
</span>                .transform().simple(<span class="code-quote">"Error ${exception.message}"</span>)
                .to(<span class="code-quote">"mock:error"</span>);

            <span class="code-comment">// <span class="code-keyword">this</span> is the file route that pickup files, notice how we use our custom exception handler on the consumer
</span>            <span class="code-comment">// the exclusiveReadLockStrategy is only configured because <span class="code-keyword">this</span> is from an unit test, so we use that to simulate exceptions
</span>            from(<span class="code-quote">"file:target/nospace?exclusiveReadLockStrategy=#myReadLockStrategy&amp;consumer.exceptionHandler=#myExceptionHandler"</span>)
                .convertBodyTo(<span class="code-object">String</span>.class)
                .to(<span class="code-quote">"mock:result"</span>);
        }
    };
}
</pre>
</div></div>

<p>The source code for this example can be seen <a href="https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java" class="external-link" rel="nofollow">here</a></p>

<h4><a name="BookComponentAppendix-Usingconsumer.bridgeErrorHandler"></a>Using consumer.bridgeErrorHandler</h4>

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

<p>If you want to use the Camel <a href="/confluence/display/CAMEL/Error+Handler" title="Error Handler">Error Handler</a> to deal with any exception occurring in the file consumer, then you can enable the <tt>consumer.bridgeErrorHandler</tt> option as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Using consumer.bridgeErrorHandler</b></div><div class="codeContent panelContent">
<pre class="code-java">@Override
<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() {
        @Override
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// to handle any IOException being thrown
</span>            onException(IOException.class)
                .handled(<span class="code-keyword">true</span>)
                .log(<span class="code-quote">"IOException occurred due: ${exception.message}"</span>)
                .transform().simple(<span class="code-quote">"Error ${exception.message}"</span>)
                .to(<span class="code-quote">"mock:error"</span>);

            <span class="code-comment">// <span class="code-keyword">this</span> is the file route that pickup files, notice how we bridge the consumer to use the Camel routing error handler
</span>            <span class="code-comment">// the exclusiveReadLockStrategy is only configured because <span class="code-keyword">this</span> is from an unit test, so we use that to simulate exceptions
</span>            from(<span class="code-quote">"file:target/nospace?exclusiveReadLockStrategy=#myReadLockStrategy&amp;consumer.bridgeErrorHandler=<span class="code-keyword">true</span>"</span>)
                .convertBodyTo(<span class="code-object">String</span>.class)
                .to(<span class="code-quote">"mock:result"</span>);
        }
    };
}
</pre>
</div></div>

<p>So all you have to do is to enable this option, and the error handler in the route will take it from there.</p>

<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">FTP</a></li>
	<li><a href="/confluence/display/CAMEL/Polling+Consumer" title="Polling Consumer">Polling Consumer</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" class="external-link" 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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-flatpack<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> The component can either process each row one by one or the entire content at once. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowShortLines</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> Allows for lines to be shorter than expected and ignores the extra characters. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreExtraColumns</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> Allows for lines to be longer than expected and ignores the extra characters. </td>
</tr>
</tbody></table>
</div>
</div>

<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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<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>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-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">"file://someDirectory"</span>/&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"flatpack:foo"</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">"flatpack:foo"</span>/&gt;</span>
      ...
    <span class="code-tag">&lt;/route&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>
</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>
<div class='table-wrap'>
<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>
<tr>
<td class='confluenceTd'> <tt>allowShortLines</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.5 and 2.10.3 onwards</b>: Allows for lines to be shorter than expected and ignores the extra characters. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreExtraColumns</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.5 and 2.10.3 onwards</b>: Allows for lines to be longer than expected and ignores the extra characters. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>To use the data format, simply instantiate an instance and invoke the marshal 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;x.x.x&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>The <b>freemarker:</b> component allows for processing a message using a <a href="http://freemarker.org/" class="external-link" 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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-freemarker<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span> <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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" class="external-link" 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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 it's loaded. <br class="atl-forced-newline" /> Note: as of <b>Camel 2.9</b> cached resource content can be cleared via JMX using the endpoint's <tt>clearContentCache</tt> operation. </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>
<tr>
<td class='confluenceTd'> <tt>templateUpdateDelay</tt> </td>
<td class='confluenceTd'> <tt>5</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Number of seconds the loaded template resource will remain in the cache. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>Headers set during the FreeMarker evaluation are returned to the message and added as headers. This provides a mechanism for the FreeMarker component to return values 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 transferred as:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>exchange.properties</tt> </td>
<td class='confluenceTd'> The <tt>Exchange</tt> properties. </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>
</div>
</div>

<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>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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Support Version </th>
</tr>
<tr>
<td class='confluenceTd'> FreemarkerConstants.FREEMARKER_RESOURCE </td>
<td class='confluenceTd'> org.springframework.core.io.Resource </td>
<td class='confluenceTd'> The template resource </td>
<td class='confluenceTd'> &lt;= 2.1 </td>
</tr>
<tr>
<td class='confluenceTd'> FreemarkerConstants.FREEMARKER_RESOURCE_URI </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> A URI for the template resource to use instead of the endpoint configured. </td>
<td class='confluenceTd'> &gt;= 2.1 </td>
</tr>
<tr>
<td class='confluenceTd'> FreemarkerConstants.FREEMARKER_TEMPLATE </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The template to use instead of the endpoint configured. </td>
<td class='confluenceTd'> &gt;= 2.1 </td>
</tr>
</tbody></table>
</div>
</div>

<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(FreemarkerConstants.FREEMARKER_RESOURCE_URI).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."</span>
            + <span class="code-quote">"\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%2FFTPSComponent"></a>FTP/SFTP/FTPS Component</h2>

<p>This component provides access to remote file systems over the FTP and SFTP protocols.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></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>More options</b><br />See <a href="/confluence/display/CAMEL/File2" title="File2">File</a> for more options as all the options from <a href="/confluence/display/CAMEL/File2" title="File2">File</a> is inherited.</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>Consuming from remote FTP server</b><br />Make sure you read the section titled <em>Default when consuming files</em> further below for details related to consuming files.</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.</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>

<p>This component uses two different libraries for the actual FTP work. FTP and FTPS uses <a href="http://commons.apache.org/net/" class="external-link" rel="nofollow">Apache Commons Net</a> while SFTP uses <a href="http://www.jcraft.com/jsch/" class="external-link" rel="nofollow">JCraft JSCH</a>.</p>

<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>

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

<p>The options below are exclusive for the FTP component.</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>More options</b><br />See <a href="/confluence/display/CAMEL/File2" title="File2">File</a> for more options as all the options from <a href="/confluence/display/CAMEL/File2" title="File2">File</a> is inherited.</td></tr></table></div>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the username to use to log in to the remote file systen. </td>
</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. Disconnect will only disconnect the current connection to the FTP server. If you have a consumer which you want to stop, then you need to stop the consumer/route instead. </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 class="atl-forced-newline" />
<tt>TLS</tt>: Transport Layer Security <br class="atl-forced-newline" />
<tt>SSL</tt>: Secure Sockets Layer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableSecureDataChannelDefaults</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4: FTPS only</b>: Whether or not to disable using default values for <tt>execPbsz</tt> and <tt>execProt</tt> when using secure data transfer. You can set this option to <tt>true</tt> if you want to be in absolute full control what the options <tt>execPbsz</tt> and <tt>execProt</tt> should be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>download</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Whether the FTP consumer should download the file. If this option is set to <tt>false</tt>, then the message body will be <tt>null</tt>, but the consumer will still trigger a Camel <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> that has details about the file such as file name, file size, etc. It's just that the file will not be downloaded. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>execProt</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4: FTPS only</b>: Will by default use option <tt>P</tt> if secure data channel defaults hasn't been disabled. Possible values are: <br class="atl-forced-newline" />
<tt>C</tt>: Clear <br class="atl-forced-newline" />
<tt>S</tt>: Safe (SSL protocol only) <br class="atl-forced-newline" />
<tt>E</tt>: Confidential (SSL protocol only) <br class="atl-forced-newline" />
<tt>P</tt>: Private </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>execPbsz</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4: FTPS only</b>: This option specifies the buffer size of the secure data channel. If option <tt>useSecureDataChannel</tt> has been enabled and this option has not been explicit set, then value <tt>0</tt> is used. </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>ciphers</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.2, 2.9: SFTP only</b> Set a comma separated list of ciphers that will be used in order of preference. Possible cipher names are defined by <a href="http://www.jcraft.com/jsch/" class="external-link" rel="nofollow">JCraft JSCH</a>. Some examples include: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc. If not specified the default list from JSCH will be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fastExistsCheck</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.2, 2.9:</b> If set this option to be true, camel-ftp will use the list file directly to check if the file exists. Since some FTP server may not support to list the file directly, if the option is false, camel-ftp will use the old way to list the directory and check if the file exists. Note from <b>Camel 2.10.1</b> onwards this option also influences <tt>readLock=changed</tt> to control whether it performs a fast check to update file information or not. This can be used to speed up the process if the FTP server has a lot of files. </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'> <tt>3</tt> </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'> <tt>1000</tt> </td>
<td class='confluenceTd'> Delay in millis Camel will wait before performing a reconnect attempt. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectTimeout</tt> </td>
<td class='confluenceTd'> <tt>10000</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Is the connect timeout in millis. This corresponds to using <tt>ftpClient.connectTimeout</tt> for the FTP/FTPS. For SFTP this option is also used when attempting to connect. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>soTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.4:</b> Is the <tt>SocketOptions.SO_TIMEOUT</tt> value in millis. Note SFTP will automatic use the <tt>connectTimeout</tt> as the <tt>soTimeout</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.4:</b> Is the data timeout in millis. This corresponds to using <tt>ftpClient.dataTimeout</tt> for the FTP/FTPS. For SFTP there is no data timeout. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnConnectFailed</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Whether or not to thrown an exception if a successful connection and login could not be establish. This allows a custom <tt>pollStrategy</tt> to deal with the exception, for example to stop the consumer or the likes. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>siteCommand</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.5:</b> To execute site commands after successful login. Multiple site commands can be separated using a new line character (\n). Use <tt>help site</tt> to see which site commands your FTP server supports. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>stepwise</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Whether or not stepwise traversing directories should be used or not. Stepwise means that it will CD one directory at a time. See more details below. You can disable this in case you can't use this approach. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>separator</tt> </td>
<td class='confluenceTd'> <tt>Auto</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Dictates what path separator char to use when uploading files. <tt>Auto</tt> = Use the path provided without altering it. <tt>UNIX</tt> = Use unix style path separators. <tt>Windows</tt> = Use Windows style path separators. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chmod</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>SFTP Producer Only:</b> <b>Camel 2.9:</b> Allows you to set chmod on the stored file. For example <tt>chmod=640</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>compression</tt> </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> <b>SFTP Only:</b> <b>Camel 2.8.3/2.9:</b> To use compression. Specify a level from 1 to 10. <b>Important:</b> You must manually add the needed JSCH zlib JAR to the classpath for compression support. </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>serverAliveInterval</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>SFTP Only:</b> <b>Camel 2.8</b> Allows you to set the serverAliveInterval of the sftp session </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serverAliveCountMax</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>SFTP Only:</b> <b>Camel 2.8</b> Allows you to set the serverAliveCountMax  of the sftp session </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>
<tr>
<td class='confluenceTd'> <tt>sslContextParameters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> <b>Camel 2.9:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="http://camel.apache.org/registry.html" class="external-link" rel="nofollow">Registry</a>.&nbsp; This reference overrides any configured SSL related options on ftpClient as well as the securityProtocol (SSL, TLS, etc.) set on FtpsConfiguration.&nbsp; See <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Using the JSSE Configuration Utility</a>. </td>
</tr>
</tbody></table>
</div>
</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 />When using the <tt>ftpClient.</tt> properties related to SSL with the FTPS component, the 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>When using <tt>sslContextParameters</tt>, the trust store is managed by the configuration of the provided SSLContextParameters instance.</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-2.2/org/apache/commons/net/ftp/FTPClientConfig.html" class="external-link" 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-2.2/org/apache/commons/net/ftp/FTPClient.html" class="external-link" 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>See <a href="/confluence/display/CAMEL/File2" title="File2">File2</a> as all the options there also applies for this component.</td></tr></table></div>


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

<p><tt><a href="ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true" class="external-link" 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" class="external-link" 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" class="external-link" 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 />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>The FTP producer does <b>not</b> have this issue, it supports concurrency.</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 />This component is an extension of the <a href="/confluence/display/CAMEL/File2" title="File2">File</a> component. So there are more samples and details on the <a href="/confluence/display/CAMEL/File2" title="File2">File</a> component page.</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 explicitly 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. See the options table at <a href="/confluence/display/CAMEL/File2" title="File2">File2</a> for more details about read locks.<br/>
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>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<h3><a name="BookComponentAppendix-Abouttimeouts"></a>About timeouts</h3>

<p>The two set of libraries (see top) has different API for setting timeout. You can use the <tt>connectTimeout</tt> option for both of them to set a timeout in millis to establish a network connection. An individual <tt>soTimeout</tt> can also be set on the FTP/FTPS, which corresponds to using <tt>ftpClient.soTimeout</tt>. Notice SFTP will automatically use <tt>connectTimeout</tt> as its <tt>soTimeout</tt>. The <tt>timeout</tt> option only applies for FTP/FTSP as the data timeout, which corresponds to the <tt>ftpClient.dataTimeout</tt> value. All timeout values are in millis.</p>


<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 />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.</td></tr></table></div>

<h3><a name="BookComponentAppendix-Stepwisechangingdirectories"></a>Stepwise changing directories</h3>

<p>Camel <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> can operate in two modes in terms of traversing directories when consuming files (eg downloading) or producing files (eg uploading)</p>
<ul class="alternate" type="square">
	<li>stepwise</li>
	<li>not stepwise</li>
</ul>


<p>You may want to pick either one depending on your situation and security issues. Some Camel end users can only download files if they use stepwise, while others can only download if they do not. At least you have the choice to pick (from Camel 2.6 onwards).</p>

<p>In Camel 2.0 - 2.5 there is only one mode and it is:</p>
<ul class="alternate" type="square">
	<li>before 2.5 not stepwise</li>
	<li>2.5 stepwise</li>
</ul>


<p>From Camel 2.6 onwards there is now an option <tt>stepwise</tt> you can use to control the behavior.</p>

<p>Note that stepwise changing of directory will in most cases only work when the user is confined to it's home directory and when the home directory is reported as <tt>"/"</tt>.</p>

<p>The difference between the two of them is best illustrated with an example. Suppose we have the following directory structure on the remote FTP server we need to traverse and download files:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
/
/one
/one/two
/one/two/sub-a
/one/two/sub-b
</pre>
</div></div>

<p>And that we have a file in each of sub-a (a.txt) and sub-b (b.txt) folder.</p>

<h4><a name="BookComponentAppendix-Usingstepwise%3Dtrue%28defaultmode%29"></a>Using stepwise=true (default mode)</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
TYPE A
200 Type set to A
PWD
257 <span class="code-quote">"/"</span> is current directory.
CWD one
250 CWD successful. <span class="code-quote">"/one"</span> is current directory.
CWD two
250 CWD successful. <span class="code-quote">"/one/two"</span> is current directory.
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,17,94
200 Port command successful
LIST
150 Opening data channel <span class="code-keyword">for</span> directory list.
226 Transfer OK
CWD sub-a
250 CWD successful. <span class="code-quote">"/one/two/sub-a"</span> is current directory.
PORT 127,0,0,1,17,95
200 Port command successful
LIST
150 Opening data channel <span class="code-keyword">for</span> directory list.
226 Transfer OK
CDUP
200 CDUP successful. <span class="code-quote">"/one/two"</span> is current directory.
CWD sub-b
250 CWD successful. <span class="code-quote">"/one/two/sub-b"</span> is current directory.
PORT 127,0,0,1,17,96
200 Port command successful
LIST
150 Opening data channel <span class="code-keyword">for</span> directory list.
226 Transfer OK
CDUP
200 CDUP successful. <span class="code-quote">"/one/two"</span> is current directory.
CWD /
250 CWD successful. <span class="code-quote">"/"</span> is current directory.
PWD
257 <span class="code-quote">"/"</span> is current directory.
CWD one
250 CWD successful. <span class="code-quote">"/one"</span> is current directory.
CWD two
250 CWD successful. <span class="code-quote">"/one/two"</span> is current directory.
PORT 127,0,0,1,17,97
200 Port command successful
RETR foo.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
CWD /
250 CWD successful. <span class="code-quote">"/"</span> is current directory.
PWD
257 <span class="code-quote">"/"</span> is current directory.
CWD one
250 CWD successful. <span class="code-quote">"/one"</span> is current directory.
CWD two
250 CWD successful. <span class="code-quote">"/one/two"</span> is current directory.
CWD sub-a
250 CWD successful. <span class="code-quote">"/one/two/sub-a"</span> is current directory.
PORT 127,0,0,1,17,98
200 Port command successful
RETR a.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
CWD /
250 CWD successful. <span class="code-quote">"/"</span> is current directory.
PWD
257 <span class="code-quote">"/"</span> is current directory.
CWD one
250 CWD successful. <span class="code-quote">"/one"</span> is current directory.
CWD two
250 CWD successful. <span class="code-quote">"/one/two"</span> is current directory.
CWD sub-b
250 CWD successful. <span class="code-quote">"/one/two/sub-b"</span> is current directory.
PORT 127,0,0,1,17,99
200 Port command successful
RETR b.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
CWD /
250 CWD successful. <span class="code-quote">"/"</span> is current directory.
QUIT
221 Goodbye
disconnected.
</pre>
</div></div>

<p>As you can see when stepwise is enabled, it will traverse the directory structure using CD xxx.</p>

<h4><a name="BookComponentAppendix-Usingstepwise%3Dfalse"></a>Using stepwise=false</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
230 Logged on
TYPE A
200 Type set to A
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,4,122
200 Port command successful
LIST one/two
150 Opening data channel <span class="code-keyword">for</span> directory list
226 Transfer OK
PORT 127,0,0,1,4,123
200 Port command successful
LIST one/two/sub-a
150 Opening data channel <span class="code-keyword">for</span> directory list
226 Transfer OK
PORT 127,0,0,1,4,124
200 Port command successful
LIST one/two/sub-b
150 Opening data channel <span class="code-keyword">for</span> directory list
226 Transfer OK
PORT 127,0,0,1,4,125
200 Port command successful
RETR one/two/foo.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
PORT 127,0,0,1,4,126
200 Port command successful
RETR one/two/sub-a/a.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
PORT 127,0,0,1,4,127
200 Port command successful
RETR one/two/sub-b/b.txt
150 Opening data channel <span class="code-keyword">for</span> file transfer.
226 Transfer OK
QUIT
221 Goodbye
disconnected.
</pre>
</div></div>

<p>As you can see when not using stepwise, there are no CD operation invoked at all.</p>

<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">//tiger:scott@localhost/<span class="code-keyword">public</span>/reports?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-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("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>
</span>      &amp;ftpClient.keyStore.file=./src/test/resources/server.jks
      &amp;ftpClient.keyStore.password=password&amp;ftpClient.keyStore.keyPassword=password")
  .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 built 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&lt;T&gt; <span class="code-keyword">implements</span> GenericFileFilter&lt;T&gt; {

    <span class="code-keyword">public</span> <span class="code-object">boolean</span> accept(GenericFile&lt;T&gt; 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 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">"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.springsource.org/spring/docs/3.0.x/api/org/springframework/util/AntPathMatcher.html" class="external-link" 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>&#42;</tt> matches zero or more characters</li>
	<li><tt>&#42;&#42;</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;bean class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>/&gt;</span>
<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:${SpringFileAntPathMatcherRemoteFileFilterTest.ftpPort}/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 exclude --&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 any files in the sub folder 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 separate 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>Tutorials</b><br /><ul>
	<li>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></li>
	<li>The <a href="/confluence/display/CAMEL/Tutorial-OAuth" title="Tutorial-OAuth">OAuth tutorial</a> demonstrates how to implement <a href="http://oauth.net/" class="external-link" rel="nofollow">OAuth</a> in web applications.</li>
</ul>
</td></tr></table></div>

<p>The Camel components for <a href="http://code.google.com/appengine/" class="external-link" 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" class="external-link" 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>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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/" class="external-link" 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/" class="external-link" 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/" class="external-link" 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/" class="external-link" 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/" class="external-link" 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/" class="external-link" 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/" class="external-link" 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/" class="external-link" rel="nofollow">Accounts service</a></td>
<td class='confluenceTd'><a href="/confluence/display/CAMEL/gauth" title="gauth">gauth</a> <br class="atl-forced-newline" /> <a href="/confluence/display/CAMEL/glogin" title="glogin">glogin</a></td>
<td class='confluenceTd'>These components interact with the Google Accounts API for authentication and authorization. Google Accounts is not specific to Google App Engine but is often used by GAE applications for implementing security. The <a href="/confluence/display/CAMEL/gauth" title="gauth">gauth</a> component is used by web applications to implement a <a href="http://code.google.com/apis/accounts/docs/OAuth.html" class="external-link" rel="nofollow">Google-specific OAuth</a> consumer. This component can also be used to OAuth-enable non-GAE web applications. The <a href="/confluence/display/CAMEL/glogin" title="glogin">glogin</a> component is used by Java clients (outside GAE) for programmatic login to GAE applications. For instructions how to protect GAE applications against unauthorized access refer to the <a href="/confluence/display/CAMEL/gsec" title="gsec">Security for Camel GAE applications</a> page.</td>
</tr>
</tbody></table>
</div>
</div>

<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 higher versions. The problem is that usage of the Camel-specific Spring configuration XML schema from the <tt><a href="http://camel.apache.org/schema/spring" class="external-link" 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. This limitation has been removed since Camel 2.2. </p>

<p>JMX must be disabled in any case 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.2orhigher"></a>Camel 2.2 or higher</h4>

<p>With Camel 2.2 or higher, applications can use the <tt><a href="http://camel.apache.org/schema/spring" class="external-link" 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/" class="external-link" 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>
<h2><a name="BookComponentAppendix-HazelcastComponent"></a>Hazelcast Component</h2>

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

<p>The <b>hazelcast:</b> component allows you to work with the <a href="http://www.hazelcast.com" class="external-link" rel="nofollow">Hazelcast</a> distributed data grid / cache. Hazelcast is a in memory data grid, entirely written in Java (single jar). It offers a great palette of different data stores like map, multi map (same key, n values), queue, list and atomic number. The main reason to use Hazelcast is its simple cluster support. If you have enabled multicast on your network you can run a cluster with hundred nodes with no extra configuration. Hazelcast can simply configured to add additional features like n copies between nodes (default is 1), cache persistence, network configuration (if needed), near cache, enviction and so on. For more information consult the Hazelcast documentation on <a href="http://www.hazelcast.com/documentation.jsp" class="external-link" rel="nofollow">http://www.hazelcast.com/documentation.jsp</a>.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-hazelcast<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
hazelcast:[ map | multimap | queue | seda | set | atomicvalue | instance]:cachename[?options]
</pre>
</div></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>You have to use the second prefix to define which type of data store you want to use.</td></tr></table></div>

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

<ol>
	<li>Usage of <a href="#BookComponentAppendix-map">map</a></li>
	<li>Usage of <a href="#BookComponentAppendix-multimap">multimap</a></li>
	<li>Usage of <a href="#BookComponentAppendix-queue">queue</a></li>
	<li>Usage of <a href="#BookComponentAppendix-list">list</a></li>
	<li>Usage of <a href="#BookComponentAppendix-seda">seda</a></li>
	<li>Usage of <a href="#BookComponentAppendix-atomicnumber">atomic number</a></li>
	<li>Usage of <a href="#BookComponentAppendix-cluster">cluster</a> support (instance)</li>
</ol>


<p><a name="BookComponentAppendix-map"></a></p>

<h3><a name="BookComponentAppendix-UsageofMap"></a>Usage of Map</h3>

<h4><a name="BookComponentAppendix-mapcacheproducerto%28%22hazelcast%3Amap%3Afoo%22%29"></a>map cache producer - to("hazelcast:map:foo")</h4>

<p>If you want to store a value in a map you can use the map cache producer. The map cache producer provides 5 operations (put, get, update, delete, query). For the first 4 you have to provide the operation inside the "hazelcast.operation.type" header variable. In Java DSL you can use the constants from <tt>org.apache.camel.component.hazelcast.HazelcastConstants</tt>.</p>

<p>Header Variables for the request message:</p>
<div class='table-wrap'>
<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>hazelcast.operation.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, delete, get, update, query </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache (not needed for the query operation) </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastOperationType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, delete, get, update, query <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache (not needed for the query operation) <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>


<p>You can call the samples with:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBodyAndHeader(<span class="code-quote">"direct:[put|get|update|delete|query]"</span>, <span class="code-quote">"my-foo"</span>, HazelcastConstants.OBJECT_ID, <span class="code-quote">"4711"</span>);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforput%3A"></a>Sample for <b>put</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:put"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:put"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;put&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforget%3A"></a>Sample for <b>get</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:get"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:get"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;get&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
	&lt;to uri=<span class="code-quote">"seda:out"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforupdate%3A"></a>Sample for <b>update</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:update"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:update"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;update&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Samplefordelete%3A"></a>Sample for <b>delete</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:delete"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:delete"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;delete&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforquery"></a>Sample for <b>query</b></h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:query"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:query"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;query&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
	&lt;to uri=<span class="code-quote">"seda:out"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>For the query operation Hazelcast offers a SQL like syntax to query your distributed map.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> q1 = <span class="code-quote">"bar &gt; 1000"</span>;
template.sendBodyAndHeader(<span class="code-quote">"direct:query"</span>, <span class="code-keyword">null</span>, HazelcastConstants.QUERY, q1);
</pre>
</div></div>


<h3><a name="BookComponentAppendix-mapcacheconsumerfrom%28%22hazelcast%3Amap%3Afoo%22%29"></a>map cache consumer - from("hazelcast:map:foo")</h3>

<p>Hazelcast provides event listeners on their data grid. If you want to be notified if a cache will be manipulated, you can use the map consumer. There're 4 events: <b>put</b>, <b>update</b>, <b>delete</b> and <b>envict</b>. The event type will be stored in the "<b>hazelcast.listener.action</b>" header variable. The map consumer provides some additional information inside these variables:</p>

<p>Header Variables inside the response message:</p>
<div class='table-wrap'>
<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>hazelcast.listener.time</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.action</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b>, <b>updated</b>, <b>envicted</b> and <b>removed</b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.name</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here map </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastListenerTime</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerAction</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b>, <b>updated</b>, <b>envicted</b> and <b>removed</b>. <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here map <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b></td>
</tr>
</tbody></table>
</div>


<p>The object value will be stored within <b>put</b> and <b>update</b> actions inside the message body.</p>

<p>Here's a sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.log(<span class="code-quote">"object..."</span>)
.choice()
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
         .log(<span class="code-quote">"...added"</span>)
         .to(<span class="code-quote">"mock:added"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
         .log(<span class="code-quote">"...envicted"</span>)
         .to(<span class="code-quote">"mock:envicted"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.UPDATED))
         .log(<span class="code-quote">"...updated"</span>)
         .to(<span class="code-quote">"mock:updated"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
         .log(<span class="code-quote">"...removed"</span>)
         .to(<span class="code-quote">"mock:removed"</span>)
    .otherwise()
         .log(<span class="code-quote">"fail!"</span>);
</pre>
</div></div>

<p><a name="BookComponentAppendix-multimap"></a></p>

<h3><a name="BookComponentAppendix-UsageofMultiMap"></a>Usage of Multi Map</h3>

<h4><a name="BookComponentAppendix-multimapcacheproducerto%28%22hazelcast%3Amultimap%3Afoo%22%29"></a>multimap cache producer - to("hazelcast:multimap:foo")</h4>

<p>A multimap is a cache where you can store n values to one key. The multimap producer provides 4 operations (put, get, removevalue, delete).</p>

<p>Header Variables for the request message:</p>
<div class='table-wrap'>
<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>hazelcast.operation.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, get, removevalue, delete </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>

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

<div class='table-wrap'>
<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>CamelHazelcastOperationType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, delete, get, update, query <b>Available as of Camel 2.8</b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache (not needed for the query operation) <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>


<p>You can call the samples with:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBodyAndHeader(<span class="code-quote">"direct:[put|get|update|delete|query]"</span>, <span class="code-quote">"my-foo"</span>, HazelcastConstants.OBJECT_ID, <span class="code-quote">"4711"</span>);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforput%3A"></a>Sample for <b>put</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:put"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:put"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;put&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforget%3A"></a>Sample for <b>get</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:get"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:get"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;get&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
	&lt;to uri=<span class="code-quote">"seda:out"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforupdate%3A"></a>Sample for <b>update</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:update"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:update"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;update&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Samplefordelete%3A"></a>Sample for <b>delete</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:delete"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:delete"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;delete&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforquery"></a>Sample for <b>query</b></h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:query"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:query"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;query&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:map:foo"</span> /&gt;
	&lt;to uri=<span class="code-quote">"seda:out"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>For the query operation Hazelcast offers a SQL like syntax to query your distributed map.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> q1 = <span class="code-quote">"bar &gt; 1000"</span>;
template.sendBodyAndHeader(<span class="code-quote">"direct:query"</span>, <span class="code-keyword">null</span>, HazelcastConstants.QUERY, q1);
</pre>
</div></div>


<h3><a name="BookComponentAppendix-mapcacheconsumerfrom%28%22hazelcast%3Amap%3Afoo%22%29"></a>map cache consumer - from("hazelcast:map:foo")</h3>

<p>Hazelcast provides event listeners on their data grid. If you want to be notified if a cache will be manipulated, you can use the map consumer. There're 4 events: <b>put</b>, <b>update</b>, <b>delete</b> and <b>envict</b>. The event type will be stored in the "<b>hazelcast.listener.action</b>" header variable. The map consumer provides some additional information inside these variables:</p>

<p>Header Variables inside the response message:</p>
<div class='table-wrap'>
<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>hazelcast.listener.time</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.action</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b>, <b>updated</b>, <b>envicted</b> and <b>removed</b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.name</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here map </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastListenerTime</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerAction</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b>, <b>updated</b>, <b>envicted</b> and <b>removed</b>. <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here map <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>


<p>The object value will be stored within <b>put</b> and <b>update</b> actions inside the message body.</p>

<p>Here's a sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.MAP_PREFIX)
.log(<span class="code-quote">"object..."</span>)
.choice()
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
         .log(<span class="code-quote">"...added"</span>)
         .to(<span class="code-quote">"mock:added"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
         .log(<span class="code-quote">"...envicted"</span>)
         .to(<span class="code-quote">"mock:envicted"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.UPDATED))
         .log(<span class="code-quote">"...updated"</span>)
         .to(<span class="code-quote">"mock:updated"</span>)
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
         .log(<span class="code-quote">"...removed"</span>)
         .to(<span class="code-quote">"mock:removed"</span>)
    .otherwise()
         .log(<span class="code-quote">"fail!"</span>);
</pre>
</div></div>

<p><a name="BookComponentAppendix-multimap"></a></p>

<h3><a name="BookComponentAppendix-UsageofMultiMap"></a>Usage of Multi Map</h3>

<h4><a name="BookComponentAppendix-multimapcacheproducerto%28%22hazelcast%3Amultimap%3Afoo%22%29"></a>multimap cache producer - to("hazelcast:multimap:foo")</h4>

<p>A multimap is a cache where you can store n values to one key. The multimap producer provides 4 operations (put, get, removevalue, delete).</p>

<p>Header Variables for the request message:</p>
<div class='table-wrap'>
<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>hazelcast.operation.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, get, removevalue, delete </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastOperationType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: put, get, removevalue, delete <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the object id to store / find your object inside the cache <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>


<h5><a name="BookComponentAppendix-Sampleforput%3A"></a>Sample for <b>put</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:put"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.to(<span class="code-object">String</span>.format(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.MULTIMAP_PREFIX));
</pre>
</div></div>

<p>Spring DSL:</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">"direct:put"</span> /&gt;
	&lt;log message=<span class="code-quote">"put.."</span>/&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;put&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:multimap:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforremovevalue%3A"></a>Sample for <b>removevalue</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:removevalue"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.MULTIMAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:removevalue"</span> /&gt;
	&lt;log message=<span class="code-quote">"removevalue..."</span>/&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;removevalue&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:multimap:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>To remove a value you have to provide the value you want to remove inside the message body. If you have a multimap object {<tt>key: "4711" values: { "my-foo", "my-bar"</tt>}} you have to put "my-foo" inside the message body to remove the "my-foo" value.</p>

<h5><a name="BookComponentAppendix-Sampleforget%3A"></a>Sample for <b>get</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:get"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.MULTIMAP_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:get"</span> /&gt;
	&lt;log message=<span class="code-quote">"get.."</span>/&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;get&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:multimap:foo"</span> /&gt;
	&lt;to uri=<span class="code-quote">"seda:out"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Samplefordelete%3A"></a>Sample for <b>delete</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:delete"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.MULTIMAP_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:delete"</span> /&gt;
	&lt;log message=<span class="code-quote">"delete.."</span>/&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;delete&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:multimap:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>you can call them in your test class with:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBodyAndHeader(<span class="code-quote">"direct:[put|get|removevalue|delete]"</span>, <span class="code-quote">"my-foo"</span>, HazelcastConstants.OBJECT_ID, <span class="code-quote">"4711"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-multimapcacheconsumerfrom%28%22hazelcast%3Amultimap%3Afoo%22%29"></a>multimap cache consumer - from("hazelcast:multimap:foo")</h4>

<p>For the multimap cache this component provides the same listeners / variables as for the map cache consumer (except the update and enviction listener). The only difference is the <b>multimap</b> prefix inside the URI. Here is a sample:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.MULTIMAP_PREFIX)
.log(<span class="code-quote">"object..."</span>)
.choice()
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
		.log(<span class="code-quote">"...added"</span>)
                .to(<span class="code-quote">"mock:added"</span>)
        <span class="code-comment">//.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
</span>        <span class="code-comment">//        .log(<span class="code-quote">"...envicted"</span>)
</span>        <span class="code-comment">//        .to(<span class="code-quote">"mock:envicted"</span>)
</span>        .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
                .log(<span class="code-quote">"...removed"</span>)
                .to(<span class="code-quote">"mock:removed"</span>)
        .otherwise()
                .log(<span class="code-quote">"fail!"</span>);
</pre>
</div></div>

<p>Header Variables inside the response message:</p>
<div class='table-wrap'>
<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>hazelcast.listener.time</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.action</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b> and <b>removed</b> (and soon <b>envicted</b>) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.objectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.name</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.cache.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here multimap </td>
</tr>
</tbody></table>
</div>


<p>Eviction will be added as feature, soon (this is a Hazelcast issue).</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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastListenerTime</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "cachelistener" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerAction</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b> and <b>removed</b> (and soon <b>envicted</b>) <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastObjectId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the oid of the object <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the name of the cache - e.g. "foo" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastCacheType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the type of the cache - here multimap <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>


<p><a name="BookComponentAppendix-queue"></a></p>

<h3><a name="BookComponentAppendix-UsageofQueue"></a>Usage of Queue</h3>

<h4><a name="BookComponentAppendix-Queueproducerto%28%E2%80%9Chazelcast%3Aqueue%3Afoo%E2%80%9D%29"></a>Queue producer &#8211; to(“hazelcast:queue:foo”)</h4>

<p>The queue producer provides 6 operations (add, put, poll, peek, offer, removevalue).</p>

<h5><a name="BookComponentAppendix-Sampleforadd%3A"></a>Sample for <b>add</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:add"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforput%3A"></a>Sample for <b>put</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:put"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforpoll%3A"></a>Sample for <b>poll</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:poll"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.POLL_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforpeek%3A"></a>Sample for <b>peek</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:peek"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PEEK_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforoffer%3A"></a>Sample for <b>offer</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:offer"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.OFFER_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforremovevalue%3A"></a>Sample for <b>removevalue</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:removevalue"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.QUEUE_PREFIX);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Queueconsumerfrom%28%E2%80%9Chazelcast%3Aqueue%3Afoo%E2%80%9D%29"></a>Queue consumer &#8211; from(“hazelcast:queue:foo”)</h4>

<p>The queue consumer provides 2 operations (add, remove).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%smm"</span>, HazelcastConstants.QUEUE_PREFIX)
   .log(<span class="code-quote">"object..."</span>)
   .choice()
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
        	.log(<span class="code-quote">"...added"</span>)
		.to(<span class="code-quote">"mock:added"</span>)
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
		.log(<span class="code-quote">"...removed"</span>)
		.to(<span class="code-quote">"mock:removed"</span>)
	.otherwise()
		.log(<span class="code-quote">"fail!"</span>);
</pre>
</div></div>


<p><a name="BookComponentAppendix-list"></a></p>

<h3><a name="BookComponentAppendix-UsageofList"></a>Usage of List</h3>

<h4><a name="BookComponentAppendix-Listproducerto%28%E2%80%9Chazelcast%3Alist%3Afoo%E2%80%9D%29"></a>List producer &#8211; to(“hazelcast:list:foo”)</h4>

<p>The list producer provides 4 operations (add, set, get, removevalue).</p>

<h5><a name="BookComponentAppendix-Sampleforadd%3A"></a>Sample for <b>add</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:add"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.LIST_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforget%3A"></a>Sample for <b>get</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:get"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.LIST_PREFIX)
.to(<span class="code-quote">"seda:out"</span>);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforsetvalue%3A"></a>Sample for <b>setvalue</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:set"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.LIST_PREFIX);
</pre>
</div></div>

<h5><a name="BookComponentAppendix-Sampleforremovevalue%3A"></a>Sample for <b>removevalue</b>:</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:removevalue"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sbar"</span>, HazelcastConstants.LIST_PREFIX);
</pre>
</div></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>Please note that set,get and removevalue and not yet supported by hazelcast, will be added in the future..</td></tr></table></div>

<h4><a name="BookComponentAppendix-Listconsumerfrom%28%E2%80%9Chazelcast%3Alist%3Afoo%E2%80%9D%29"></a>List consumer &#8211; from(“hazelcast:list:foo”)</h4>

<p>The list consumer provides 2 operations (add, remove).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%smm"</span>, HazelcastConstants.LIST_PREFIX)
	.log(<span class="code-quote">"object..."</span>)
	.choice()
		.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
			.log(<span class="code-quote">"...added"</span>)
                        .to(<span class="code-quote">"mock:added"</span>)
		.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
			.log(<span class="code-quote">"...removed"</span>)
                        .to(<span class="code-quote">"mock:removed"</span>)
                .otherwise()
                        .log(<span class="code-quote">"fail!"</span>);
</pre>
</div></div>


<p><a name="BookComponentAppendix-seda"></a></p>

<h3><a name="BookComponentAppendix-UsageofSEDA"></a>Usage of SEDA</h3>

<p>SEDA component differs from the rest components provided. It implements a work-queue in order to  support asynchronous SEDA architectures, similar to the core "SEDA" component.</p>

<h4><a name="BookComponentAppendix-SEDAproducerto%28%E2%80%9Chazelcast%3Aseda%3Afoo%E2%80%9D%29"></a>SEDA producer &#8211; to(“hazelcast:seda:foo”)</h4>

<p>The SEDA producer provides no operations. You only send data to the specified queue.</p>

<div class='table-wrap'>
<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>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.0:</b> if set to true the whole Exchange will be transfered. If header or body contains  not serializable objects, they will be skipped. </td>
</tr>
</tbody></table>
</div>


<p>Java DSL :</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">"hazelcast:seda:foo"</span>);
</pre>
</div></div>

<p>Spring DSL :</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">"direct:start"</span> /&gt;
   &lt;to uri=<span class="code-quote">"hazelcast:seda:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<h4><a name="BookComponentAppendix-SEDAconsumerfrom%28%E2%80%9Chazelcast%3Aseda%3Afoo%E2%80%9D%29"></a>SEDA consumer &#8211; from(“hazelcast:seda:foo”)</h4>

<p>The SEDA consumer provides no operations. You only retrieve data from the specified queue.</p>

<div class='table-wrap'>
<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>pollInterval</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> How frequent to poll from the SEDA queue </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>concurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> To use concurrent consumers polling from the SEDA queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.0:</b> if set to true the whole Exchange will be transfered. If header or body contains  not serializable objects, they will be skipped. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transacted</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10.4:</b> if set to true then the consumer runs in transaction mode, where the messages in the seda queue will only be removed if the transaction commits, which happens when the processing is complete. </td>
</tr>
</tbody></table>
</div>



<p>Java DSL :</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"hazelcast:seda:foo"</span>)
.to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>Spring DSL:</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">"hazelcast:seda:foo"</span> /&gt;
  &lt;to uri=<span class="code-quote">"mock:result"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p><a name="BookComponentAppendix-atomicnumber"></a></p>

<h3><a name="BookComponentAppendix-UsageofAtomicNumber"></a>Usage of Atomic Number</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>There is no consumer for this endpoint&#33;</td></tr></table></div>


<h4><a name="BookComponentAppendix-atomicnumberproducerto%28%22hazelcast%3Aatomicnumber%3Afoo%22%29"></a>atomic number producer - to("hazelcast:atomicnumber:foo")</h4>

<p>An atomic number is an object that simply provides a grid wide number (long). The operations for this producer are setvalue (set the number with a given value), get, increase (+1), decrease (-1) and destroy.</p>

<p>Header Variables for the request message:</p>
<div class='table-wrap'>
<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>hazelcast.operation.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: setvalue, get, increase, decrease, destroy </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastOperationType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> valid values are: setvalue, get, increase, decrease, destroy <b>Available as of Camel version 2.8</b> </td>
</tr>
</tbody></table>
</div>


<h5><a name="BookComponentAppendix-Sampleforset%3A"></a>Sample for <b>set</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:set"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.ATOMICNUMBER_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:set"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;setvalue&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:atomicvalue:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>Provide the value to set inside the message body (here the value is 10): <tt>template.sendBody("direct:set", 10);</tt></p>

<h5><a name="BookComponentAppendix-Sampleforget%3A"></a>Sample for <b>get</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:get"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.ATOMICNUMBER_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:get"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;get&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:atomicvalue:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>You can get the number with <tt>long body = template.requestBody("direct:get", null, Long.class);</tt>.</p>

<h5><a name="BookComponentAppendix-Sampleforincrement%3A"></a>Sample for <b>increment</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:increment"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.INCREMENT_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.ATOMICNUMBER_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:increment"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;increment&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:atomicvalue:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>The actual value (after increment) will be provided inside the message body.</p>

<h5><a name="BookComponentAppendix-Samplefordecrement%3A"></a>Sample for <b>decrement</b>:</h5>

<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:decrement"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DECREMENT_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.ATOMICNUMBER_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:decrement"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;decrement&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:atomicvalue:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>The actual value (after decrement) will be provided inside the message body.</p>

<h5><a name="BookComponentAppendix-Samplefordestroy"></a>Sample for <b>destroy</b></h5>

<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>There's a bug inside Hazelcast. So this feature may not work properly. Will be fixed in 1.9.3.</td></tr></table></div>
<p>Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:destroy"</span>)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DESTROY_OPERATION))
.toF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.ATOMICNUMBER_PREFIX);
</pre>
</div></div>

<p>Spring DSL:</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">"direct:destroy"</span> /&gt;
        &lt;!-- If using version 2.8 and above set headerName to <span class="code-quote">"CamelHazelcastOperationType"</span> --&gt;
	&lt;setHeader headerName=<span class="code-quote">"hazelcast.operation.type"</span>&gt;
		&lt;constant&gt;destroy&lt;/constant&gt;
	&lt;/setHeader&gt;
	&lt;to uri=<span class="code-quote">"hazelcast:atomicvalue:foo"</span> /&gt;
&lt;/route&gt;
</pre>
</div></div>


<p><a name="BookComponentAppendix-cluster"></a></p>

<h3><a name="BookComponentAppendix-clustersupport"></a>cluster support</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>This endpoint provides no producer&#33;</td></tr></table></div>

<h3><a name="BookComponentAppendix-instanceconsumerfrom%28%22hazelcast%3Ainstance%3Afoo%22%29"></a>instance consumer - from("hazelcast:instance:foo")</h3>

<p>Hazelcast makes sense in one single "server node", but it's extremly powerful in a clustered environment. The instance consumer fires if a new cache instance will join or leave the cluster.</p>

<p>Here's a sample:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fromF(<span class="code-quote">"hazelcast:%sfoo"</span>, HazelcastConstants.INSTANCE_PREFIX)
.log(<span class="code-quote">"instance..."</span>)
.choice()
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
		.log(<span class="code-quote">"...added"</span>)
		.to(<span class="code-quote">"mock:added"</span>)
	.otherwise()
		.log(<span class="code-quote">"...removed"</span>)
		.to(<span class="code-quote">"mock:removed"</span>);
</pre>
</div></div>

<p>Each event provides the following information inside the message header:</p>

<p>Header Variables inside the response message:</p>
<div class='table-wrap'>
<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>hazelcast.listener.time</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "instancelistener" </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.listener.action</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b> or <b>removed</b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.instance.host</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> host name of the instance </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>hazelcast.instance.port</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> port number of the instance </td>
</tr>
</tbody></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>Header variables have changed in Camel 2.8</td></tr></table></div>
<div class='table-wrap'>
<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>CamelHazelcastListenerTime</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> time of the event in millis <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> the map consumer sets here "instancelistener" <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastListenerActionn</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> type of event - here <b>added</b> or <b>removed</b>. <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastInstanceHost</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> host name of the instance <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHazelcastInstancePort</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> port number of the instance <b><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Version+2.8&amp;linkCreation=true&amp;fromPageId=25202845" class="createlink">Version 2.8</a></b> </td>
</tr>
</tbody></table>
</div>

<h2><a name="BookComponentAppendix-HDFSComponent"></a>HDFS Component</h2>
<p><b>Available as of Camel 2.8</b></p>

<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" class="external-link" rel="nofollow">Hadoop</a>.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-hdfs<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>append</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Append to existing file. Notice that not all HDFS file systems support the append option. </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, MAP_FILE, ARRAY_FILE, or 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 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 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 how to split the file based on different 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/writing the file is renamed with this suffix to avoid to read it during the 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 renamed with this suffix to avoid to 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) 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 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 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 into chunks producing a message per chunk. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectOnStartup</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3/2.10.1:</b> Whether to connect to the HDFS file system on starting the producer/consumer. If <tt>false</tt> then the connection is created on-demand. Notice that HDFS may take up till 15 minutes to establish a connection, as it has hardcoded 45 x 20 sec redelivery. By setting this option to <tt>false</tt> allows your application to startup, and not block for up till 15 minutes. </td>
</tr>
</tbody></table>
</div>
</div>

<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 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:</p>
<ul>
	<li>BYTES a new file is created, and the old is closed when the number of written bytes is more than &lt;value&gt;</li>
	<li>MESSAGES a new file is created, and the old is closed when the number of written messages is more than  &lt;value&gt;</li>
	<li>IDLE a new file is created, and the old is closed when no writing happened in the last &lt;value&gt; milliseconds</li>
</ul>


<p>for example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hdfs:<span class="code-comment">//localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5</span>
</pre>
</div></div>
<p>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 <tt>hadoop fs -ls /tmp/simple-file</tt> you'll find the following files seg0, seg1, seg2, etc</p>


<h3><a name="BookComponentAppendix-Controllingtoclosefilestream"></a>Controlling to close file stream</h3>
<p><b>Available as of Camel 2.10.4</b></p>

<p>When using the <a href="/confluence/display/CAMEL/HDFS" title="HDFS">HDFS</a> producer <b>without</b> a split strategy, then the file output stream is by default closed after the write. However you may want to keep the stream open, and only explicit close the stream later. For that you can use the header <tt>HdfsConstants.HDFS_CLOSE</tt> (value = <tt>"CamelHdfsClose"</tt>) to control this. Setting this value to a boolean allows you to explicit control whether the stream should be closed or not.</p>

<p>Notice this does not apply if you use a split strategy, as there is varios strategy that control when the stream is closed.</p>


<h3><a name="BookComponentAppendix-UsingthiscomponentinOSGi"></a>Using this component in OSGi</h3>
<p>This component is fully functional in an OSGi environment however, it requires some actions from the user. Hadoop uses the thread context class loader in order to load resources. Usually, the thread context classloader will be the bundle class loader of the bundle that contains the routes. So, the default configuration files need to be visible from the bundle class loader. A typical way to deal with it is to keep a copy of core-default.xml in your bundle root. That file can be found in the hadoop-common.jar.</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/" class="external-link" rel="nofollow">Camel Extra</a> project which hosts all *GPL related components for Camel.</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>Note that Camel also ships with a <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> component. The <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> component abstracts from the underlying persistence provider and allows you to work with Hibernate, OpenJPA or EclipseLink.</td></tr></table></div>

<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" class="external-link" 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 type conversion 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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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" class="external-link" 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" class="external-link" 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" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>
</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/Hibernate+Example" title="Hibernate Example">Hibernate Example</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 <a href="http://www.hl7.org/" class="external-link" rel="nofollow">HL7 v2 messages</a> using the <a href="http://hl7api.sourceforge.net" class="external-link" 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/" class="external-link" 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 ease-of-use as it's integrated well with the <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> (<b>Camel 2.11</b>: <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Mina2&amp;linkCreation=true&amp;fromPageId=92354" class="createlink">camel-mina2</a> ) component.</li>
</ul>


<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-hl7<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<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 mina/mina2 component where we just use the <tt>HL7MLLPCodec</tt> as codec.</p>

<p>The HL7 MLLP codec has the following options:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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. </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.</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. </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://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html" class="external-link" rel="nofollow">charset name</a>) to use for the codec. If not provided, Camel will use the <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html#defaultCharset()" class="external-link" rel="nofollow">JVM default Charset</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>convertLFtoCR</tt> </td>
<td class='confluenceTd'> <tt>true</tt> (<b>Camel 2.11</b>:<tt>false</tt>) </td>
<td class='confluenceTd'> Will convert <tt>\n</tt> to <tt>\r</tt> (<tt>0x0d</tt>, 13 decimal) as HL7 stipulates <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'> Whether HAPI Parser should validate or not. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>parser</tt> </td>
<td class='confluenceTd'> <tt>ca.uhn.hl7v2.parser.PipeParser</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use a custom parser. Must be of type <tt>ca.uhn.hl7v2.parser.Parser</tt>. </td>
</tr>
</tbody></table>
</div>
</div>

<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>
        <span class="code-tag"><span class="code-comment">&lt;!-- Camel 2.11: uri="mina2:tcp... --&gt;</span></span>
</pre>
</div></div>
<p>Notice that we use TCP on <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>Above we also configure the charset encoding to use (<tt>iso-8859-1</tt>).</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">"hl7listener"</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.healthcare.service.PatientLookupService"</span>/&gt;</span>
</pre>
</div></div>
<p>Another powerful feature of Camel is that we can have our business logic in POJO classes that is not 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">import</span> ca.uhn.hl7v2.HL7Exception;
<span class="code-keyword">import</span> ca.uhn.hl7v2.model.Message;
<span class="code-keyword">import</span> ca.uhn.hl7v2.model.v24.segment.QRD;

<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 uses just imports from the HAPI library and <b>not</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 its data format. Camel uses its <a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> to convert to/from strings to the HAPI HL7 model objects. However, you can use plain <tt>String</tt> objects if you prefer, for instance if you wish to parse the data yourself.</p>

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

<h3><a name="BookComponentAppendix-HL7v2ModelusingHAPI"></a>HL7v2 Model using HAPI</h3>
<p>The HL7v2 model uses Java objects from the HAPI library. Using this library, we can encode and decode from the EDI format (ER7) that is mostly used with HL7v2.<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 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</tt> object.<br/>
To retrieve the patient ID in the message 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>If you know the message type in advance, you can be more type-safe:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
QRY_A19 msg = exchange.getIn().getBody(QRY_A19.class);
<span class="code-object">String</span> patientId = msg.getQRD().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 HL7v2 model objects.</p>

<h3><a name="BookComponentAppendix-HL7DataFormat"></a>HL7 DataFormat</h3>
<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 marshal or unmarshal 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>

<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>Segment separators</b><br />As of <b>Camel 2.11</b>, <tt>unmarshal</tt> does not automatically fix segment separators anymore by converting <tt>\n</tt> to <tt>\r</tt>. If you <br/>
need this conversion, <tt>org.apache.camel.component.hl7.HL7#convertLFToCR</tt> provides a handy <tt>Expression</tt> for this purpose.</td></tr></table></div>

<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>

<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>Serializable messages</b><br />As of HAPI 2.0 (used by <b>Camel 2.11</b>), the HL7v2 model classes are fully serializable. So you can put HL7v2 messages directly into a JMS queue (i.e. without calling <tt>marshal()</tt> and read them again directly from the queue (i.e. without calling <tt>unmarshal()</tt>.</td></tr></table></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>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>validate</tt> </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Whether the HAPI Parser should validate using the default validation rules. <b>Camel 2.11:</b> better use the <tt>parser</tt> option and initialize the parser with the desired HAPI <tt>ValidationContext</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>parser</tt> </td>
<td class='confluenceTd'> <tt>ca.uhn.hl7v2.parser.GenericParser</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use a custom parser. Must be of type <tt>ca.uhn.hl7v2.parser.Parser</tt>. Note that <tt>GenericParser</tt> also allows to parse XML-encoded HL7v2 messages. </td>
</tr>
</tbody></table>
</div>

</div>

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

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

<p>The HAPI library since Version 0.6 has been split into a <a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-base" class="external-link" rel="nofollow">base library</a> and several structure libraries, one for each HL7v2 message version:</p>

<ul>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v21" class="external-link" rel="nofollow">v2.1 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v22" class="external-link" rel="nofollow">v2.2 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v23" class="external-link" rel="nofollow">v2.3 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v231" class="external-link" rel="nofollow">v2.3.1 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v24" class="external-link" rel="nofollow">v2.4 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v25" class="external-link" rel="nofollow">v2.5 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v251" class="external-link" rel="nofollow">v2.5.1 structures library</a></li>
	<li><a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-structures-v26" class="external-link" rel="nofollow">v2.6 structures library</a></li>
</ul>


<p>By default <tt>camel-hl7</tt> only references the HAPI <a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-base" class="external-link" rel="nofollow">base library</a>. Applications are responsible for including structure libraries themselves. For example, if a application works with HL7v2 message versions 2.4 and 2.5 then the following dependencies must be added:</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>ca.uhn.hapi<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>hapi-structures-v24<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>1.2<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your hapi-base version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>ca.uhn.hapi<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>hapi-structures-v25<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>1.2<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your hapi-base version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>Alternatively, an OSGi bundle containing the base library, all structures libraries and required dependencies (on the bundle classpath) can be downloaded from the <a href="http://repo1.maven.org/maven2/ca/uhn/hapi/hapi-osgi-base" class="external-link" rel="nofollow">central Maven repository</a>. </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>ca.uhn.hapi<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>hapi-osgi-base<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>1.2<span class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Terserlanguage%28Camel2.11%29"></a>Terser language (<b>Camel 2.11</b>)</h3>

<p><a href="http://hl7api.sourceforge.net" class="external-link" rel="nofollow">HAPI</a> provides a <a href="http://hl7api.sourceforge.net/base/apidocs/ca/uhn/hl7v2/util/Terser.html" class="external-link" rel="nofollow">Terser</a> class that provides access to fields using a commonly used terse location specification syntax. The Terser language allows to use this syntax to extract values from messages and to use them as expressions and predicates for filtering, content-based routing etc.</p>

<p>Sample:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.apache.camel.component.hl7.HL7.terser;
...

   <span class="code-comment">// extract patient ID from field QRD-8 in the QRY_A19 message above and put into message header
</span>   from(<span class="code-quote">"direct:test1"</span>)
      .setHeader(<span class="code-quote">"PATIENT_ID"</span>,terser(<span class="code-quote">"QRD-8(0)-1"</span>))
      .to(<span class="code-quote">"mock:test1"</span>);
   <span class="code-comment">// <span class="code-keyword">continue</span> processing <span class="code-keyword">if</span> extracted field equals a message header
</span>   from(<span class="code-quote">"direct:test2"</span>)
      .filter(terser(<span class="code-quote">"QRD-8(0)-1"</span>)
      .isEqualTo(header(<span class="code-quote">"PATIENT_ID"</span>))
      .to(<span class="code-quote">"mock:test2"</span>);

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


<h3><a name="BookComponentAppendix-HL7Validationpredicate%28Camel2.11%29"></a>HL7 Validation predicate (<b>Camel 2.11</b>)</h3>

<p>Often it is preferable to parse a HL7v2 message and validate it against a HAPI <a href="http://hl7api.sourceforge.net/base/apidocs/ca/uhn/hl7v2/validation/ValidationContext.html" class="external-link" rel="nofollow">ValidationContext</a> in a separate step afterwards.</p>

<p>Sample:</p>

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

<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.apache.camel.component.hl7.HL7.messageConformsTo;
<span class="code-keyword">import</span> ca.uhn.hl7v2.validation.impl.DefaultValidation;
...

  <span class="code-comment">// Use standard or define your own validation rules
</span>   ValidationContext defaultContext = <span class="code-keyword">new</span> DefaultValidation(); 

   <span class="code-comment">// Throws PredicateValidationException <span class="code-keyword">if</span> message does not validate
</span>   from(<span class="code-quote">"direct:test1"</span>).validate(messageConformsTo(defaultContext)).to(<span class="code-quote">"mock:test1"</span>);
</pre>
</div></div>


<h3><a name="BookComponentAppendix-HL7Acknowledgementexpression%28Camel2.11%29"></a>HL7 Acknowledgement expression (<b>Camel 2.11</b>)</h3>

<p>A common task in HL7v2 processing is to generate an acknowledgement message as response to an incoming HL7v2 message, e.g. based on a validation result. The <tt>ack</tt> expression lets us accomplish this very elegantly:</p>

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

<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.apache.camel.component.hl7.HL7.messageConformsTo;
<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.apache.camel.component.hl7.HL7.ack;
<span class="code-keyword">import</span> ca.uhn.hl7v2.validation.impl.DefaultValidation;
...

  <span class="code-comment">// Use standard or define your own validation rules
</span>   ValidationContext defaultContext = <span class="code-keyword">new</span> DefaultValidation(); 

   from(<span class="code-quote">"direct:test1"</span>)
      .onException(Exception.class)
         .handled(<span class="code-keyword">true</span>)
         .transform(ack()) <span class="code-comment">// auto-generates negative ack because of exception in Exchange
</span>         .end()
      .validate(messageConformsTo(defaultContext))
      <span class="code-comment">// <span class="code-keyword">do</span> something meaningful here
</span>      ...
      <span class="code-comment">// acknowledgement
</span>      .transform(ack())
</pre>
</div></div>


<h3><a name="BookComponentAppendix-MoreSamples"></a>More Samples</h3>
<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>;

StringBuilder in = <span class="code-keyword">new</span> StringBuilder();
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">"mina2: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">"mina2: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">// marshal 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 preconfigured 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>

<h4><a name="BookComponentAppendix-SampleusingplainStringobjects"></a>Sample using plain String objects</h4>
<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">"mina2: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">"mina2: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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-http<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
http:hostname[:port][/resourceUri][?param1=value1][&amp;param2=value2]
</pre>
</div></div>
<p>Will by default use port 80 for HTTP and 443 for HTTPS.</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 />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> or the <a href="/confluence/display/CAMEL/SERVLET" title="SERVLET">Servlet Component</a></td></tr></table></div>

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

<p>Call the url with the body using POST and return response as out message. If body is null call URL using GET and return response as out message</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
<th class='confluenceTh'>Spring DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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">//myhost/mypath"</span>);</span></pre>
</div></div></td>
<td class='confluenceTd'><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">"direct:start"</span>/&gt;</span>
<span class="code-tag">&lt;to uri=<span class="code-quote">"http://oldhost"</span>/&gt;</span></pre>
</div></div></td>
</tr>
</tbody></table>
</div>


<p>You can override the HTTP endpoint URI by adding a header. Camel will call the <a href="http://newhost" class="external-link" rel="nofollow">http://newhost</a>. This is very handy for e.g. REST urls.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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_URI, simple(<span class="code-quote">"http:<span class="code-comment">//myserver/orders/${header.orderId}"</span>))
</span>  .to(<span class="code-quote">"http:<span class="code-comment">//dummyhost"</span>);</span></pre>
</div></div></td>
</tr>
</tbody></table>
</div>


<p>URI parameters can either be set directly on the endpoint URI or as a header</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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>from(<span class="code-quote">"direct:start"</span>)
  .setHeader(Exchange.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></td>
</tr>
</tbody></table>
</div>


<p>Set the HTTP request method to POST</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
<th class='confluenceTh'>Spring DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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(<span class="code-quote">"POST"</span>))
  .to(<span class="code-quote">"http:<span class="code-comment">//www.google.com"</span>);</span>
</pre>
</div></div></td>
<td class='confluenceTd'><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">"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>
</pre>
</div></div></td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-HttpEndpointOptions"></a>HttpEndpoint Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> 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'> 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. <br class="atl-forced-newline" />
<b>Camel 2.3:</b> If the option is true, HttpProducer and CamelServlet will skip the gzip processing if the content-encoding is "gzip". </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableStreamCache</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support read it twice, otherwise DefaultHttpBinding will set the request input stream direct into the message body. </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>. From Camel 2.3 onwards prefer to use the <tt>httpBinding</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpBinding</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>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>. From Camel 2.3 onwards prefer to use the <tt>httpClientConfigurer</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientConfigurer</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" class="external-link" rel="nofollow">HttpClientParams</a>. For instance <tt>httpClient.soTimeout=5000</tt> will set the <tt>SO_TIMEOUT</tt> to 5 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>clientConnectionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a custom <tt>org.apache.http.conn.ClientConnectionManager</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> If enabled and an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> failed processing on the consumer side, and if the caused <tt>Exception</tt> was send back serialized in the response as a <tt>application/x-java-serialized-object</tt> content type (for example using <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> or <a href="/confluence/display/CAMEL/SERVLET" title="SERVLET">SERVLET</a> Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the <tt>HttpOperationFailedException</tt>. The caused exception is required to be serialized. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Reference to a instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. It will be used to apply the custom headerFilterStrategy on the new create HttpEndpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>urlRewrite</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b> Refers to a custom <tt>org.apache.camel.component.http.UrlRewrite</tt> which allows you to rewrite urls when you bridge/proxy endpoints. See more details at <a href="/confluence/display/CAMEL/UrlRewrite" title="UrlRewrite">UrlRewrite</a> and <a href="/confluence/display/CAMEL/How+to+use+Camel+as+a+HTTP+proxy+between+a+client+and+server" title="How to use Camel as a HTTP proxy between a client and server">How to use Camel as a HTTP proxy between a client and server</a>. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-AuthenticationandProxy"></a>Authentication and Proxy</h3>

<p>The following authentication options can also be set on the HttpEndpoint:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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>authMethod</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Authentication method, either as <tt>Basic</tt>, <tt>Digest</tt> or <tt>NTLM</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>authMethodPriority</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Priority of authentication methods. Is a list separated with comma. For example: <tt>Basic,Digest</tt> to exclude <tt>NTLM</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>authUsername</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username for authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>authPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password for authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>authDomain</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Domain for NTML authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>authHost</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Optional host for 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 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyPort</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The proxy port number </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyAuthMethod</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Authentication method for proxy, either as <tt>Basic</tt>, <tt>Digest</tt> or <tt>NTLM</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyAuthUsername</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username for proxy authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyAuthPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password for proxy authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyAuthDomain</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Domain for proxy NTML authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyAuthHost</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Optional host for proxy NTML authentication </td>
</tr>
</tbody></table>
</div>
</div>

<p>When using authentication you <b>must</b> provide the choice of method for the <tt>authMethod</tt> or <tt>authProxyMethod</tt> options.<br/>
You can configure the proxy and authentication details on either the <tt>HttpComponent</tt> or the <tt>HttpEndoint</tt>. Values provided on the <tt>HttpEndpoint</tt> will take precedence over <tt>HttpComponent</tt>. Its most likely best to configure this on the <tt>HttpComponent</tt> which allows you to do this once.</p>

<p>The <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a> component uses convention over configuration which means that if you have not explicit set a <tt>authMethodPriority</tt> then it will fallback and use the select(ed) <tt>authMethod</tt> as priority as well. So if you use <tt>authMethod.Basic</tt> then the <tt>auhtMethodPriority</tt> will be <tt>Basic</tt> only.</p>

<h3><a name="BookComponentAppendix-HttpComponentOptions"></a>HttpComponent Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>httpBinding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a custom <tt>org.apache.camel.component.http.HttpBinding</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientConfigurer</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a custom <tt>org.apache.camel.component.http.HttpClientConfigurer</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpConnectionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a custom <tt>org.apache.commons.httpclient.HttpConnectionManager</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpConfiguration</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a custom <tt>org.apache.camel.component.http.HttpConfiguration</tt> </td>
</tr>
</tbody></table>
</div>
</div>
<p><tt>HttpConfiguration</tt> contains all the options listed in the table above under the section <em>HttpConfiguration - Setting Authentication and Proxy</em>.</p>

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

<div class="confluenceTableSmall"><div class='table-wrap'>
<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_METHOD</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> HTTP Method / Verb to use (GET/POST/PUT/DELETE/HEAD/OPTIONS/TRACE) </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, the header will be used to build the request URI with the HTTP_URI. <b>Camel 2.3.0:</b> If the path is start with "/", http producer will try to find the relative path based on the Exchange.HTTP_BASE_URI header or the exchange.getFromEndpoint().getEndpointUri(); </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>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_SERVLET_REQUEST</tt> </td>
<td class='confluenceTd'> <tt>HttpServletRequest</tt> </td>
<td class='confluenceTd'> The <tt>HttpServletRequest</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_SERVLET_RESPONSE</tt> </td>
<td class='confluenceTd'> <tt>HttpServletResponse</tt> </td>
<td class='confluenceTd'> The <tt>HttpServletResponse</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_PROTOCOL_VERSION</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> You can set the http protocol version with this header, eg. "HTTP/1.0". If you didn't specify the header, HttpProducer will use the default value "HTTP/1.1" </td>
</tr>
</tbody></table>
</div>
</div>

<p>The header name above are constants. For the spring DSL you have to use the value of the constant instead of the name.</p>

<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+, 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 />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.</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.lang.String</tt>, if server provided a body as response</li>
</ul>


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

<p>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>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>

<h3><a name="BookComponentAppendix-UsingclienttimeoutSOTIMEOUT"></a>Using client timeout - SO_TIMEOUT</h3>

<p>See the unit test in <a href="http://svn.apache.org/viewvc?view=rev&amp;revision=781775" class="external-link" rel="nofollow">this link</a></p>

<h2><a name="BookComponentAppendix-MoreExamples"></a>More Examples</h2>

<h3><a name="BookComponentAppendix-ConfiguringaProxy"></a>Configuring a Proxy</h3>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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></td>
</tr>
</tbody></table>
</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>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Java DSL</th>
<th class='confluenceTh'>Spring DSL</th>
</tr>
<tr>
<td class='confluenceTd'><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></td>
<td class='confluenceTd'><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></td>
</tr>
</tbody></table>
</div>


<p>Options on Endpoint will override options on the context.</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></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
setProperty(Exchange.CHARSET_NAME, <span class="code-quote">"iso-8859-1"</span>);
</pre>
</div></div>

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

<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>

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

<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(Exchange.HTTP_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>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:{{port}}/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:{{port}}/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-Usingpreemptiveauthentication"></a>Using preemptive authentication</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-Acceptingselfsignedcertificatesfromremoteserver"></a>Accepting self signed certificates 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" class="external-link" 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>


<h5><a name="BookComponentAppendix-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h5>

<p>As of Camel 2.8, the HTTP4 component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp;  This utility greatly decreases the amount of component specific code  you need to write and is configurable at the endpoint and component  levels.&nbsp; The following examples demonstrate how to use the utility with  the HTTP4 component.</p>

<p>The version of the Apache HTTP client used in this component resolves SSL/TLS information from a global "protocol" registry.&nbsp; This component provides an implementation, <tt>org.apache.camel.component.http.SSLContextParametersSecureProtocolSocketFactory</tt>, of the HTTP client's protocol socket factory in order to support the use of the Camel JSSE Configuration utility.&nbsp; The following example demonstrates how to configure the protocol registry and use the registered protocol information in a route.</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
KeyStoreParameters ksp = <span class="code-keyword">new</span> KeyStoreParameters();
ksp.setResource(<span class="code-quote">"/users/home/server/keystore.jks"</span>);
ksp.setPassword(<span class="code-quote">"keystorePassword"</span>);

KeyManagersParameters kmp = <span class="code-keyword">new</span> KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword(<span class="code-quote">"keyPassword"</span>);

SSLContextParameters scp = <span class="code-keyword">new</span> SSLContextParameters();
scp.setKeyManagers(kmp);

ProtocolSocketFactory factory =
    <span class="code-keyword">new</span> SSLContextParametersSecureProtocolSocketFactory(scp);

Protocol.registerProtocol(<span class="code-quote">"https"</span>,
        <span class="code-keyword">new</span> Protocol(
        <span class="code-quote">"https"</span>,
        factory,
        443));

from(<span class="code-quote">"direct:start"</span>)
        .to(<span class="code-quote">"https:<span class="code-comment">//mail.google.com/mail/"</span>).to(<span class="code-quote">"mock:results"</span>);</span>
</pre>
</div></div>

<h5><a name="BookComponentAppendix-ConfiguringApacheHTTPClientDirectly"></a>Configuring Apache HTTP Client Directly</h5>

<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/" class="external-link" rel="nofollow">Apache iBATIS</a>.</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>Prefer MyBatis</b><br />The Apache iBatis project is no longer active. The project is moved outside Apache and is now know as the MyBatis project.<br/>
Therefore we encourage users to use <a href="/confluence/display/CAMEL/MyBatis" title="MyBatis">MyBatis</a> instead. This camel-ibatis component will be removed in Camel 3.0.</td></tr></table></div>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-ibatis<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> 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'> 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'> 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>
<tr>
<td class='confluenceTd'> <tt>isolation</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>TRANSACTION_REPEATABLE_READ</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> A String the defines the transaction isolation level of the will be used. Allowed values are TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE </td>
</tr>
</tbody></table>
</div>


<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> <tt>isolation</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>TRANSACTION_REPEATABLE_READ</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> A String the defines the transaction isolation level of the will be used. Allowed values are TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE </td>
</tr>
</tbody></table>
</div>

</div>

<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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>CamelIBatisStatementName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> 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'> 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>
</div>
</div>

<h3><a name="BookComponentAppendix-MessageBody"></a>Message Body</h3>
<p>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>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. 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>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/MyBatis" title="MyBatis">MyBatis</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" class="external-link" rel="nofollow">IRC</a> (Internet Relay Chat) transport.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-irc<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
irc:nick@host[:port]/#room[?options]
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> 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'> 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>
<tr>
<td class='confluenceTd'> sslContextParameters </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="http://camel.apache.org/registry.html" class="external-link" rel="nofollow">Registry</a>.&nbsp; This reference overrides any configured SSLContextParameters at the component level.&nbsp; See <a href="http://camel.apache.org/http4.html#HTTP4-UsingtheJSSEConfigurationUtility" class="external-link" rel="nofollow">Using the JSSE Configuration Utility</a>.&nbsp; Note that this setting overrides the trustManager option. </td>
<td class='confluenceTd'> &#35;mySslContextParameters <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-SSLSupport"></a>SSL Support</h3>

<h4><a name="BookComponentAppendix-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h4>

<p>As of Camel 2.9, the IRC component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp; This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels.&nbsp; The following examples demonstrate how to use the utility with the IRC component.</p>

<h5><a name="BookComponentAppendix-Programmaticconfigurationoftheendpoint"></a>Programmatic configuration of the endpoint</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
KeyStoreParameters ksp = <span class="code-keyword">new</span> KeyStoreParameters();
ksp.setResource(<span class="code-quote">"/users/home/server/truststore.jks"</span>);
ksp.setPassword(<span class="code-quote">"keystorePassword"</span>);

TrustManagersParameters tmp = <span class="code-keyword">new</span> TrustManagersParameters();
tmp.setKeyStore(ksp);

SSLContextParameters scp = <span class="code-keyword">new</span> SSLContextParameters();
scp.setTrustManagers(tmp);

Registry registry = ...
registry.bind(<span class="code-quote">"sslContextParameters"</span>, scp);

...

from(...)
    .to(<span class="code-quote">"ircs:<span class="code-comment">//camel-prd-user@server:6669/#camel-test?nickname=camel-prd&amp;password=password&amp;sslContextParameters=#sslContextParameters"</span>);
</span>
</pre>
</div></div>

<h5><a name="BookComponentAppendix-SpringDSLbasedconfigurationofendpoint"></a>Spring DSL based configuration of endpoint</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
...
  &lt;camel:sslContextParameters
      id=<span class="code-quote">"sslContextParameters"</span>&gt;
    <span class="code-tag">&lt;camel:trustManagers&gt;</span>
      &lt;camel:keyStore
          resource=<span class="code-quote">"/users/home/server/truststore.jks"</span>
          password=<span class="code-quote">"keystorePassword"</span>/&gt;
    <span class="code-tag">&lt;/camel:keyManagers&gt;</span>
  <span class="code-tag">&lt;/camel:sslContextParameters&gt;</span>...
...
  <span class="code-tag">&lt;to uri=<span class="code-quote">"ircs://camel-prd-user@server:6669/#camel-test?nickname=camel-prd&amp;password=password&amp;sslContextParameters=#sslContextParameters"</span>/&gt;</span>...
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Usingthelegacybasicconfigurationoptions"></a>Using the legacy basic configuration options</h4>

<p>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" class="external-link" 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-Jasyptcomponent"></a>Jasypt component</h2>
<p><b>Available as of Camel 2.5</b></p>

<p><a href="http://www.jasypt.org/" class="external-link" rel="nofollow">Jasypt</a> is a simplified encryption library which makes encryption and decryption easy. Camel integrates with Jasypt to allow sensitive information in <a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a> files to be encrypted. By dropping <b><tt>camel-jasypt</tt></b> on the classpath those encrypted values will automatic be decrypted on-the-fly by Camel. This ensures that human eyes can't easily spot sensitive information such as usernames and passwords.</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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-jasypt<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

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

<p>The <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a> component provides a little command line tooling to encrypt or decrypt values.</p>

<p>The console output the syntax and which options it provides:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Apache Camel Jasypt takes the following options

  -h or -help = Displays the help screen
  -c or -command &lt;command&gt; = Command either encrypt or decrypt
  -p or -password &lt;password&gt; = Password to use
  -i or -input &lt;input&gt; = Text to encrypt or decrypt
  -a or -algorithm &lt;algorithm&gt; = Optional algorithm to use
</pre>
</div></div>

<p>For example to encrypt the value <tt>tiger</tt> you run with the following parameters. In the apache camel kit, you cd into the lib folder and run the following java cmd, where <em>&lt;CAMEL_HOME&gt;</em> is where you have downloaded and extract the Camel distribution.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ cd &lt;CAMEL_HOME&gt;/lib
$ java -jar camel-jasypt-2.5.0.jar -c encrypt -p secret -i tiger
</pre>
</div></div>
<p>Which outputs the following result</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Encrypted text: qaEEacuW7BUti8LcMgyjKw==
</pre>
</div></div>
<p>This means the encrypted representation <tt>qaEEacuW7BUti8LcMgyjKw==</tt> can be decrypted back to <tt>tiger</tt> if you know the master password which was <tt>secret</tt>.<br/>
If you run the tool again then the encrypted value will return a different result. But decrypting the value will always return the correct original value.</p>

<p>So you can test it by running the tooling using the following parameters:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ cd &lt;CAMEL_HOME&gt;/lib
$ java -jar camel-jasypt-2.5.0.jar -c decrypt -p secret -i qaEEacuW7BUti8LcMgyjKw==
</pre>
</div></div>
<p>Which outputs the following result:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Decrypted text: tiger
</pre>
</div></div>

<p>The idea is then to use those encrypted values in your <a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a> files. Notice how the password value is encrypted and the value has the tokens surrounding <tt>ENC(value here)</tt></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"># refer to a mock endpoint name by that encrypted password
cool.result=mock:{{cool.password}}

# here is a password which is encrypted
cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ToolingdependenciesforCamel2.5and2.6"></a>Tooling dependencies for Camel 2.5 and 2.6</h4>

<p>The tooling requires the following JARs in the classpath, which has been enlisted in the <tt>MANIFEST.MF</tt> file of <tt>camel-jasypt</tt> with <tt>optional/</tt> as prefix. Hence why the java cmd above can pickup the needed JARs from the Apache Distribution in the <tt>optional</tt> directory.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jasypt-1.6.jar commons-lang-2.4.jar commons-codec-1.4.jar icu4j-4.0.1.jar
</pre>
</div></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>Java 1.5 users</b><br />The <tt>icu4j-4.0.1.jar</tt> is only needed when running on JDK 1.5.

<p>This JAR is not distributed by Apache Camel and you have to download it manually and copy it to the <tt>lib/optional</tt> directory of the Camel distribution.<br/>
You can download it from <a href="http://repo2.maven.org/maven2/com/ibm/icu/icu4j/4.0.1/" class="external-link" rel="nofollow">Apache Central Maven repo</a>.</p></td></tr></table></div>

<h4><a name="BookComponentAppendix-ToolingdependenciesforCamel2.7orbetter"></a>Tooling dependencies for Camel 2.7 or better</h4>

<p>Jasypt 1.7 onwards is now fully standalone so no additional JARs is needed.</p>

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>
<p>The options below are exclusive for the <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a> component. </p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Type </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'> <tt>String</tt> </td>
<td class='confluenceTd'> Specifies the master password to use for decrypting. This option is mandatory. See below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>algorithm</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Name of an optional algorithm to use. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-Protectingthemasterpassword"></a>Protecting the master password</h3>
<p>The master password used by <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a> must be provided, so its capable of decrypting the values. However having this master password out in the opening may not be an ideal solution. Therefore you could for example provided it as a JVM system property or as a OS environment setting. If you decide to do so then the <tt>password</tt> option supports prefixes which dictates this. <tt>sysenv:</tt> means to lookup the OS system environment with the given key. <tt>sys:</tt> means to lookup a JVM system property.</p>

<p>For example you could provided the password before you start the application</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ export CAMEL_ENCRYPTION_PASSWORD=secret
</pre>
</div></div>
<p>Then start the application, such as running the start script.</p>

<p>When the application is up and running you can unset the environment</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ unset CAMEL_ENCRYPTION_PASSWORD
</pre>
</div></div>

<p>The <tt>password</tt> option is then a matter of defining as follows: <tt>password=sysenv:CAMEL_ENCRYPTION_PASSWORD</tt>.</p>

<h3><a name="BookComponentAppendix-ExamplewithJavaDSL"></a>Example with Java DSL</h3>

<p>In Java DSL you need to configure <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a> as a <tt>JasyptPropertiesParser</tt> instance and set it on the <a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a> component as show below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// create the jasypt properties parser
</span>JasyptPropertiesParser jasypt = <span class="code-keyword">new</span> JasyptPropertiesParser();
<span class="code-comment">// and set the master password
</span>jasypt.setPassword(<span class="code-quote">"secret"</span>);

<span class="code-comment">// create the properties component
</span>PropertiesComponent pc = <span class="code-keyword">new</span> PropertiesComponent();
pc.setLocation(<span class="code-quote">"classpath:org/apache/camel/component/jasypt/myproperties.properties"</span>);
<span class="code-comment">// and use the jasypt properties parser so we can decrypt values
</span>pc.setPropertiesParser(jasypt);

<span class="code-comment">// add properties component to camel context
</span>context.addComponent(<span class="code-quote">"properties"</span>, pc);
</pre>
</div></div>

<p>The properties file <tt>myproperties.properties</tt> then contain the encrypted value, such as shown below. Notice how the password value is encrypted and the value has the tokens surrounding <tt>ENC(value here)</tt></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"># refer to a mock endpoint name by that encrypted password
cool.result=mock:{{cool.password}}

# here is a password which is encrypted
cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ExamplewithSpringXML"></a>Example with Spring XML</h3>

<p>In Spring XML you need to configure the <tt>JasyptPropertiesParser</tt> which is shown below. Then the Camel <a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a> component is told to use <tt>jasypt</tt> as the properties parser, which means <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a> have its chance to decrypt values looked up in the properties. </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 jasypt properties parser with the given password to be used --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"jasypt"</span> class=<span class="code-quote">"org.apache.camel.component.jasypt.JasyptPropertiesParser"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"secret"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- define the camel properties component --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"properties"</span> class=<span class="code-quote">"org.apache.camel.component.properties.PropertiesComponent"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- the properties file is in the classpath --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"location"</span> value=<span class="code-quote">"classpath:org/apache/camel/component/jasypt/myproperties.properties"</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- and let it leverage the jasypt parser --&gt;</span></span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"propertiesParser"</span> ref=<span class="code-quote">"jasypt"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>The <a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a> component can also be inlined inside the <tt>&lt;camelContext&gt;</tt> tag which is shown below. Notice how we use the <tt>propertiesParserRef</tt> attribute to refer to <a href="/confluence/display/CAMEL/Jasypt" title="Jasypt">Jasypt</a>.</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 jasypt properties parser with the given password to be used --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"jasypt"</span> class=<span class="code-quote">"org.apache.camel.component.jasypt.JasyptPropertiesParser"</span>&gt;</span>
    &lt;!-- password is mandatory, you can prefix it with sysenv: or sys: to indicate it should use
         an OS environment or JVM system property value, so you dont have the master password defined here --&gt;
    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"secret"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- define the camel properties placeholder, and let it leverage jasypt --&gt;</span></span>
    &lt;propertyPlaceholder id=<span class="code-quote">"properties"</span>
                         location=<span class="code-quote">"classpath:org/apache/camel/component/jasypt/myproperties.properties"</span>
                         propertiesParserRef=<span class="code-quote">"jasypt"</span>/&gt;
    <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">"{{cool.result}}"</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-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Security" title="Security">Security</a></li>
	<li><a href="/confluence/display/CAMEL/Properties" title="Properties">Properties</a></li>
	<li><a href="http://activemq.apache.org/encrypted-passwords.html" class="external-link" rel="nofollow">Encrypted passwords in ActiveMQ</a> - ActiveMQ has a similar feature as this <tt>camel-jasypt</tt> component</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/" class="external-link" rel="nofollow">Blitz implementation </a> and the <a href="http://www.gigaspaces.com/" class="external-link" 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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-javaspace<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

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

<h4><a name="BookComponentAppendix-SendingandReceivingEntries"></a>Sending and Receiving Entries</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// sending route
</span>from(<span class="code-quote">"direct:input"</span>)
    .to(<span class="code-quote">"javaspace:jini:<span class="code-comment">//localhost?spaceName=mySpace"</span>);
</span>
<span class="code-comment">// receiving Route
</span>from(<span class="code-quote">"javaspace:jini:<span class="code-comment">//localhost?spaceName=mySpace&amp;templateId=template&amp;verb=take&amp;concurrentConsumers=1"</span>)
</span>    .to(<span class="code-quote">"mock:foo"</span>);
</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="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// client side
</span>from(<span class="code-quote">"direct:input"</span>)
    .to(<span class="code-quote">"javaspace:jini:<span class="code-comment">//localhost?spaceName=mySpace"</span>);
</span>
<span class="code-comment">// server side
</span>from(<span class="code-quote">"javaspace:jini:<span class="code-comment">//localhost?concurrentConsumers=10&amp;spaceName=mySpace"</span>)
</span>    .to(<span class="code-quote">"mock:foo"</span>);
</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-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" class="external-link" 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/" class="external-link" 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>See below for information about how to use <tt>StreamSource</tt> types from <a href="http://servicemix.apache.org/" class="external-link" rel="nofollow">ServiceMix</a> in Camel.</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" class="external-link" 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" class="external-link" 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>
<div class='table-wrap'>
<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.  Set to <tt>nocheck</tt> to disable this check altogether, note that this should only be used for in-memory transports like SEDAFlow, otherwise you can expect to get <tt>NotSerializableException</tt> thrown at runtime. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>convertException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <tt>false</tt>: send any exceptions thrown from the Camel route back unmodified <br class="atl-forced-newline" /> <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>
</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">
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>The stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt> option.<br/>
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" class="external-link" 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;x.x.x&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" class="external-link" rel="nofollow">ServiceMix Camel module</a></li>
	<li><a href="http://servicemix.apache.org/3-beginner-using-apache-camel-inside-servicemix.html" class="external-link" rel="nofollow">Using Camel with ServiceMix</a></li>
	<li><a href="http://servicemix.apache.org/order-file-processing.html" class="external-link" 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/read nodes to/from a JCR compliant content repository (for example, <a href="http://jackrabbit.apache.org/" class="external-link" rel="nofollow">Apache Jackrabbit</a>) with its producer, or register an EventListener with the consumer.</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-jcr&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">
jcr:<span class="code-comment">//user:password@repository/path/to/node</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>Consumer added</b><br />From <b>Camel 2.10</b> onwards you can use consumer as an EventListener in JCR or a producer to read a node by identifier.</td></tr></table></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>

<h4><a name="BookComponentAppendix-Producer"></a>Producer</h4>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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>CamelJcrOperation</tt> </td>
<td class='confluenceTd'> <tt>CamelJcrInsert</tt> </td>
<td class='confluenceTd'> CamelJcrInsert or CamelJcrGetById operation to use </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJcrNodeName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Used to determine the node name to use. </td>
</tr>
</tbody></table>
</div>
</div>

<p>When a message is sent to a JCR producer endpoint:</p>
<ul>
	<li>If the operation is CamelJcrInsert: A new node is created in the content repository, all the message properties of the IN message are transformed to JCR <tt>Value</tt> instances and added to the new node and the node's UUID is returned in the OUT message.</li>
	<li>If the operation is CamelJcrGetById: A new node is retrieved from the repository using the message body as node identifier.</li>
</ul>


<h4><a name="BookComponentAppendix-Consumer"></a>Consumer</h4>
<p>The consumer will connect to JCR periodically and return a List&lt;javax.jcr.observation.Event&gt; in the message body. </p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>eventTypes</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> A combination of one or more event types encoded as a bit mask value such as javax.jcr.observation.Event.NODE_ADDED, javax.jcr.observation.Event.NODE_REMOVED, etc. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deep</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> When it is true, events whose associated parent node is at current path or within its subgraph are received. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>uuids</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Only events whose associated parent node has one of the identifiers in the comma separated uuid list will be received.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nodeTypeNames</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Only events whose associated parent node has one of the node types (or a subtype of one of the node types) in this list will be received. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>noLocal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>noLocal</tt> is <tt>true</tt>, then events generated by the session through which the listener was registered are ignored. Otherwise, they are not ignored. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sessionLiveCheckInterval</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> Interval in milliseconds to wait before each session live checking. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sessionLiveCheckIntervalOnStart</tt> </td>
<td class='confluenceTd'> <tt>3000</tt> </td>
<td class='confluenceTd'> Interval in milliseconds to wait before the first session live checking. </td>
</tr>
</tbody></table>
</div>
</div>

<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>

<p>The following code will register an EventListener under the path import-application/inbox for Event.NODE_ADDED and Event.NODE_REMOVED events (event types 1 and 2, both masked as 3) and listening deep for all the children.</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">"jcr://user:pass@repository/import-application/inbox?eventTypes=3&amp;deep=true"</span> /&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:execute-import-application"</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>

<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>

<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-jdbc&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='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>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.</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>This component can not be used as a <a href="http://camel.apache.org/transactional-client.html" class="external-link" rel="nofollow">Transactional Client</a>. If you need transaction support in your route, you should use the <a href="http://camel.apache.org/sql-component.html" class="external-link" rel="nofollow">SQL component</a> instead.</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>

<div class='table-wrap'>
<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> </td>
<td class='confluenceTd'> The default maximum number of rows that can be read by a polling query. 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" class="external-link" 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 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>
<tr>
<td class='confluenceTd'> <tt>resetAutoCommit</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Camel will set the autoCommit on the JDBC connection to be false, commit the change after executed the statement and reset the autoCommit flag of the connection at the end, if the resetAutoCommit is true. If the JDBC connection doesn't support to reset the autoCommit flag, you can set the resetAutoCommit flag to be false, and Camel will not try to reset the autoCommit flag.</td>
</tr>
</tbody></table>
</div>


<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>
<div class='table-wrap'>
<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>
<tr>
<td class='confluenceTd'> <tt>CamelGeneratedKeysRows</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Rows that contains the generated kets. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeneratedKeysRowCount</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> The number of rows in the header that contains generated keys. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Generatedkeys"></a>Generated keys</h3>
<p><b>Available as of Camel 2.10</b></p>

<p>If you insert data using SQL INSERT, then the RDBMS may support auto generated keys. You can instruct the <a href="/confluence/display/CAMEL/JDBC" title="JDBC">JDBC</a> producer to return the generated keys in headers.<br/>
To do that set the header <tt>CamelRetrieveGeneratedKeys=true</tt>. Then the generated keys will be provided as headers with the keys listed in the table above.</p>

<p>You can see more details in this <a href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcGeneratedKeysTest.java" class="external-link" rel="nofollow">unit test</a>.</p>


<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>, db);
<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;!-- trigger every second --&gt;
     &lt;from uri=<span class="code-quote">"timer:<span class="code-comment">//kickoff?period=1s"</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;jdbc:embedded-database id=<span class="code-quote">"testdb"</span> type=<span class="code-quote">"DERBY"</span>&gt;
	&lt;jdbc:script location=<span class="code-quote">"classpath:sql/init.sql"</span>/&gt;
&lt;/jdbc:embedded-database&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());
List&lt;Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;&gt; data = out.getOut().getBody(List.class);
assertNotNull(data);
assertEquals(3, data.size());
Map&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>The <b>jetty</b> component provides HTTP-based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br/>
Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</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>Stream</b><br />Jetty is stream based, which means the input it receives is submitted to Camel as a stream. That means you will only be able to read the content of the stream <b>once</b>.<br/>
If you find a situation where the message body appears to be empty or you need to access the data multiple times (eg: doing multicasting, or redelivery error handling)<br/>
you should use <a href="/confluence/display/CAMEL/Stream+caching" title="Stream caching">Stream caching</a> or convert the message body to a <tt>String</tt> which is safe to be re-read multiple times.</td></tr></table></div>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-jetty<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
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>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> Configuration of Jetty's <a href="http://wiki.eclipse.org/Jetty/Tutorial/HttpClient" class="external-link" 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>httpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a shared <tt>org.eclipse.jetty.client.HttpClient</tt> for all producers created by this endpoint. This option should only be used in special circumstances. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMinThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b>: To set a value for minimum number of threads in <tt>HttpClient</tt> thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMaxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b>: To set a value for maximum number of threads in <tt>HttpClient</tt> thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. </td>
</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>. <tt>HttpBinding</tt> can be used to customize how a response should be written for the consumer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jettyHttpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6.0+:</b> Reference to an <tt>org.apache.camel.component.jetty.JettyHttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. <tt>JettyHttpBinding</tt> can be used to customize how a response should be written for the producer. </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. See here <a href="/confluence/display/CAMEL/How+do+I+let+Jetty+match+wildcards" title="How do I let Jetty match wildcards">How do I let Jetty match wildcards</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>handlers</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 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>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>
<tr>
<td class='confluenceTd'> <tt>enableJmx</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If this option is true, Jetty JMX support will be enabled for this endpoint. See <a href="#BookComponentAppendix-JettyJMXsupport">Jetty JMX support</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableStreamCache</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Determines whether or not the raw input stream from Jetty is cached or not (Camel will read the stream into a in memory/overflow to file, <a href="/confluence/display/CAMEL/Stream+caching" title="Stream caching">Stream caching</a>) cache. By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to <tt>true</tt> when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store. DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is <tt>false</tt> to support reading the stream multiple times. If you use <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> to bridge/proxy an endpoint then consider enabling this option to improve performance, in case you do not need to read the message payload multiple times. </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>throwExceptionOnFailure</b> to be false to let the HttpProducer send all the fault response back. <br class="atl-forced-newline" />
<b>Camel 2.3:</b> If the option is true, HttpProducer and CamelServlet will skip the gzip processing if the content-encoding is "gzip". Also consider setting <b>disableStreamCache</b> to true to optimize when bridging. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>enableMultipartFilter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Whether Jetty <tt>org.eclipse.jetty.servlets.MultiPartFilter</tt> is enabled or not. You should set this value to <tt>false</tt> when bridging endpoints, to ensure multipart requests is proxied/bridged as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multipartFilterRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Allows using a custom multipart filter. Note: setting <tt>multipartFilterRef</tt> forces the value of <tt>enableMultipartFilter</tt> to <tt>true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filtersRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Allows using a custom filters which is putted into a list and can be find in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>continuationTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Allows to set a timeout in millis when using <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> as consumer (server). By default Jetty uses 30000. You can use a value of <tt>&lt;= 0</tt> to never expire. If a timeout occurs then the request will be expired and Jetty will return back a http error 503 to the client. This option is only in use when using <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> with the <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">Asynchronous Routing Engine</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useContinuation</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Whether or not to use <a href="http://wiki.eclipse.org/Jetty/Feature/Continuations" class="external-link" rel="nofollow">Jetty continuations</a> for the Jetty Server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslContextParametersRef</tt><br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>null</tt><br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.&nbsp; This reference overrides any configured SSLContextParameters at the component level.&nbsp; See <a href="#BookComponentAppendix-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration Utility</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>traceEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Reference to a instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. It will be used to apply the custom headerFilterStrategy on the new create HttpJettyEndpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>urlRewrite</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b> Refers to a custom <tt>org.apache.camel.component.http.UrlRewrite</tt> which allows you to rewrite urls when you bridge/proxy endpoints. See more details at <a href="/confluence/display/CAMEL/UrlRewrite" title="UrlRewrite">UrlRewrite</a> and <a href="/confluence/display/CAMEL/How+to+use+Camel+as+a+HTTP+proxy+between+a+client+and+server" title="How to use Camel as a HTTP proxy between a client and server">How to use Camel as a HTTP proxy between a client and server</a>. </td>
</tr>
</tbody></table>
</div>
</div>

<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" class="external-link" rel="nofollow">http://myserver/myserver?orderid=123</a></tt>, the exchange will contain a header named <tt>orderid</tt> with the value 123. </p>

<p>Starting with 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 supports both consumer and producer endpoints. Another option for producing to other HTTP endpoints, is to use the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP Component</a></p>

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

<p>The <tt>JettyHttpComponent</tt> provides the following options:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>enableJmx</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If this option is true, Jetty JMX support will be enabled for this endpoint. See <a href="#BookComponentAppendix-JettyJMXsupport">Jetty JMX support</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslKeyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The password for the keystore when using SSL. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The password when using SSL. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslKeystore</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The path to the keystore. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>minThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To set a value for minimum number of threads in server thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To set a value for maximum number of threads in server thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>threadPool</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To use a custom thread pool for the server. This option should only be used in special circumstances. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslSocketConnectors</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3</b> <b>Consumer only:</b> A map which contains per port number specific SSL connectors. See section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>socketConnectors</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only:</b> A map which contains per port number specific HTTP connectors. Uses the same principle as <tt>sslSocketConnectors</tt> and therefore see section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslSocketConnectorProperties</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>. A map which contains general SSL connector properties. See section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>socketConnectorProperties</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>. A map which contains general HTTP connector properties. Uses the same principle as <tt>sslSocketConnectorProperties</tt> and therefore see section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Deprecated:</b> <b>Producer only</b>: To use a custom <tt>HttpClient</tt> with the jetty producer. This option is removed from Camel 2.11 onwards, instead you can set the option on the endpoint instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMinThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Producer only</b>: To set a value for minimum number of threads in <tt>HttpClient</tt> thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMaxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Producer only</b>: To set a value for maximum number of threads in <tt>HttpClient</tt> thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientThreadPool</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Deprecated:</b> <b>Producer only</b>: To use a custom thread pool for the client. This option is removed from Camel 2.11 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslContextParameters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> To configure a custom SSL/TLS configuration options at the component level.&nbsp; See&nbsp; <a href="#BookComponentAppendix-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration Utility</a> for more details. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>The following is a basic example of how to send an HTTP request to an existing HTTP endpoint.</p>

<p>in Java DSL</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">"jetty:<span class="code-comment">//http://www.google.com"</span>);</span>
</pre>
</div></div>

<p>or in Spring XML</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:start"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"jetty://http://www.google.com"</span>/&gt;</span>
<span class="code-tag">&lt;route&gt;</span>
</pre>
</div></div>

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

<p>In this sample we define a route that exposes a HTTP service at <tt><a href="http://localhost:8080/myapp/myservice" class="external-link" 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:{{port}}/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 />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>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">"${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" class="external-link" 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>&#45;&#45;<del>such as</del> <del><a href="/confluence/display/CAMEL/EL" title="EL">EL</a></del> <del>or</del> <del><a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a></del>&#45;-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 = exchange.getIn(HttpMessage.class).getRequest().getSession();
    ...
}
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SSLSupport%28HTTPS%29"></a>SSL Support (HTTPS)</h3>


<h5><a name="BookComponentAppendix-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h5>

<p>As of Camel 2.8, the Jetty component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp;  This utility greatly decreases the amount of component specific code  you need to write and is configurable at the endpoint and component  levels.&nbsp; The following examples demonstrate how to use the utility with  the Jetty component.</p>

<h6><a name="BookComponentAppendix-Programmaticconfigurationofthecomponent"></a>Programmatic configuration of the component</h6>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
KeyStoreParameters ksp = <span class="code-keyword">new</span> KeyStoreParameters();
ksp.setResource(<span class="code-quote">"/users/home/server/keystore.jks"</span>);
ksp.setPassword(<span class="code-quote">"keystorePassword"</span>);

KeyManagersParameters kmp = <span class="code-keyword">new</span> KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword(<span class="code-quote">"keyPassword"</span>);

SSLContextParameters scp = <span class="code-keyword">new</span> SSLContextParameters();
scp.setKeyManagers(kmp);

JettyComponent jettyComponent = getContext().getComponent(<span class="code-quote">"jetty"</span>, JettyComponent.class);
jettyComponent.setSslContextParameters(scp);
</pre>
</div></div>

<h6><a name="BookComponentAppendix-SpringDSLbasedconfigurationofendpoint"></a>Spring DSL based configuration of endpoint</h6>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
...
  &lt;camel:sslContextParameters
      id=<span class="code-quote">"sslContextParameters"</span>&gt;
    &lt;camel:keyManagers
        keyPassword=<span class="code-quote">"keyPassword"</span>&gt;
      &lt;camel:keyStore
          resource=<span class="code-quote">"/users/home/server/keystore.jks"</span>
          password=<span class="code-quote">"keystorePassword"</span>/&gt;
    <span class="code-tag">&lt;/camel:keyManagers&gt;</span>
  <span class="code-tag">&lt;/camel:sslContextParameters&gt;</span>...
...
  <span class="code-tag">&lt;to uri=<span class="code-quote">"jetty:https://127.0.0.1/mail/?sslContextParametersRef=sslContextParameters"</span>/&gt;</span>
...
</pre>
</div></div>

<h5><a name="BookComponentAppendix-ConfiguringJettyDirectly"></a>Configuring Jetty Directly</h5>

<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---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>

<p><b>until Camel 2.2</b></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>&#45;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>&#45;keypass</tt> option).</li>
</ul>


<p><b>from Camel 2.3 onwards</b></p>
<ul>
	<li><tt>org.eclipse.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>org.eclipse.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>&#45;storepass</tt> option).</li>
	<li><tt>org.eclipse.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>&#45;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: <a href="http://docs.codehaus.org/display/JETTY/How+to+configure+SSL" class="external-link" rel="nofollow">http://docs.codehaus.org/display/JETTY/How+to+configure+SSL</a></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 the various Camel versions:</p>

<p><b>Up to Camel 2.2</b></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">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sslSocketConnectors"</span>&gt;</span>
        <span class="code-tag">&lt;map&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"8043"</span>&gt;</span>
                <span class="code-tag">&lt;bean class=<span class="code-quote">"org.mortbay.jetty.security.SslSocketConnector"</span>&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keyPassword"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keystore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"needClientAuth"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"truststore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                <span class="code-tag">&lt;/bean&gt;</span>
            <span class="code-tag">&lt;/entry&gt;</span>
        <span class="code-tag">&lt;/map&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<p><b>Camel 2.3, 2.4</b></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">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sslSocketConnectors"</span>&gt;</span>
        <span class="code-tag">&lt;map&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"8043"</span>&gt;</span>
                <span class="code-tag">&lt;bean class=<span class="code-quote">"org.eclipse.jetty.server.ssl.SslSocketConnector"</span>&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keyPassword"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keystore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"needClientAuth"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"truststore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                <span class="code-tag">&lt;/bean&gt;</span>
            <span class="code-tag">&lt;/entry&gt;</span>
        <span class="code-tag">&lt;/map&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>&#42;From Camel 2.5 we switch to use SslSelectChannelConnector *</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">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sslSocketConnectors"</span>&gt;</span>
        <span class="code-tag">&lt;map&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"8043"</span>&gt;</span>
                <span class="code-tag">&lt;bean class=<span class="code-quote">"org.eclipse.jetty.server.ssl.SslSelectChannelConnector"</span>&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"password"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keyPassword"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"keystore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"needClientAuth"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                    <span class="code-tag">&lt;property name=<span class="code-quote">"truststore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
                <span class="code-tag">&lt;/bean&gt;</span>
            <span class="code-tag">&lt;/entry&gt;</span>
        <span class="code-tag">&lt;/map&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<p>The value you use as keys in the above map is the port you configure Jetty to listen on.</p>

<h4><a name="BookComponentAppendix-ConfiguringgeneralSSLproperties"></a>Configuring general SSL properties</h4>

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

<p>Instead of a per port number specific SSL socket connector (as shown above) you can now configure general properties which applies for all SSL socket connectors (which is not explicit configured as above with the port number as entry).</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">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sslSocketConnectorProperties"</span>&gt;</span>
        <span class="code-tag">&lt;map&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"password"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"keyPassword"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"keystore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"needClientAuth"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"truststore"</span>value=<span class="code-quote">"..."</span>/&gt;</span>
        <span class="code-tag">&lt;/map&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<h4><a name="BookComponentAppendix-HowtoobtainreferencetotheX509Certificate"></a>How to obtain reference to the X509Certificate</h4>

<p>Jetty stores a reference to the certificate in the HttpServletRequest which you can access from code as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
X509Certificate cert = (X509Certificate) req.getAttribute(<span class="code-quote">"javax.servlet.request.X509Certificate"</span>)
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ConfiguringgeneralHTTPproperties"></a>Configuring general HTTP properties</h4>

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

<p>Instead of a per port number specific HTTP socket connector (as shown above) you can now configure general properties which applies for all HTTP socket connectors (which is not explicit configured as above with the port number as entry).</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">"jetty"</span> class=<span class="code-quote">"org.apache.camel.component.jetty.JettyHttpComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"socketConnectorProperties"</span>&gt;</span>
        <span class="code-tag">&lt;map&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"acceptors"</span> value=<span class="code-quote">"4"</span>/&gt;</span>
            <span class="code-tag">&lt;entry key=<span class="code-quote">"maxIdleTime"</span> value=<span class="code-quote">"300000"</span>/&gt;</span>
        <span class="code-tag">&lt;/map&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<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>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 {
    <span class="code-keyword">public</span> MyHttpBinding(HttpEndpoint ep) {
        <span class="code-keyword">super</span>(ep);
    }
    @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>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><b>And from Camel 2.3 onwards</b> you can configure a list of Jetty handlers 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">"constraint"</span> class=<span class="code-quote">"org.eclipse.jetty.http.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.eclipse.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.eclipse.jetty.security.ConstraintSecurityHandler"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"authenticator"</span>&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.eclipse.jetty.security.authentication.BasicAuthenticator"</span>/&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"constraintMappings"</span>&gt;</span>
        <span class="code-tag">&lt;list&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"constraintMapping"</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>

<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-HowtoreturnacustomHTTP500replymessage"></a>How to return a custom HTTP 500 reply message</h3>

<p>You may want to return a custom reply message when something goes wrong, instead of the default reply message Camel <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> replies with.<br/>
You could use a custom <tt>HttpBinding</tt> to be in control of the message mapping, but often it may be easier to use Camel's <a href="/confluence/display/CAMEL/Exception+Clause" title="Exception Clause">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <tt>Dude something went wrong</tt> with HTTP error code 500:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"jetty:<span class="code-comment">//http://localhost:{{port}}/myserver"</span>)
</span>    <span class="code-comment">// use onException to <span class="code-keyword">catch</span> all exceptions and <span class="code-keyword">return</span> a custom reply message
</span>    .onException(Exception.class)
        .handled(<span class="code-keyword">true</span>)
        <span class="code-comment">// create a custom failure response
</span>        .transform(constant(<span class="code-quote">"Dude something went wrong"</span>))
        <span class="code-comment">// we must remember to set error code 500 as handled(<span class="code-keyword">true</span>)
</span>        <span class="code-comment">// otherwise would let Camel thing its a OK response (200)
</span>        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
    .end()
    <span class="code-comment">// now just force an exception immediately
</span>    .throwException(<span class="code-keyword">new</span> IllegalArgumentException(<span class="code-quote">"I cannot <span class="code-keyword">do</span> <span class="code-keyword">this</span>"</span>));
</pre>
</div></div>

<h3><a name="BookComponentAppendix-MultipartFormsupport"></a>Multi-part Form support</h3>

<p>From Camel 2.3.0, camel-jetty support to multipart form post out of box. The submitted form-data are mapped into the message header. Camel-jetty creates an attachment for each uploaded file. The file name is mapped to the name of the attachment. The content type is set as the content type of the attachment file name. You can find the example here.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Note: getName() functions as shown below in versions 2.5 and higher. In earlier versions you receive the temporary file name for the attachment instead</b></div><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// Set the jetty temp directory which store the file <span class="code-keyword">for</span> multi part form
</span><span class="code-comment">// camel-jetty will clean up the file after it handled the request.
</span><span class="code-comment">// The option works rightly from Camel 2.4.0
</span>getContext().getProperties().put(<span class="code-quote">"CamelJettyTempDir"</span>, <span class="code-quote">"target"</span>);

from(<span class="code-quote">"jetty:<span class="code-comment">//http://localhost:{{port}}/test"</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 {
        Message in = exchange.getIn();
        assertEquals(<span class="code-quote">"Get a wrong attachement size"</span>, 1, in.getAttachments().size());
        <span class="code-comment">// The file name is attachment id
</span>        DataHandler data = in.getAttachment(<span class="code-quote">"NOTICE.txt"</span>);

        assertNotNull(<span class="code-quote">"Should get the DataHandle NOTICE.txt"</span>, data);
        <span class="code-comment">// This <span class="code-keyword">assert</span> is wrong, but the correct content-type (application/octet-stream)
</span>        <span class="code-comment">// will not be returned until Jetty makes it available - currently the content-type
</span>        <span class="code-comment">// returned is just the <span class="code-keyword">default</span> <span class="code-keyword">for</span> FileDataHandler (<span class="code-keyword">for</span> the implentation being used)
</span>        <span class="code-comment">//assertEquals(<span class="code-quote">"Get a wrong content type"</span>, <span class="code-quote">"text/plain"</span>, data.getContentType());
</span>        assertEquals(<span class="code-quote">"Got the wrong name"</span>, <span class="code-quote">"NOTICE.txt"</span>, data.getName());

        assertTrue(<span class="code-quote">"We should get the data from the DataHandle"</span>, data.getDataSource()
            .getInputStream().available() &gt; 0);

        <span class="code-comment">// The other form date can be get from the message header
</span>        exchange.getOut().setBody(in.getHeader(<span class="code-quote">"comment"</span>));
    }

});
</pre>
</div></div>

<h3><a name="BookComponentAppendix-JettyJMXsupport"></a>Jetty JMX support</h3>

<p>From Camel 2.3.0, camel-jetty supports the enabling of Jetty's JMX capabilities at the component and endpoint level with the endpoint configuration taking priority.  Note that JMX must be enabled within the Camel context in order to enable JMX support in this component as the component provides Jetty with a reference to the MBeanServer registered with the Camel context.  Because the camel-jetty component caches and reuses Jetty resources for a given protocol/host/port pairing, this configuration option will only be evaluated during the creation of the first endpoint to use a protocol/host/port pairing.  For example, given two routes created from the following XML fragments, JMX support would remain enabled for all endpoints listening on "https://0.0.0.0".</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/myservice1/?enableJmx=true"</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;from uri=<span class="code-quote">"jetty:https://0.0.0.0/myapp/myservice2/?enableJmx=false"</span>/&gt;</span>
</pre>
</div></div>

<p>The camel-jetty component also provides for direct configuration of the Jetty MBeanContainer.  Jetty creates MBean names dynamically.  If you are running another instance of Jetty outside of the Camel context and sharing the same MBeanServer between the instances, you can provide both instances with a reference to the same MBeanContainer in order to avoid name collisions when registering Jetty MBeans.</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" class="external-link" rel="nofollow">Jing Library</a> to perform XML validation of the message body using either</p>

<ul>
	<li><a href="http://relaxng.org/" class="external-link" rel="nofollow">RelaxNG XML Syntax</a></li>
	<li><a href="http://relaxng.org/compact-tutorial-20030326.html" class="external-link" rel="nofollow">RelaxNG Compact Syntax</a></li>
</ul>


<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-jing&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>

<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/" class="external-link" rel="nofollow">RelaxNG XML Syntax</a> whereas <b>rnc</b> means use <a href="http://relaxng.org/compact-tutorial-20030326.html" class="external-link" rel="nofollow">RelaxNG Compact Syntax</a>. The following examples show possible URI values</p>

<div class='table-wrap'>
<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" class="external-link" 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" class="external-link" rel="nofollow">http://foo.com/bar.rnc</a></td>
</tr>
</tbody></table>
</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>
<div class='table-wrap'>
<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'> Specifies whether DOMSource/DOMResult or SaxSource/SaxResult should be used by the validator. </td>
</tr>
</tbody></table>
</div>


<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" class="external-link" 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" class="external-link" 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>

<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 ActiveMQ</b><br />If you are using <a href="http://activemq.apache.org/" class="external-link" rel="nofollow">Apache ActiveMQ</a>, you should prefer the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component as it has been optimized for <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a>. 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.</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>Transacted and caching</b><br />See section <em>Transactions and Cache Levels</em> below if you are using transactions with <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as it can impact performance.</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>Request/Reply over JMS</b><br />Make sure to read the section <em>Request-reply over JMS</em> further below on this page for important notes about request/reply, as Camel offers a number of options to configure for performance, and clustered environments.</td></tr></table></div>

<p>The JMS component allows messages to be sent to (or consumed from) a <a href="http://java.sun.com/products/jms/" class="external-link" 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>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-jms<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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">
jms:[queue:|topic:]destinationName[?options]
</pre>
</div></div>

<p>Where <tt>destinationName</tt> is a JMS queue or topic name. By default, the <tt>destinationName</tt> 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">
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 append query options to the URI using the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

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


<h4><a name="BookComponentAppendix-UsingActiveMQ"></a>Using ActiveMQ</h4>

<p>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 <a href="http://activemq.apache.org/jmstemplate-gotchas.html" class="external-link" rel="nofollow">poor performance</a>.</p>

<p>If you intend to use <a href="http://activemq.apache.org/" class="external-link" 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 optimized to use ActiveMQ efficiently</li>
	<li>Use the <tt>PoolingConnectionFactory</tt> in ActiveMQ.</li>
</ul>


<h4><a name="BookComponentAppendix-TransactionsandCacheLevels"></a>Transactions and Cache Levels</h4>
<p><a name="BookComponentAppendix-transactionCacheLevels"></a><br/>
If you are consuming messages and using transactions (<tt>transacted=true</tt>) then the default settings for cache level can impact performance.<br/>
If you are using XA transactions then you cannot cache as it can cause the XA transaction to not work properly.</p>

<p>If you are <b>not</b> using XA, then you should consider caching as it speeds up performance, such as setting <tt>cacheLevelName=CACHE_CONSUMER</tt>.</p>

<p>Through Camel 2.7.x, the default setting for <tt>cacheLevelName</tt> is <tt>CACHE_CONSUMER</tt>. You will need to explicitly set <tt>cacheLevelName=CACHE_NONE</tt>.<br/>
In Camel 2.8 onwards, the default setting for <tt>cacheLevelName</tt> is <tt>CACHE_AUTO</tt>. This default auto detects the mode and sets the cache level accordingly to:</p>
<ul class="alternate" type="square">
	<li>CACHE_CONSUMER = if transacted=false</li>
	<li>CACHE_NONE = if transacted=true</li>
</ul>


<p>So you can say the default setting is conservative. Consider using <tt>cacheLevelName=CACHE_CONSUMER</tt> if you are using non-XA transactions.</p>

<h4><a name="BookComponentAppendix-DurableSubscriptions"></a>Durable Subscriptions</h4>

<p>If you wish to use durable topic subscriptions, you need to specify both <b>clientId</b> and <b>durableSubscriptionName</b>. 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" class="external-link" 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" class="external-link" rel="nofollow">here</a>.</p>

<h4><a name="BookComponentAppendix-MessageHeaderMapping"></a>Message Header Mapping</h4>

<p>When using message headers, the JMS specification states that header names must be valid Java identifiers. So try to name your headers to be 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>A simple strategy for mapping header names is used by default. The strategy is to replace any dots and hyphens in the header name as shown below 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>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>


<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/current/camel-jms/apidocs/org/apache/camel/component/jms/JmsConfiguration.html" class="external-link" rel="nofollow">JMSConfiguration POJO</a>.</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><b>Mapping to Spring JMS</b><br />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.</td></tr></table></div>

<p>The options are 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"><div class='table-wrap'>
<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>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" class="external-link" 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. From <b>Camel 2.10.3</b> onwards this option can also be used when doing request/reply over JMS. See also the <tt>maxMessagesPerTask</tt> option to control dynamic scaling up/down of threads. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableReplyTo</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, a producer will behave like a InOnly exchange with the exception that <tt>JMSReplyTo</tt> header is sent out and not be suppressed like in the case of <tt>InOnly</tt>. Like <tt>InOnly</tt> the producer will not wait for a reply. A consumer with this flag will behave like <tt>InOnly</tt>. This feature can be used to bridge <tt>InOut</tt> requests to another queue so that a route on the other queue will send it´s response directly back to the original <tt>JMSReplyTo</tt>. </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. The <tt>clientId</tt> option <b>must</b> be configured as well. </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. From <b>Camel 2.10.3</b> onwards this option can also be used when doing request/reply over JMS. See also the <tt>maxMessagesPerTask</tt> option to control dynamic scaling up/down of threads. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerTask</tt> </td>
<td class='confluenceTd'> <tt>&#45;1</tt> </td>
<td class='confluenceTd'> The number of messages per task. &#45;1 is unlimited. If you use a range for concurrent consumers (eg min &lt; max), then this option can be used to set a value to eg <tt>100</tt> to control how fast the consumers will shrink when less work is required. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preserveMessageQos</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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>replyTo</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Provides an explicit ReplyTo destination, which overrides any incoming value of <tt>Message.getJMSReplyTo()</tt>. If you do <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS then <b>make sure</b> to read the section <em>Request-reply over JMS</em> further below for more details, and the <tt>replyToType</tt> option as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: <tt>Temporary</tt>, <tt>Shared</tt>, or <tt>Exclusive</tt>. By default Camel will use temporary queues. However if <tt>replyTo</tt> has been configured, then <tt>Shared</tt> is used by default. This option allows you to use exclusive queues instead of shared ones. See further below for more details, and especially the notes about the implications if running in a clustered environment, and the fact that <tt>Shared</tt> reply queues has lower performance than its alternatives <tt>Temporary</tt> and <tt>Exclusive</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestTimeout</tt> </td>
<td class='confluenceTd'> <tt>20000</tt> </td>
<td class='confluenceTd'> <b>Producer only:</b> The timeout for waiting for a reply when using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (in milliseconds). The default is 20 seconds. See below in section <em>About time to live</em> for more details. See also the <em>requestTimeoutCheckerInterval</em> option. </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 <b>Before Camel 2.3.0</b>, we don't support this option in CamelConsumerTemplate </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). See below in section <em>About time to live</em> for more details. </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 ensures that Camel is not started with failed connections. From <b>Camel 2.8</b> onwards also the JMS producers is tested as well. </td>
</tr>
</tbody></table>
</div>


<h4><a name="BookComponentAppendix-Alltheotheroptions"></a>All the other options</h4>

<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<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. You may consider enabling this option, if you start and stop <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> routes at runtime, while there are still messages enqued on the queue. If this option is <tt>false</tt>, and you stop the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option. </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>SESSION_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>&#45;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>allowNullBody</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3/2.10.1:</b> Whether to allow sending messages with no body. If this option is <tt>false</tt> and the message body is null, then an <tt>JMSException</tt> is thrown. </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>asyncConsumer</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Whether the <tt>JmsConsumer</tt> processes the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">asynchronously</a>. If enabled then the <tt>JmsConsumer</tt> may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">Asynchronous Routing Engine</a>). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is fully processed before the <tt>JmsConsumer</tt> will pickup the next message from the JMS queue. Note if <tt>transacted</tt> has been enabled, then <tt>asyncConsumer=true</tt> does not run asynchronously, as transactions must be executed synchronously (Camel 3.0 may support async transactions). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>asyncStartListener</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Whether to startup the <tt>JmsConsumer</tt> message listener asynchronously, when starting a route. For example if a <tt>JmsConsumer</tt> cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to <tt>true</tt>, you will let routes startup, while the <tt>JmsConsumer</tt> connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at <tt>WARN</tt> level, and the consumer will not be able to receive messages; You can then restart the route to retry. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>asyncStopListener</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Whether to stop the <tt>JmsConsumer</tt> message listener asynchronously, when stopping a route. </td>
</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>cacheLevelName</tt> </td>
<td class='confluenceTd'> CACHE_AUTO (Camel &gt;= 2.8.0)<br class="atl-forced-newline" />
 CACHE_CONSUMER (Camel &lt;= 2.7.1) </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>. The default setting for <b>Camel 2.8</b> and newer is <tt>CACHE_AUTO</tt>. For <b>Camel 2.7.1</b> and older the default is <tt>CACHE_CONSUMER</tt>. See the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" class="external-link" rel="nofollow">Spring documentation</a> and <a href="#BookComponentAppendix-transactionCacheLevels">Transactions Cache Levels</a> for more information. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevel</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Sets the cache level by ID for the underlying JMS resources. See <tt>cacheLevelName</tt> option for more details. </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>Custom</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>. When <tt>Custom</tt> is specified, the <tt>MessageListenerContainerFactory</tt> defined by the <tt>messageListenerContainerFactoryRef</tt> option will determine what <tt>org.springframework.jms.listener.AbstractMessageListenerContainer</tt> to use (<b>new option in Camel 2.10.2 onwards</b>). This option was temporary removed in Camel 2.7 and 2.8. But has been added back from Camel 2.9 onwards. </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>defaultTaskExecutorType</tt> </td>
<td class='confluenceTd'> (see description) </td>
<td class='confluenceTd'> <b>Camel 2.10.4:</b> Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: <tt>SimpleAsync</tt> (uses Spring's <a href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/core/task/SimpleAsyncTaskExecutor.html" class="external-link" rel="nofollow">SimpleAsyncTaskExecutor</a>) or <tt>ThreadPool</tt> (uses Spring's <a href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html" class="external-link" rel="nofollow">ThreadPoolTaskExecutor</a> with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of <tt>ThreadPool</tt> is recommended to reduce "thread trash" in elastic configurations with dynamically increasing and decreasing concurrent consumers. </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'> 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'> 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>disableTimeToLive</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the <tt>requestTimeout</tt> value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use <tt>disableTimeToLive=true</tt> to <b>not</b> set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section <em>About time to live</em> for more details. </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>errorHandler</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.2, 2.9:</b> Specifies a <tt>org.springframework.util.ErrorHandler</tt> to be invoked in case of any uncaught exceptions thrown while processing a <tt>Message</tt>. By default these exceptions will be logged at the WARN level, if no <tt>errorHandler</tt> has been configured. From <b>Camel 2.9.1:</b> onwards you can configure logging level and whether stack traces should be logged using the below two options. This makes it much easier to configure, than having to code a custom <tt>errorHandler</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>errorHandlerLoggingLevel</tt> </td>
<td class='confluenceTd'> <tt>WARN</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.1:</b> Allows to configure the default <tt>errorHandler</tt> logging level for logging uncaught exceptions. </td>
</tr>
<tr>
<td class='c