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 Thu, 26 Aug 2010 11:44:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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/~davsclaus">Claus Ibsen</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:SEDA} <br>{include:SERVLET} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{include:Smooks}</span> <span class="diff-added-words"style="background-color: #dfd;">{include:Sip}</span> <br></td></tr>
            <tr><td class="diff-unchanged" >{include:SMPP} <br>{include:SNMP} <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 the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS Component</a> and uses Spring's JMS support for declarative transactions, using Spring's <tt>JmsTemplate</tt> for sending and a <tt>MessageListenerContainer</tt> for consuming. All the options from the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> component also applies for this component.</p>

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

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

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

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

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

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

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

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

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

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

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

<p>The following <a href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-camel/src/test/java/org/apache/camel/component/ActiveMQRouteTest.java" 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://camel.apache.org/maven/camel-activemq/apidocs/org/apache/camel/component/activemq/ActiveMQComponent.html#activeMQComponent(java.lang.String)" 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>


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

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

<h3><a name="BookComponentAppendix-Usingconnectionpooling"></a>Using connection pooling</h3>
<p>When sending to an ActiveMQ broker using Camel it's recommended to use a pooled connection factory to handle efficient pooling of JMS connections, sessions and producers. This is documented in the page <a href="http://activemq.apache.org/spring-support.html" class="external-link" rel="nofollow">ActiveMQ Spring Support </a>.</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.3.2<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>And then setup the <b>activemq</b> Camel component as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">

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

	<span class="code-tag">&lt;bean id=<span class="code-quote">"pooledConnectionFactory"</span> class=<span class="code-quote">"org.apache.activemq.pool.PooledConnectionFactory"</span>&gt;</span>
		<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">"maximumActive"</span> value=<span class="code-quote">"500"</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>


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

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

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

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

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

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

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

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

<h3><a name="BookComponentAppendix-ConsumingAdvisoryMessages"></a>Consuming Advisory Messages</h3>

<p>ActiveMQ can generates <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 to send alarm in case you detect slow consumers<br/>
or to build statistics (nber of messages/produced per day, ...). The following Spring DSL example shows you how to read messages from Connection Topic :</p>

<p>The route start by reading the topic : ActiveMQ.Advisory.Connection. To watch another topic, simply change the name according to the name provided in ActiveMQ Advisory Messages<br/>
documentation. The parameter mapJmsMessage=false allows to convert the org.apache.activemq.command.ActiveMqMessage object from the jms queue.<br/>
Next, the body received is converted into a String for the example purpose 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 produce consume a message on a queue, you should see the following files under 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, 
</span>transactionId = <span class="code-keyword">null</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>, droppable = <span class="code-keyword">false</span>}</span>
</pre>
</div></div>

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

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


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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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


<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://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Exchange.html#getIn()" class="external-link" rel="nofollow">in message</a> :</p>
<ul>
	<li><a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Message.html#getHeader(java.lang.String)" 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://activemq.apache.org/camel/maven/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://activemq.apache.org/camel/maven/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://activemq.apache.org/camel/maven/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 AMQP component supports the <a href="http://www.amqp.org/" class="external-link" rel="nofollow">AMQP protocol</a> via the <a href="http://cwiki.apache.org/qpid/" 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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-ampq&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">
amqp:[queue:|topic:]destinationName[?options]
</pre>
</div></div>

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

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

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

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

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

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


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


<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='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.component.atom.feed</tt> </td>
<td class='confluenceTd'> Camel 1.x: When consuming the <tt>org.apache.abdera.model.Feed</tt> object is set to this header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAtomFeed</tt> </td>
<td class='confluenceTd'> Camel 2.0: When consuming the <tt>org.apache.abdera.model.Feed</tt> object is set to this header. </td>
</tr>
</tbody></table>
</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;

@Override
<span class="code-keyword">protected</span> CamelContext createCamelContext() <span class="code-keyword">throws</span> Exception {
    <span class="code-comment">// We initialize Camel
</span>
    SimpleRegistry registry = <span class="code-keyword">new</span> SimpleRegistry();
    <span class="code-comment">// First we register a blog service in our bean registry
</span>    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(createRouteBuilder());

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

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

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

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

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

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

    <span class="code-comment">// There should be two good blog entries from the feed
</span>    mock.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();
}

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

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

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

}

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

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

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

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

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

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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<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>cache</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enabled, Camel will cache the result of the first <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> look-up. Cache can be enabled if the bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> is defined as a singleton scope. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiParameterArray</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5:</b> How to treat the parameters which are passed from the message body; if it is <tt>true</tt>, the In message body should be an array of parameters. </td>
</tr>
</tbody></table>
</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, put the bean in JNDI.</p>

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

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

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

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

<p>A <b>bean:</b> endpoint cannot be defined as the input to the route; i.e. you cannot consume from it, you can only route from some inbound message <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> to the bean endpoint as output.  So consider using a <b>direct:</b> or <b>queue:</b> endpoint as the input.  </p>

<p>You can use the <tt>createProxy()</tt> methods on <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html" 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-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/stable/validator/reference/en/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-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(<span class="code-quote">"bean-validator:<span class="code-comment">//x?group=AllChecks&amp;messageInterpolator=#myMessageInterpolator&amp;traversableResolver=#myTraversableResolver&amp;constraintValidatorFactory=#myConstraintValidatorFactory"</span>)
</span>.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><b>Available as of Camel 2.0</b></p>

<p>The Browse component provides a simple <a href="/confluence/display/CAMEL/BrowsableEndpoint" title="BrowsableEndpoint">BrowsableEndpoint</a> which can be useful for testing, visualisation tools or debugging. The exchanges sent to the endpoint are all available to be browsed.</p>


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

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

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

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

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

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

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


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

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

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

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

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

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

<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=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>maxElementsInMemory</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> The numer of elements that may be stored in the defined cache </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>memoryStoreEvictionPolicy</tt> </td>
<td class='confluenceTd'> <tt>MemoryStoreEvictionPolicy.LFU</tt> </td>
<td class='confluenceTd'> The number of elements that may be stored in the defined cache. Options include
<ul class="alternate" type="square">
	<li>MemoryStoreEvictionPolicy.LFU - Least frequently used</li>
	<li>MemoryStoreEvictionPolicy.LRU - Least recently used</li>
	<li>MemoryStoreEvictionPolicy.FIFO - first in first out, the oldest element by creation time</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>overflowToDisk</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether cache may overflow to disk</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eternal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Sets whether elements are eternal. If eternal, timeouts are ignored and the<br/>
element is never expired. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToLiveSeconds</tt> </td>
<td class='confluenceTd'> <tt>300</tt> </td>
<td class='confluenceTd'> The maximum time between creation time and when an element expires.<br/>
Is only used if the element is not eternal </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToIdleSeconds</tt> </td>
<td class='confluenceTd'> <tt>300</tt> </td>
<td class='confluenceTd'> The maximum amount of time between accesses before an element expires </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>diskPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the disk store persists between restarts of the Virtual Machine.<br/>
The default value is false. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>diskExpiryThreadIntervalSeconds</tt> </td>
<td class='confluenceTd'> <tt>120</tt> </td>
<td class='confluenceTd'> The number of seconds between runs of the disk expiry thread. The default value<br/>
is 120 seconds </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheManagerFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If you want to use a custom factory which instantiates and creates the EHCache <tt>net.sf.ehcache.CacheManager</tt>. </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-MessageHeaders"></a>Message Headers</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. The 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/>
The <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-CacheProducer"></a>Cache Producer </h4>
<p>Sending data to the cache involves the ability to direct payloads in exchanges to be stored in a pre-existing or created-on-demand cache. The mechanics of doing this involve</p>
<ul class="alternate" type="square">
	<li>setting the Message Exchange Headers shown above.</li>
	<li>ensuring that the Message Exchange Body contains the message directed to the cache</li>
</ul>


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


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


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

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

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

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

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

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

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

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

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

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

<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: CHECK command tests existence of the entry in the cache but doesn't place message to 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>EHCache 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>

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


<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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-cometd&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">
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='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 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>240000</tt> </td>
<td class='confluenceTd'> The server side poll timeout in milliseconds. This is how long the server will hold a reconnect request before responding. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>interval</tt> </td>
<td class='confluenceTd'>      <tt>0</tt>          </td>
<td class='confluenceTd'> The client side poll timeout in milliseconds. How long a client will wait between reconnects</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxInterval</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> The max client side poll timeout in milliseconds. A client will be removed if a connection is not received in this time. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiFrameInterval</tt>   </td>
<td class='confluenceTd'> <tt>1500</tt> </td>
<td class='confluenceTd'> The client side poll timeout, if multiple connections are detected from the same browser. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jsonCommented</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  If <tt>true</tt>, the server will accept JSON wrapped in a comment and will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>logLevel</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <tt>0</tt>=none, <tt>1</tt>=info, <tt>2</tt>=debug. </td>
</tr>
</tbody></table>
</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 --&gt; cometd://localhost:8080?resourceBase=file./webapp<br/>
For classpath (when by example the web resources are packaged inside the webapp folder --&gt; cometd://localhost:8080?resourceBase=classpath:webapp</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-CryptocomponentforDigitalSignatures"></a>Crypto component for Digital Signatures</h2>
<p><b>Available as of Camel 2.3</b></p>

<p>Using 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 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 your messages. Messages are signed by encrypting a digest of the message with the private key. 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 digest 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 sources 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, sign and verify need to share a pair of keys, sign requiring a <tt>PrivateKey</tt> and verify a <tt>PublicKey</tt> (or a <tt>Certificate</tt> containing one). Using the JCE is 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 sign and verify 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 wil lbe 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>
</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 an 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 for housing pairs of PrivateKeys and Certificates keeping them encrypted and password protected. They can be retrieved from it 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 neither be feasible or desirable. It would be useful to be able to specify the 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>Better again 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>

<p>The <b>cxf:</b> component provides integration with <a href="http://incubator.apache.org/cxf/" 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-AvailableinRelease1.6.1andafter%28onlyinPOJOmode%29'>Available in Release 1.6.1 and after (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-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-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'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>wsdlURL</tt> </td>
<td class='confluenceTd'> The location of the WSDL. </td>
<td class='confluenceTd'> <a href="file://local/wsdl/hello.wsdl" class="external-link" rel="nofollow">file://local/wsdl/hello.wsdl</a> or <tt>wsdl/hello.wsdl</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> WSDL is obtained from endpoint address by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClass</tt> </td>
<td class='confluenceTd'> The name of the SEI (Service Endpoint Interface) class.  This class can have, but does not require, JSR181 annotations.&nbsp; <br class="atl-forced-newline" />
<b>Since 2.0,</b> this option is only required by POJO mode.&nbsp;&nbsp; If the wsdlURL option is provided, serviceClass is not required for PAYLOAD and MESSAGE mode.&nbsp; When wsdlURL option is used without serviceClass, the serviceName and portName (endpointName for Spring configuration) options <b>MUST</b> be provided. <br class="atl-forced-newline" />
<br class="atl-forced-newline" />
<b>Since 2.0</b>, it is possible to use <tt>&#35;</tt> notation to reference a <tt>serviceClass</tt> object instance from the registry.&nbsp; E.g. <tt>serviceClass=#beanName</tt>. <br class="atl-forced-newline" />
<br class="atl-forced-newline" />
<b>Please be advised that the referenced object cannot be a Proxy (Spring AOP Proxy is OK)</b> as it relies on <tt>Object.getClass().getName()</tt> method for non Spring AOP Proxy. <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>org.apache.camel.Hello</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceClassInstance</tt> </td>
<td class='confluenceTd'> <b>In 1.6 or later (will be deprecated in 2.0)</b>, <tt>serviceClassInstance</tt> works like <tt>serviceClass=#beanName</tt>, which looks up a <tt>serviceObject</tt> instance from the registry. </td>
<td class='confluenceTd'> <tt>serviceClassInstance=beanName</tt> </td>
<td class='confluenceTd'> No (use either <tt>serviceClass</tt> or <tt>serviceClassInstance</tt>) </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>serviceName</tt> </td>
<td class='confluenceTd'> The service name this service is implementing, it maps to the <tt>wsdl:service@name</tt>. </td>
<td class='confluenceTd'> {http:­//org.apache.camel}ServiceName </td>
<td class='confluenceTd'> Only if more than one <tt>serviceName</tt> in WSDL present, and it is required for camel-cxf consumer since camel 2.2 </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>portName</tt> </td>
<td class='confluenceTd'> The port name this service is implementing, it maps to the <tt>wsdl:port@name</tt>. </td>
<td class='confluenceTd'> {http:­//org.apache.camel}PortName </td>
<td class='confluenceTd'> Only if more than one <tt>portName</tt> under the <tt>serviceName</tt> is present, and it is required for camel-cxf consumer since camel 2.2 </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>dataFormat</tt> </td>
<td class='confluenceTd'> Which data type messages the CXF endpoint supports </td>
<td class='confluenceTd'> <tt>POJO</tt>, <tt>PAYLOAD</tt>, <tt>MESSAGE</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>POJO</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>relayHeaders</tt> </td>
<td class='confluenceTd'> Available since 1.6.1. Please see the <b>Description of</b> <tt><b>relayHeaders</b></tt> <b>option</b> section for this option in 2.0.  Should a CXF endpoint relay headers along the route. Currently only available when <tt>dataFormat=POJO</tt> </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wrapped</tt> </td>
<td class='confluenceTd'> Which kind of operation that CXF  endpoint producer will invoke </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wrappedStyle</tt> </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 </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>Null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> Will set the default bus when CXF endpoint create a bus by itself </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a bus object from the registry. The referenced object must be an instance of <tt>org.apache.cxf.Bus</tt>. <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>bus=#busName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Default bus created by CXF Bus Factory <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxfBinding</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a CXF binding object from the registry. The referenced object must be an instance of <tt>org.apache.camel.component.cxf.CxfBinding</tt>. </td>
<td class='confluenceTd'> <tt>cxfBinding=#bindingName</tt> <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.DefaultCxfBinding</tt> <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> New in 2.0, use <tt>&#35;</tt> notation to reference a header filter strategy object from the registry. The referenced object must be an instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>. </td>
<td class='confluenceTd'> <tt>headerFilterStrategy=#strategyName</tt> </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.CxfHeaderFilterStrategy</tt> <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>loggingFeatureEnabled</tt> </td>
<td class='confluenceTd'> New in 2.3, this option enables CXF Logging Feature which writes inbound and outbound SOAP messages to log. </td>
<td class='confluenceTd'> <tt>loggingFeatureEnabled</tt><tt>=true</tt> </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> false <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultOperationName</tt> </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. </td>
<td class='confluenceTd'> <tt>defaultOperationName</tt><tt>=greetMe</tt> </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> null </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultOperationNameSpace</tt> </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. </td>
<td class='confluenceTd'> <tt>defaultOperationNamespace</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>
<th class='confluenceTh'> No <br class="atl-forced-newline" /> </th>
<td class='confluenceTd'> null </td>
</tr>
</tbody></table>
</div>
</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>

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

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

<div class="confluenceTableSmall"><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.  JAX-WS handler is not supported. </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">"write"</span>/&gt;</span> 
   <span class="code-tag">&lt;/bean&gt;</span>
   		
&lt;cxf:cxfEndpoint id=<span class="code-quote">"serviceEndpoint"</span> address=<span class="code-quote">"http://localhost:9002/helloworld"</span>
	serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.HelloService"</span>&gt;
	<span class="code-tag">&lt;cxf:outInterceptors&gt;</span>
	    <span class="code-tag">&lt;ref bean=<span class="code-quote">"loggingOutInterceptor"</span>/&gt;</span>
	<span class="code-tag">&lt;/cxf:outInterceptors&gt;</span>
	<span class="code-tag">&lt;cxf:properties&gt;</span>
		<span class="code-tag">&lt;entry key=<span class="code-quote">"dataFormat"</span> value=<span class="code-quote">"MESSAGE"</span>/&gt;</span>
	<span class="code-tag">&lt;/cxf:properties&gt;</span>
<span class="code-tag">&lt;/cxf:cxfEndpoint&gt;</span>
</pre>
</div></div>

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

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

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

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

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

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

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

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

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

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

<p><a href="https://svn.apache.org/repos/asf/camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java" 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> as it does in 1.6.1.  If filtering of in-band headers is required, please use <tt>PAYLOAD</tt> mode or plug in a (pretty straightforward) CXF interceptor/JAXWS Handler to the CXF endpoint.</li>
	<li>The Message Header Relay mechanism has been merged into <tt>CxfHeaderFilterStrategy</tt>.  The <tt>relayHeaders</tt> option, its semantics, and default value remain the same, but it is a property of <tt>CxfHeaderFilterStrategy</tt>.<br/>
Here is an example of configuring it.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"dropAllMessageHeadersStrategy"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.CxfHeaderFilterStrategy"</span>&gt;</span>

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


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

<p>You can configure the CXF endpoint with the Spring configuration file shown below, and you can also embed the endpoint into the <tt>camelContext</tt> tags.  When you are invoking the service endpoint, you can set the <tt>operationName</tt> and <tt>operationNameSpace</tt> headers to explicitly state which operation you are calling.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-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://activemq.apache.org/camel/schema/cxfEndpoint"</span>
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                http://activemq.apache.org/camel/schema/cxfEndpoint http://activemq.apache.org/camel/schema/cxf/camel-cxf-1.6.0.xsd
                http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/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><b>NOTE</b> In Camel 2.x we change to use {{http:­//camel.apache.org/schema/cxf}} as the CXF endpoint's target namespace.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-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-2.0.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;
 ...
</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 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>

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

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

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

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

<p><tt>PAYLOAD</tt> means that you process the payload message from the SOAP envelope. You can use the <tt>Header.HEADER_LIST</tt> as the key to set or get the SOAP headers and use the <tt>List&lt;Element&gt;</tt> to set or get SOAP body elements.<br/>
Camel 1.x branch, you can get the <tt>List&lt;Element&gt;</tt> and header from the CXF Message, but if you want to set the response message, you need to create the CXF message using the CXF API.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            from(SIMPLE_ENDPOINT_URI + <span class="code-quote">"&amp;dataFormat=PAYLOAD"</span>).to(<span class="code-quote">"log:info"</span>).process(<span class="code-keyword">new</span> Processor() {
                <span class="code-keyword">public</span> void process(<span class="code-keyword">final</span> Exchange exchange) <span class="code-keyword">throws</span> Exception {
                    Message inMessage = exchange.getIn();
                    <span class="code-keyword">if</span> (inMessage <span class="code-keyword">instanceof</span> CxfMessage) {
                        CxfMessage cxfInMessage = (CxfMessage) inMessage;
                        CxfMessage cxfOutMessage = (CxfMessage) exchange.getOut();
                        List&lt;Element&gt; inElements = cxfInMessage.getMessage().get(List.class);
                        List&lt;Element&gt; outElements = <span class="code-keyword">new</span> ArrayList&lt;Element&gt;();
                        XmlConverter converter = <span class="code-keyword">new</span> XmlConverter();
                        <span class="code-object">String</span> documentString = ECHO_RESPONSE;
                        <span class="code-keyword">if</span> (inElements.get(0).getLocalName().equals(<span class="code-quote">"echoBoolean"</span>)) {
                            documentString = ECHO_BOOLEAN_RESPONSE;
                        }
                        org.apache.cxf.message.Exchange ex = ((CxfExchange)exchange).getExchange();
                        Endpoint ep = ex.get(Endpoint.class);
                        org.apache.cxf.message.Message response = ep.getBinding().createMessage();
                        Document outDocument = converter.toDOMDocument(documentString);
                        outElements.add(outDocument.getDocumentElement());
                        response.put(List.class, outElements);
                        cxfOutMessage.setMessage(response);                            
                    }
                }
            });
        }
    };
}
</pre>
</div></div>
<p><b>Change in 2.0</b>, There is no more <tt>CxfMessage</tt>, we just use the common Camel <tt>DefaultMessageImpl</tt> under layer. <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(SIMPLE_ENDPOINT_URI + <span class="code-quote">"&amp;dataFormat=PAYLOAD"</span>).to(<span class="code-quote">"log:info"</span>).process(<span class="code-keyword">new</span> Processor() {
                @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;Element&gt; inElements = requestPayload.getBody();
                    List&lt;Element&gt; outElements = <span class="code-keyword">new</span> ArrayList&lt;Element&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;
                    <span class="code-keyword">if</span> (inElements.get(0).getLocalName().equals(<span class="code-quote">"echoBoolean"</span>)) {
                        documentString = ECHO_BOOLEAN_RESPONSE;
                        assertEquals(<span class="code-quote">"Get a wrong request"</span>, ECHO_BOOLEAN_REQUEST, request);
                    } <span class="code-keyword">else</span> {
                        assertEquals(<span class="code-quote">"Get a wrong request"</span>, ECHO_REQUEST, request);
                    }
                    Document outDocument = converter.toDOMDocument(documentString);
                    outElements.add(outDocument.getDocumentElement());
                    <span class="code-comment">// set the payload header with <span class="code-keyword">null</span>
</span>                    CxfPayload&lt;SoapHeader&gt; responsePayload = <span class="code-keyword">new</span> CxfPayload&lt;SoapHeader&gt;(<span class="code-keyword">null</span>, outElements);
                    exchange.getOut().setBody(responsePayload); 
                }
            });
        }
    };
}
</pre>
</div></div>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<p><a href="https://svn.apache.org/repos/asf/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java" 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:9091/jaxws-mtom/hello"</span>
         wsdlURL=<span class="code-quote">"mtom.wsdl"</span>
         serviceName=<span class="code-quote">"ns:HelloService"</span>
         endpointName=<span class="code-quote">"ns:HelloPort"</span>
         <span class="code-keyword">xmlns:ns</span>=<span class="code-quote">"http://apache.org/camel/cxf/mtom_feature"</span>&gt;

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

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

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

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

    }
    
});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<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%282.0orlater%29"></a>CXF Bean Component (<b>2.0 or later</b>)</h2>

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

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

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

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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<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>
</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>
<p><b>Note: Currently, CXF Bean component has (only) been tested with Jetty HTTP component it can understand headers from Jetty HTTP component without requiring conversion.</b></p>

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

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

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

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

</pre>
</div></div>
<p>That's it.  Once the route is started, the web service is ready for business.  A HTTP client can make a request and receive response.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">url = <span class="code-keyword">new</span> URL(<span class="code-quote">"http:<span class="code-comment">//localhost:9000/customerservice/orders/223/products/323"</span>);
</span>in = url.openStream();
assertEquals(<span class="code-quote">"{\"</span>Product\<span class="code-quote">":{\"</span>description\<span class="code-quote">":\"</span>product 323\<span class="code-quote">",\"</span>id\<span class="code-quote">":323}}"</span>, CxfUtils.getStringFromInputStream(in));
</pre>
</div></div>

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

<p>The <b>cxfrs:</b> component provides integration with <a href="http://incubator.apache.org/cxf/" 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?resourceClass=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 </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>httpClientAPI</tt> </td>
<td class='confluenceTd'> <b>new to Camel 2.1</b> If it is true, the CxfRsProducer will use the HttpClientAPI to invoke the service <br/>
If it is false, the CxfRsProducer will use the ProxyClientAPI to invoke the service</td>
<td class='confluenceTd'> httpClientAPI=true  </td>
<td class='confluenceTd'>No </td>
<td class='confluenceTd'> <em>true</em> </td>
</tr>
</tbody></table>
</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 provides different configuration for them.<br/>
Please check out the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd" 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"><span class="code-comment">&lt;!-- Defined the real JAXRS back end service  --&gt;</span></span>
  &lt;jaxrs:server id=<span class="code-quote">"restService"</span>
		        address=<span class="code-quote">"http://localhost:9002/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">&lt;bean id=<span class="code-quote">"jsonProvider"</span> class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.JSONProvider"</span>/&gt;</span>

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

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


<h3><a name="BookComponentAppendix-HowtoconsumertheRESTrequestinCamel"></a>How to consumer 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</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">protected</span> RouteBuilder createRouteBuilder() <span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span> RouteBuilder() {
        <span class="code-keyword">public</span> void configure() {
            errorHandler(<span class="code-keyword">new</span> NoErrorHandlerBuilder());
            from(CXF_RS_ENDPOINT_URI).process(<span class="code-keyword">new</span> Processor() {

                <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                    Message inMessage = exchange.getIn();                        
                    <span class="code-comment">// Get the operation name from in message
</span>                    <span class="code-object">String</span> operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, <span class="code-object">String</span>.class);
                    <span class="code-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 = (<span class="code-object">String</span>) 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> {
                            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">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>


<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();
        <span class="code-comment">// set the operation name 
</span>        inMessage.setHeader(CxfConstants.OPERATION_NAME, <span class="code-quote">"getCustomer"</span>);
        <span class="code-comment">// using the proxy client API
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, <span class="code-object">Boolean</span>.FALSE);
        <span class="code-comment">// set the parameters , <span class="code-keyword">if</span> you just have one parameter 
</span>        <span class="code-comment">// camel will put <span class="code-keyword">this</span> object into an <span class="code-object">Object</span>[] itself
</span>        inMessage.setBody(<span class="code-quote">"123"</span>);
    }
    
});
     
<span class="code-comment">// get the response message 
</span>Customer response = (Customer) exchange.getOut().getBody();

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

<p><a href="http://cwiki.apache.org/CXF20DOC/jax-rs.html" 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();
        <span class="code-comment">// using the http central client API
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, <span class="code-object">Boolean</span>.TRUE);
        <span class="code-comment">// set the Http method
</span>        inMessage.setHeader(Exchange.HTTP_METHOD, <span class="code-quote">"GET"</span>);
        <span class="code-comment">// set the relative path
</span>        inMessage.setHeader(Exchange.HTTP_PATH, <span class="code-quote">"/customerservice/customers/123"</span>);                
        <span class="code-comment">// Specify the response class , cxfrs will use InputStream as the response object type 
</span>        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
        <span class="code-comment">// since we use the Get method, so we don't need to set the message body
</span>        inMessage.setBody(<span class="code-keyword">null</span>);                
    }
    
});
     
<span class="code-comment">// get the response message 
</span>Customer response = (Customer) exchange.getOut().getBody();

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

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

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

<p>The DataSet component (available since 1.3.0) provides a mechanism to easily perform load &amp; soak testing of your system. It works by allowing you to create <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/dataset/DataSet.html" 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/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='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>


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


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

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

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

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

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Asynchronous</b><br />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='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>


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

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


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


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

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

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

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

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

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

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

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

<p>or</p>

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

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

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

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

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

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Avoid reading files currently being written by another application</b><br />Beware the JDK File IO API is a bit limited in detecting whether another application is currently writing/copying a file. And the implementation can be different depending on OS platform as well. This could lead to that Camel thinks the file is not locked by another process and start consuming it. Therefore you have to do you own investigation what suites your environment. To help with this Camel provides different <tt>readLock</tt> options that you can use. See also the section <em>Consuming files from folders where others drop files directly</em>.</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 to where the files should be written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> 128kb </td>
<td class='confluenceTd'> Write buffer sized in bytes. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename. For consumers, it's used as a filename filter. For producers, it's used to evaluate the filename to write. If an expression is set, it take precedence over the <tt>CamelFileName</tt> header. (<b>Note:</b> The header itself can also be an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>). The expression options support both <tt>String</tt> and <tt>Expression</tt> types. If the expression is a <tt>String</tt> type, it is <b>always</b> evaluated using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. If the expression is an <tt>Expression</tt> type, the specified <tt>Expression</tt> type is used - this allows you, for instance, to use <a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a> expressions. For the consumer, you can use it to filter filenames, so you can for instance consume today's file using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> syntax: <tt>mydata-${date:now:yyyyMMdd}.txt</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flatten</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Flatten is used to flatten the file name path to strip any leading paths, so it's just the file name. This allows you to consume recursively into sub-directories, but when you eg write the files to another directory they will be written in a single directory. Setting this to <tt>true</tt> on the producer enforces that any file name recived in <tt>CamelFileName</tt> header will be stripped for any leading paths. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-Consumeronly"></a>Consumer only</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'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use fixed delay between pools, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>recursive</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If a directory, will look for files in all the sub-directories as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delete</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, the file will be deleted <b>after</b> it is processed </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>noop</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, the file is not moved or deleted in any way. This option is good for readonly data, or for <a href="/confluence/display/CAMEL/ETL" title="ETL">ETL</a> type requirements. If <tt>noop=true</tt>, Camel will set <tt>idempotent=true</tt> as well, to avoid consuming the same files over and over again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preMove</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving it <b>before</b> processing. For example to move in-progress files into the <tt>order</tt> directory set this value to <tt>order</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>move</tt> </td>
<td class='confluenceTd'> <tt>.camel</tt> </td>
<td class='confluenceTd'> Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving it <b>after</b> processing. To move files into a <tt>.done</tt> subdirectory just enter <tt>.done</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>moveFailed</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'>  Use <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> such as <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to dynamically set the filename when moving <b>failed files after</b> processing. To move files into a <tt>error</tt> subdirectory just enter <tt>error</tt>. <b>Note:</b> When moving the files to another location it can/will <b>handle</b> the error when you move it to another location so Camel cannot pick up the file again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>include</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Is used to include files, if filename matches the regex pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exclude</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Is used to exclude files, if filename matches the regex pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idempotent</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Option to use the <a href="/confluence/display/CAMEL/Idempotent+Consumer" title="Idempotent Consumer">Idempotent Consumer</a> EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If <tt>noop=true</tt> then idempotent will be enabled as well to avoid consuming the same files over and over again. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idempotentRepository</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable repository as a <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html" class="external-link" rel="nofollow">org.apache.camel.processor.idempotent.MessageIdRepository</a> class. Will by default use <tt>MemoryMessageIdRepository</tt> if none is specified and <tt>idempotent</tt> is <tt>true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inProgressRepository</tt> </td>
<td class='confluenceTd'> <tt>memory</tt> </td>
<td class='confluenceTd'> Pluggable in-progress repository as a <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html" class="external-link" rel="nofollow">org.apache.camel.processor.idempotent.MessageIdRepository</a> class. The in-progress repository is used to account the current in progress files being consumed. By default a memory based repository is used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable filter as a <tt>org.apache.camel.component.file.GenericFileFilter</tt> class. Will skip files if filter returns <tt>false</tt> in its <tt>accept()</tt> method. Camel also ships with an <b>ANT path matcher</b> filter in the <tt>camel-spring</tt> component. More details in section below. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sorter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable sorter as a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Comparator.html" 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/>
This option provides the build in strategies: 
<ul class="alternate" type="square">
	<li><tt>markerFile</tt> is the behaviour from Camel 1.x, where Camel will create a marker file and hold a lock on the marker file. This option is <b>not</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component.</li>
	<li><tt>changed</tt> is using file length/modification timestamp to detect whether the file is currently being copied or not. Will at least use 1 sec. to determine this, so this option cannot consume files as fast as the others, but can be more reliable as the JDK IO API cannot always determine whether a file is currently being used by another process. This option is <b>not</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component.</li>
	<li><tt>fileLock</tt> is for using <tt>java.nio.channels.FileLock</tt>. This option is <b>not</b> avail for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> component.</li>
	<li><tt>rename</tt> is for using a try to rename the file as a test if we can get exclusive read-lock.</li>
	<li><tt>none</tt> is for no read locks at all.</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readLockTimeout</tt> </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Optional timeout in milliseconds for the read-lock, if supported by the read-lock. If the read-lock could not be granted and the timeout triggered, then Camel will skip the file. At next poll Camel, will try the file again, and this time maybe the read-lock could be granted. Use a value of 0 or lower to indicate forever. In <b>Camel 2.0</b> the default value is 0. In <b>Camel 2.1</b> the default value is 10000. Currently <tt>fileLock</tt>, <tt>changed</tt> and <tt>rename</tt> support the timeout. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exclusiveReadLockStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Pluggable read-lock as a <tt>org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy</tt> implementation. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>processStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.apache.camel.component.file.GenericFileProcessStrategy</tt> allowing you to implement your own <tt>readLock</tt> option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special <em>ready</em> file exists. If this option is set then the <tt>readLock</tt> option does not apply. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> An integer that defines the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid having the server read thousands of files as it starts up. Set a value of 0 or negative to disabled it. </td>
</tr>
<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>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>
</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-Produceronly"></a>Producer only</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> and <b>Ignore</b>. <tt>Override</tt>, which is the default, replaces the existing file. <tt>Append</tt> adds content to the existing file. <tt>Fail</tt> throws a <tt>GenericFileOperationException</tt>, indicating that there is already an existing file. <tt>Ignore</tt> silently ignores the problem and <b>does not</b> override the existing file, but assumes everything is okay. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tempPrefix</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a> when uploading big files. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tempFileName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The <b>same</b> as <tt>tempPrefix</tt> option but offering a more fine grained control on the naming of the temporary filename as it uses the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. </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. </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.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Override is now default</b><br />In Camel 1.x the <tt>Append</tt> is the default for the file producer. We have changed this to <tt>Override</tt> in Camel 2.0 as this is also the default file operation using <tt>java.io.File</tt>.<br/>
And also the default for the FTP library we use in the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">camel-ftp</a> component.</td></tr></table></div></li>
</ul>


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

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

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

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

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

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

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

<h4><a name="BookComponentAppendix-FinegrainedcontroloverMoveandPreMoveoption"></a>Fine grained control over Move and PreMove option</h4>
<p>The <b>move</b> and <b>preMove</b> option is <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>-based, so we have the full power of the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> to do advanced configuration of the directory and name pattern.<br/>
Camel will, in fact, internally convert the directory name you enter into a <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> expression. So when we enter <tt>move=.done</tt> Camel will convert this into: <tt>${<a href="file:parent" class="external-link" rel="nofollow">file:parent</a>}/.done/${<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/${<a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a>}-${date:now:yyyyMMddHHmmssSSS}.${<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='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>
</tbody></table>
</div>


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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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

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

    assertMockEndpointsSatisfied();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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


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

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

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

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

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

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

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

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

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

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

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

<h4><a name="BookComponentAppendix-FilteringusingANTpathmatcher"></a>Filtering using ANT path matcher</h4>
<p>The ANT path matcher is shipped out-of-the-box in the <b>camel-spring</b> jar. So you need to depend on <b>camel-spring</b> if you are using Maven.<br/>
The reasons is that we leverage Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html" 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>*</tt> matches zero or more characters</li>
	<li><tt>**</tt> matches zero or more directories in a path</li>
</ul>


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

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

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

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

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

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

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

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

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>URI options can reference beans using the # syntax</b><br />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:size
</pre>
</div></div>

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

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

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

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


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

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

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

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

<p>The Flatpack component supports fixed width and delimited file parsing via the <a href="http://flatpack.sourceforge.net" 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-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;!-- 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">
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='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'> As of Camel 1.5, the component can either process each row one by one or the entire content at once. </td>
</tr>
</tbody></table>
</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='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>


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

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

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

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


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

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

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


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

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

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

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

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

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


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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<p>The data format has the following options:</p>
<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>
</tbody></table>
</div>


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

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

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

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

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

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

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


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

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

<p>The <b>freemarker:</b> component allows you to process a message using a <a href="http://freemarker.org/" 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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-freemarker&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">
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='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 its loaded. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Character encoding of the resource content. </td>
</tr>
</tbody></table>
</div>


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

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

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

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

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

<h3><a name="BookComponentAppendix-FreemarkerContext"></a>Freemarker Context</h3>
<p>Camel will provide exchange information in the Freemarker context (just a <tt>Map</tt>). The <tt>Exchange</tt> is transfered as:</p>
<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 Exchange itself. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headers</tt> </td>
<td class='confluenceTd'> The headers of the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>camelContext</tt> </td>
<td class='confluenceTd'> The Camel Context. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> The In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>body</tt> </td>
<td class='confluenceTd'> The In message body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>response</tt> </td>
<td class='confluenceTd'> The Out message (only for InOut message exchange pattern). </td>
</tr>
</tbody></table>
</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><b>Available as of Camel 2.1</b><br/>
Camel provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime.</p>

<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'> CamelFreemarkerResourceUri </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> A URI for the template resource to use instead of the endpoint configured. </td>
</tr>
<tr>
<td class='confluenceTd'> CamelFreemarkerTemplate </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> The template to use instead of the endpoint configured. </td>
</tr>
</tbody></table>
</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(<span class="code-quote">"CamelFreemarkerResourceUri"</span>).constant(<span class="code-quote">"path/to/my/template.ftl"</span>).
  to(<span class="code-quote">"freemarker:dummy"</span>);
</pre>
</div></div>

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

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

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

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

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

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

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

    mock.assertIsSatisfied();
}

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

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

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

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

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

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Libraries used</b><br />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>.</td></tr></table></div>

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

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

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

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

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

<h3><a name="BookComponentAppendix-URIOptions"></a>URI Options</h3>
<p>The options below are exclusive for the <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP2</a> component. </p>
<div class="confluenceTableSmall"><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>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the password to use to log in to the remote file system. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>binary</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies the file transfer mode, BINARY or ASCII. Default is ASCII (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Whether or not to disconnect from remote FTP server right after use. Can be used for both consumer and producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>localWorkDirectory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial, if you consume a very big remote file and thus can conserve memory. See below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>passiveMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS only</b>: Specifies whether to use passive mode connections. Default is active mode (<tt>false</tt>). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityProtocol</tt> </td>
<td class='confluenceTd'> <tt>TLS</tt> </td>
<td class='confluenceTd'> <b>FTPS only:</b> Sets the underlying security protocol. The following values are defined:<br 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>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>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>ftpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.1:</b> Allows you to use a custom <tt>org.apache.commons.net.ftp.FTPClient</tt> instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClientConfig</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTP and FTPS Only:</b> <b>Camel 2.1:</b> Allows you to use a custom <tt>org.apache.commons.net.ftp.FTPClientConfig</tt> instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.file</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store file, so that the FTPS client can look up for trusted certificates. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.type</tt> </td>
<td class='confluenceTd'> <tt>JKS</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.algorithm</tt> </td>
<td class='confluenceTd'> <tt>SunX509</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store algorithm. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.trustStore.password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the trust store password. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.file</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store file, so that the FTPS client can look up for the private certificate. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.type</tt> </td>
<td class='confluenceTd'> <tt>JKS</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.algorithm</tt> </td>
<td class='confluenceTd'> <tt>SunX509</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store algorithm. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the key store password. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ftpClient.keyStore.keyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>FTPS Only:</b> Sets the private key password. </td>
</tr>
</tbody></table>
</div>
</div>

<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 />By default, the FTPS component trust store accept all certificates. If you only want trust selective certificates, you have to configure the trust store with the <tt>ftpClient.trustStore.xxx</tt> options or by configuring a custom <tt>ftpClient</tt>.</td></tr></table></div>

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

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

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

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

<p>See the documentation of the <a href="http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClientConfig.html" 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/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>

<h4><a name="BookComponentAppendix-Examples"></a>Examples</h4>
<p><tt><a href="ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&amp;binary=true" 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>

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

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

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

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

<h4><a name="BookComponentAppendix-limitations"></a>limitations</h4>
<p>The option <b>readLock</b> can be used to force Camel <b>not</b> to consume files that is currently in the progress of being written. However, this option is turned off by default, as it requires that the user has write access. And there is only a few options supported for FTP.<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='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
</tbody></table>
</div>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<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-Samples"></a>Samples</h3>

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

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

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

<h4><a name="BookComponentAppendix-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 build our own filter that only accepts files starting with report in the filename.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyFileFilter <span class="code-keyword">implements</span> GenericFileFilter {

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

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

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


<h3><a name="BookComponentAppendix-FilteringusingANTpathmatcher"></a>Filtering using ANT path matcher</h3>
<p>The ANT path matcher is a filter that is shipped out-of-the-box in the <b>camel-spring</b> jar. So you need to depend on <b>camel-spring</b> if you are using Maven.<br/>
The reason is that we leverage Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html" 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>*</tt> matches zero or more characters</li>
	<li><tt>**</tt> matches zero or more directories in a path</li>
</ul>


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

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

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

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

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

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

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

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

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>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='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>


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

<p>Setting up a <tt>SpringCamelContext</tt> on Google App Engine differs between Camel 2.1 and Camel 2.2. The problem is that usage of the Camel-specific Spring configuration XML schema from the <tt><a href="http://camel.apache.org/schema/spring" 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.</p>

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


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

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

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

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


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

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

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

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

<p>With Camel 2.2, 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-HDFSComponent"></a>HDFS Component</h2>

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

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

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

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


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

<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>bufferSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> The buffer size used by HDFS  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replication</tt> </td>
<td class='confluenceTd'> <tt>3</tt> </td>
<td class='confluenceTd'> The HDFS replication factor  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>blockSize</tt> </td>
<td class='confluenceTd'> <tt>67108864</tt> </td>
<td class='confluenceTd'> The size of the HDFS blocks  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileType</tt> </td>
<td class='confluenceTd'> <tt>NORMAL_FILE</tt> </td>
<td class='confluenceTd'> It can be SEQUENCE_FILE,<br/>
                                   MAP_FILE, ARRAY_FILE, or<br/>
                                   BLOOMMAP_FILE, see Hadoop </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileSystemType</tt> </td>
<td class='confluenceTd'> <tt>HDFS</tt> </td>
<td class='confluenceTd'> It can be LOCAL for local filesystem  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyType</tt> </td>
<td class='confluenceTd'> <tt>NULL</tt> </td>
<td class='confluenceTd'> The type for the key in case of<br/>
                           sequence or map files. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>valueType</tt> </td>
<td class='confluenceTd'> <tt>TEXT</tt> </td>
<td class='confluenceTd'> The type for the key in case of<br/>
                             sequence or map files. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitStrategy</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> A string describing the strategy on <br/>
                        how to split the file based on different<br/>
                        criteria. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>openedSuffix</tt> </td>
<td class='confluenceTd'> <tt>opened</tt> </td>
<td class='confluenceTd'> When a file is opened for reading/<br/>
                                  writing the file is renamed with this<br/>
                                  suffix to avoid to read it during the<br/>
                                  writing phase. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readSuffix</tt> </td>
<td class='confluenceTd'> <tt>read</tt> </td>
<td class='confluenceTd'> Once the file has been read is<br/>
                              renamed with this suffix to avoid to<br/>
                              read it again.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> For the consumer, how much to wait (milliseconds)<br/>
                             before to start scanning the directory.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> The interval (milliseconds) between the directory<br/>
                      scans. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'> <tt>*</tt> </td>
<td class='confluenceTd'> The pattern used for scanning the<br/>
                        directory  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunkSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> When reading a normal file, this is split   <br/>
                             into chunks producing a message per<br/>
                             chunk   </td>
</tr>
</tbody></table>
</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 (0.20.1) opening a file in append mode is disabled since it's not enough reliable. So, for the moment, it's only possible to create new files. The Camel HDFS endpoint tries to solve this problem in this way:</p>
<ul>
	<li>If the split strategy option has been defined, the actual file name will become a directory name and a &lt;file name&gt;/seg0 will be initially created.</li>
	<li>Every time a splitting condition is met a new file is created with name &lt;original file name&gt;/segN where N is 1, 2, 3, etc.<br/>
The splitStrategy option  is defined as a string with the following syntax:<br/>
splitStrategy=&lt;ST&gt;:&lt;value&gt;,&lt;ST&gt;:&lt;value&gt;,*</li>
</ul>


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

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

<p>The <b>hibernate:</b> component allows you to work with databases using Hibernate as the object relational mapping technology to map POJOs to database tables. The <b>camel-hibernate</b> library is provided by the <a href="http://code.google.com/p/camel-extra/" 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 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 <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Type+Conversion&amp;linkCreation=true&amp;fromPageId=90525" class="createlink">Type Conversion</a> to ensure the body is of the correct type.</p>

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

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

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

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



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

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

<p>The <b>hl7</b> component is used for working with the HL7 MLLP protocol and the <a href="http://www.hl7.org/" class="external-link" rel="nofollow">HL7 model</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 easy-of-use as its integrated well with the <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</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 <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> component where we just use the <tt>HL7MLLPCodec</tt> as codec.</p>

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

<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. Is the HL7 default value of <tt>0x0b</tt> (11 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>endByte1</tt> </td>
<td class='confluenceTd'> <tt>0x1c</tt> </td>
<td class='confluenceTd'> The first end byte spanning the HL7 payload. Is the HL7 default value of <tt>0x1c</tt> (28 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>endByte2</tt> </td>
<td class='confluenceTd'> <tt>0x0d</tt> </td>
<td class='confluenceTd'> The 2nd end byte spanning the HL7 payload. Is the HL7 default value of <tt>0x0d</tt> (13 decimal). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>charset</tt> </td>
<td class='confluenceTd'> JVM Default </td>
<td class='confluenceTd'> The encoding (is a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" class="external-link" rel="nofollow">charset name</a>) to use for the codec. If not provided, Camel will use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()" 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> </td>
<td class='confluenceTd'> Will convert <tt>\n</tt> to <tt>\r</tt> (<tt>0x0d</tt>, 13 decimal) as HL7 usually uses <tt>\r</tt> as segment terminators. The HAPI library requires the use of <tt>\r</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>validate</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether HAPI Parser should validate or not. </td>
</tr>
</tbody></table>
</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>
</pre>
</div></div>
<p>Notice we configure it to use <a href="/confluence/display/CAMEL/MINA" title="MINA">camel-mina</a> with TCP on the <tt>localhost</tt> on port <tt>8888</tt>. We use <b>sync=true</b> to indicate that this listener is synchronous and therefore will return a HL7 response to the caller. Then we setup mina to use our HL7 codec with <b>codec=#hl7codec</b>. Notice that <tt>hl7codec</tt> is just a Spring bean ID, so we could have named it <tt>mygreatcodecforhl7</tt> or whatever. The codec is also set up in the Spring XML file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"hl7codec"</span> class=<span class="code-quote">"org.apache.camel.component.hl7.HL7MLLPCodec"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"charset"</span> value=<span class="code-quote">"iso-8859-1"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<p>And here we configure the charset encoding to use, and <tt>iso-8859-1</tt> is commonly used.</p>

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

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

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

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

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

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

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

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

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

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

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

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


<h4><a name="BookComponentAppendix-Camel2.0"></a>Camel 2.0</h4>
<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>


<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='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'> validate </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Whether the HAPI Parser should validate. </td>
</tr>
</tbody></table>
</div>


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

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

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

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

<p>Since HAPI 0.6, the library has been split into a <a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-base/1.0/" class="external-link" rel="nofollow">base library</a> and several structures libraries, one for each HL7v2 message version:</p>

<ul>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v21/1.0/" class="external-link" rel="nofollow">v2.1 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v22/1.0/" class="external-link" rel="nofollow">v2.2 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v23/1.0/" class="external-link" rel="nofollow">v2.3 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v231/1.0/" class="external-link" rel="nofollow">v2.3.1 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v24/1.0/" class="external-link" rel="nofollow">v2.4 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v24/1.0/" class="external-link" rel="nofollow">v2.5 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v251/1.0/" class="external-link" rel="nofollow">v2.5.1 structures library</a></li>
	<li><a href="http://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-structures-v26/1.0/" 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://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-base/1.0/" class="external-link" rel="nofollow">base library</a>. Applications are responsible for including structures 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-java">
&lt;dependency&gt;
    &lt;groupId&gt;ca.uhn.hapi&lt;/groupId&gt;
    &lt;artifactId&gt;hapi-structures-v24&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;ca.uhn.hapi&lt;/groupId&gt;
    &lt;artifactId&gt;hapi-structures-v25&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

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

<p>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://hl7api.sourceforge.net/m2/ca/uhn/hapi/hapi-osgi-base/" class="external-link" rel="nofollow">HAPI Maven repository</a> as well. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;ca.uhn.hapi&lt;/groupId&gt;
    &lt;artifactId&gt;hapi-osgi-base&lt;/artifactId&gt;
    &lt;version&gt;1.0.1&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Samples"></a>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">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>, in.toString());</span>
</pre>
</div></div>

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

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

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

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

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

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

<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">"mina:tcp:<span class="code-comment">//127.0.0.1:8888?sync=<span class="code-keyword">true</span>&amp;codec=#hl7codec"</span>, <span class="code-quote">"Hello World"</span>);
</span>
assertMockEndpointsSatisfied();

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

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

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

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

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

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

<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][?options]
</pre>
</div></div>
<p>Will by default use port 80 for HTTP and 443 for HTTPS.</p>

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

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>camel-http vs camel-jetty</b><br />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></td></tr></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'> <b>Camel 2.0:</b> Option to disable throwing the <tt>HttpOperationFailedException</tt> in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'><b>Camel 2.1:</b> If the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the <b>throwExcpetionOnFailure</b> to be false to let the HttpProducer send all the fault response back. <br/>
<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'><b>Camel 2.3:</b> 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'> <b>Camel 2.3:</b> 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'> <b>Camel 2.3:</b> 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'> <b>Camel 2.3:</b> To use a custom <tt>org.apache.http.conn.ClientConnectionManager</tt>. </td>
</tr>
</tbody></table>
</div>
</div>

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

<h4><a name="BookComponentAppendix-Camel2.2orolder%3ASettingAuthenticationandProxy"></a>Camel 2.2 or older: Setting Authentication and Proxy</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>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username for authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password for authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>domain</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Domain for NTML Authentication. This option must be used to force NTML authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyHost</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2:</b> The proxy host name </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyPort</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2:</b> The proxy port number </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyUsername</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2:</b> Username for proxy authentication </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>proxyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2:</b> Password for proxy authentication </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-Camel2.3ornewer%3AHttpConfigurationSettingAuthenticationandProxy"></a>Camel 2.3 or newer: HttpConfiguration - Setting Authentication and Proxy</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>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'> <b>Camel 2.3:</b> 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>

<h4><a name="BookComponentAppendix-Camel1.x"></a>Camel 1.x</h4>
<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>HttpProducer.HTTP_URI</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.0</b>: URI to call. Will override existing URI set directly on the endpoint. Is set on the In message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>HttpProducer.HTTP_RESPONSE_CODE</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The HTTP response code from the external server. Is 200 for OK. Is set on the Out message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>HttpProducer.QUERY</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> URI parameters. Will override existing URI parameters set directly on the endpoint. Is set on the In message. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="BookComponentAppendix-Camel2.x"></a>Camel 2.x</h4>
<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_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'> <b>Camel 2.3:</b> 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'> <b>Camel 2.3:</b> 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>


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

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

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

<p>Camel will handle according to the HTTP response code:</p>
<ul class="alternate" type="square">
	<li>Response code is in the range 100..299, Camel regards it as a success response.</li>
	<li>Response code is in the range 300..399, Camel regards it as a redirection response and will throw a <tt>HttpOperationFailedException</tt> with the information.</li>
	<li>Response code is 400&#43;, Camel regards it as an external server failure and will throw a <tt>HttpOperationFailedException</tt> with the information.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>throwExceptionOnFailure</b><br />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>In <b>Camel 1.5</b> the following algorithm is used to determine if either <tt>GET</tt> or <tt>POST</tt> HTTP method should be used:<br/>
1. Use method provided in header.<br/>
2. <tt>GET</tt> if query string is provided in header.<br/>
3. <tt>GET</tt> if endpoint is configured with a query string.<br/>
4. <tt>POST</tt> if there is data to send (body is not null).<br/>
5. <tt>GET</tt> otherwise.</p>

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

<p>You can get access to these two using the Camel type converter system using<br/>
<b>NOTE</b> from Camel 2.3.0 you can get the request and response not just from the processor after the camel-jetty or camel-cxf endpoint.</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-ConfiguringURItocall"></a>Configuring URI to call</h3>

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<h4><a name="BookComponentAppendix-Acceptingselfsignedcertificationsfromremoteserver"></a>Accepting self signed certifications from remote server</h4>
<p>See this <a href="http://www.nabble.com/Using-HTTPS-in-camel-http-when-remote-side-has-self-signed-cert-td25916878.html" 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>
<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>

<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-ibatis&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">
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='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'> <b>Camel 2.0:</b> Sets whether empty result set should be routed or not. By default, empty result sets are not routed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>statementType</tt> </td>
<td class='confluenceTd'> <tt>StatementType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Mandatory to specify for IbatisProducer to control which iBatis <tt>SqlMapClient</tt> method to invoke. The enum values are: <tt>QueryForObject</tt>, <tt>QueryForList</tt>, <tt>Insert</tt>, <tt>Update</tt>, <tt>Delete</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> An integer to define a maximum messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disabled it. </td>
</tr>
</tbody></table>
</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='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>org.apache.camel.ibatis.queryName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Camel 1.x: The <b>statementName</b> used (for example: insertAccount). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelIBatisStatementName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Camel 2.0: The <b>statementName</b> used (for example: insertAccount). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelIBatisResult</tt> </td>
<td class='confluenceTd'> <tt>Object</tt> </td>
<td class='confluenceTd'> Camel 1.6.2/2.0: The <b>response</b> returned from iBatis in any of the operations. For instance an <tt>INSERT</tt> could return the auto-generated key, or number of rows etc. </td>
</tr>
</tbody></table>
</div>


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

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

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

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

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

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

<h3><a name="BookComponentAppendix-UsingStatementTypeforbettercontrolofIBatis"></a>Using StatementType for better control of IBatis</h3>
<p><b>Available as of Camel 1.6.1/2.0</b><br/>
When routing to an iBatis endpoint you want more fine grained control so you can control whether the SQL statement to be executed is a <tt>SELEECT</tt>, <tt>UPDATE</tt>, <tt>DELETE</tt> or <tt>INSERT</tt> etc. This is now possible in Camel 1.6.1/2.0. So for instance if we want to route to an iBatis endpoint in which the IN body contains parameters to a <tt>SELECT</tt> statement we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:selectAccountById?statementType=QueryForObject"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>In the code above we can invoke the iBatis statement <tt>selectAccountById</tt> and the IN body should contain the account id we want to retrieve, such as an <tt>Integer</tt> type.</p>

<p>We can do the same for some of the other operations, such as <tt>QueryForList</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:selectAllAccounts?statementType=QueryForList"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>And the same for <tt>UPDATE</tt>, where we can send an <tt>Account</tt> object as IN body to iBatis:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"ibatis:updateAccount?statementType=Update"</span>)
    .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>


<h4><a name="BookComponentAppendix-Scheduledpollingexample"></a>Scheduled polling example</h4>
<p>Since this component does not support scheduled polling, you need to use another mechanism for triggering the scheduled polls, such as the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> or <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a> components.</p>

<p>In the sample below we poll the database, every 30 seconds using the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> component and send the data to the JMS queue:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"timer:<span class="code-comment">//pollTheDatabase?delay=30000"</span>).to(<span class="code-quote">"ibatis:selectAllAccounts?statementType=QueryForList"</span>).to(<span class="code-quote">"activemq:queue:allAccounts"</span>);</span>
</pre>
</div></div>

<p>And the iBatis SQL map file used:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag"><span class="code-comment">&lt;!-- Select with no parameters using the result map for Account class. --&gt;</span></span>
  <span class="code-tag">&lt;select id=<span class="code-quote">"selectAllAccounts"</span> resultMap=<span class="code-quote">"AccountResult"</span>&gt;</span>
    select * from ACCOUNT
  <span class="code-tag">&lt;/select&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingonConsume"></a>Using onConsume</h4>
<p>This component supports executing statements <b>after</b> data have been consumed and processed by Camel. This allows you to do post updates in the database. Notice all statements must be <tt>UPDATE</tt> statements. Camel supports executing multiple statements whose name should be separated by comma.</p>

<p>The route below illustrates we execute the <b>consumeAccount</b> statement data is processed. This allows us to change the status of the row in the database to processed, so we avoid consuming it twice or more.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"ibatis:selectUnprocessedAccounts?consumer.onConsume=consumeAccount"</span>).to(<span class="code-quote">"mock:results"</span>);
</pre>
</div></div>

<p>And the statements in the sqlmap file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;select id=<span class="code-quote">"selectUnprocessedAccounts"</span> resultMap=<span class="code-quote">"AccountResult"</span>&gt;</span>
     select * from ACCOUNT where PROCESSED = false
<span class="code-tag">&lt;/select&gt;</span>
</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;update id=<span class="code-quote">"consumeAccount"</span> parameterClass=<span class="code-quote">"Account"</span>&gt;</span>
     update ACCOUNT set PROCESSED = true where ACC_ID = #id#
<span class="code-tag">&lt;/update&gt;</span>
</pre>
</div></div>

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

<h2><a name="BookComponentAppendix-IRCComponent"></a>IRC Component</h2>

<p>The <b>irc</b> component implements an <a href="http://en.wikipedia.org/wiki/Internet_Relay_Chat" 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]
</pre>
</div></div>

<p>In Camel 2.0, you can also use the following format:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
irc:nick@host[:port]?channels=#channel1,#channel2,#channel3[?options]
</pre>
</div></div>

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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<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'> <b>Camel 2.0:</b> Comma separated list of IRC channels to join. </td>
<td class='confluenceTd'> <tt>channels=#channel1,#channel2</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nickname</tt> </td>
<td class='confluenceTd'> The nickname used in chat. </td>
<td class='confluenceTd'> <tt>irc:MyNick@irc.server.org#channel</tt> or <tt>irc:irc.server.org#channel?nickname=MyUser</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> The IRC server user name. </td>
<td class='confluenceTd'> <tt>irc:MyUser@irc.server.org#channel</tt> or <tt>irc:irc.server.org#channel?username=MyUser</tt> </td>
<td class='confluenceTd'> Same as nickname. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> The IRC server password. </td>
<td class='confluenceTd'> <tt>password=somepass</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>realname</tt> </td>
<td class='confluenceTd'> The IRC user's actual name. </td>
<td class='confluenceTd'> <tt>realname=MyName</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>colors</tt> </td>
<td class='confluenceTd'> Whether or not the server supports color codes. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onReply</tt> </td>
<td class='confluenceTd'> Whether or not to handle general responses to commands or informational messages. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onNick</tt> </td>
<td class='confluenceTd'> Handle nickname change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onQuit</tt> </td>
<td class='confluenceTd'> Handle user quit events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onJoin</tt> </td>
<td class='confluenceTd'> Handle user join events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onKick</tt> </td>
<td class='confluenceTd'> Handle kick events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onMode</tt> </td>
<td class='confluenceTd'> Handle mode change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onPart</tt> </td>
<td class='confluenceTd'> Handle user part events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onTopic</tt> </td>
<td class='confluenceTd'> Handle topic change events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onPrivmsg</tt> </td>
<td class='confluenceTd'> Handle message events. </td>
<td class='confluenceTd'> <tt>true, false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trustManager</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> The trust manager used to verify the SSL server's certificate. </td>
<td class='confluenceTd'> <tt>trustManager=#referenceToTrustManagerBean</tt> </td>
<td class='confluenceTd'> The default trust manager, which accepts <em>all</em> certificates, will be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keys</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Comma separated list of IRC channel keys. Important to be listed in same order as channels. When joining multiple channels with only some needing keys just insert an empty value for that channel. </td>
<td class='confluenceTd'> <tt>irc:MyNick@irc.server.org/#channel?keys=chankey</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>As of Camel 2.0, you can also connect to an SSL enabled IRC server, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ircs:host[:port]/#room?username=user&amp;password=pass
</pre>
</div></div>

<p>By default, the IRC transport uses <a href="http://moepii.sourceforge.net/irclib/javadoc/org/schwering/irc/lib/ssl/SSLDefaultTrustManager.html" 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-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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-javaspace&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">
javaspace:jini:<span class="code-comment">//host[?options]</span>
</pre>
</div></div>

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

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

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

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>//Sending route
from("direct:input").to("javaspace:jini://localhost?spaceName=mySpace");

//Receiving Route
from("javaspace:jini://localhost?spaceName=mySpace&amp;templateId=template&amp;verb=take&amp;concurrentConsumers=1")
</pre>
</div></div>

<p>In this case the payload can be any object that inherits from the Jini <tt>Entry</tt> type.</p>

<h4><a name="BookComponentAppendix-Sendingandreceivingserializableobjects"></a>Sending and receiving serializable objects</h4>
<p>Using the preceding routes, it is also possible to send and receive any serializable object. The JavaSpace component detects that the payload is not a Jini <tt>Entry</tt> and then it automatically wraps the payload with a Camel Jini <tt>Entry</tt>. In this way, a JavaSpace can be used as a generic transport mechanism.</p>

<h4><a name="BookComponentAppendix-UsingJavaSpaceasaremoteinvocationtransport"></a>Using JavaSpace as a remote invocation transport</h4>
<p>The JavaSpace component has been tailored to work in combination with the Camel bean component. It is therefore possible to call a remote POJO using JavaSpace as the transport:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>from("direct:input").to("javaspace:jini://localhost?spaceName=mySpace"); //Client side

from("javaspace:jini://localhost?concurrentConsumers=10&amp;spaceName=mySpace").to("pojo:pojo"); //Server side
</pre>
</div></div>

<p>In the code there are two test cases showing how to use a POJO to realize the master/worker pattern. The idea is to use the POJO to provide the business logic and rely on Camel for sending/receiving requests/replies with the proper correlation.  </p>

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

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


<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>From <b>Camel 1.5</b> onwards, the stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt> option.<br/>
In <b>Camel 2.0</b> we store big input streams (by default, over 64K) in a <tt>temp</tt> file using <tt>CachedOutputStream</tt>. When you close the input stream, the temp file will be deleted.</p>

<h3><a name="BookComponentAppendix-CreatingaJBIServiceUnit"></a>Creating a JBI Service Unit</h3>

<p>If you have some Camel routes that you want to deploy inside JBI as a Service Unit, you can use the <a href="/confluence/display/CAMEL/JBI+Service+Unit+Archetype" title="JBI Service Unit Archetype">JBI Service Unit Archetype</a> to create a new Maven project for the Service Unit.</p>

<p>If you have an existing Maven project that you need to convert into a JBI Service Unit, you may want to consult <a href="http://servicemix.apache.org/maven-jbi-plugin.html" 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;1.0.0&lt;/camel-version&gt;
    &lt;servicemix-version&gt;3.3&lt;/servicemix-version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.servicemix&lt;/groupId&gt;
      &lt;artifactId&gt;servicemix-camel&lt;/artifactId&gt;
      &lt;version&gt;${servicemix-version}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.servicemix&lt;/groupId&gt;
      &lt;artifactId&gt;servicemix-core&lt;/artifactId&gt;
      &lt;version&gt;${servicemix-version}&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;defaultGoal&gt;install&lt;/defaultGoal&gt;

    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.5&lt;/source&gt;
          &lt;target&gt;1.5&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

      &lt;!-- creates the JBI deployment unit --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.servicemix.tooling&lt;/groupId&gt;
        &lt;artifactId&gt;jbi-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;${servicemix-version}&lt;/version&gt;
        &lt;extensions&gt;<span class="code-keyword">true</span>&lt;/extensions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre>
</div></div>


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

<ul>
	<li><a href="http://servicemix.apache.org/servicemix-camel.html" 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 nodes to a JCR (JSR-170) compliant content repository (for example, <a href="http://jackrabbit.apache.org/" class="external-link" rel="nofollow">Apache Jackrabbit </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-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>

<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>The <tt>repository</tt> element of the URI is used to look up the JCR <tt>Repository</tt> object in the Camel context registry.</p>

<p>If a message is sent to a JCR producer endpoint:</p>
<ul>
	<li>A new node is created in the content repository,</li>
	<li>All the message properties of the IN message are transformed to JCR <tt>Value</tt> instances and added to the new node,</li>
	<li>The node's UUID is returned in the OUT message.</li>
</ul>


<h3><a name="BookComponentAppendix-Messageproperties"></a>Message properties</h3>
<p>All message properties are converted to node properties, except for the <tt>CamelJcrNodeName</tt> property (you can refer to <tt>JcrConstants.NODE_NAME</tt> in your code), which is used to determine the node name.</p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>The snippet below creates a node named <tt>node</tt> under the <tt>/home/test</tt> node in the content repository.  One additional attribute is added to the node as well: <tt>my.contents.property</tt> which will contain the body of the message being sent.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:a"</span>).setProperty(JcrConstants.JCR_NODE_NAME, constant(<span class="code-quote">"node"</span>))
    .setProperty(<span class="code-quote">"my.contents.property"</span>, body()).to(<span class="code-quote">"jcr:<span class="code-comment">//user:pass@repository/home/test"</span>);</span>
</pre>
</div></div>

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

<h2><a name="BookComponentAppendix-JDBCComponent"></a>JDBC Component</h2>

<p>The <b>jdbc</b> component enables you to access databases through JDBC, where SQL queries and operations are sent in the message body. This component uses the standard JDBC API, unlike the <a href="/confluence/display/CAMEL/SQL+Component" title="SQL Component">SQL Component</a> component, which uses spring-jdbc.</p>

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

<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> / <tt>2000</tt> </td>
<td class='confluenceTd'> The default maximum number of rows that can be read by a polling query. The default value is 2000 for Camel 1.5.0 or older. In newer releases the default value is 0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>statement.&lt;xxx&gt;</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Sets additional options on the <tt>java.sql.Statement</tt> that is used behind the scenes to execute the queries. For instance, <tt>statement.maxRows=10</tt>. For detailed documentation, see the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html" 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 1.6.3/2.2:</b> Sets whether to use JDBC 4/3 column label/name semantics. You can use this option to turn it <tt>false</tt> in case you have issues with your JDBC driver to select data. This only applies when using <tt>SQL SELECT</tt> using aliases (e.g. <tt>SQL SELECT id as identifier, name as given_name from persons</tt>). </td>
</tr>
</tbody></table>
</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>
</tbody></table>
</div>


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

<p>In the following example, we fetch the rows from the customer table.</p>

<p>First we register our datasource in the Camel registry as <tt>testdb</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">JndiRegistry reg = <span class="code-keyword">super</span>.createRegistry();
reg.bind(<span class="code-quote">"testdb"</span>, ds);
<span class="code-keyword">return</span> reg;
</pre>
</div></div>

<p>Then we configure a route that routes to the JDBC component, so the SQL will be executed. Note how we refer to the <tt>testdb</tt> datasource that was bound in the previous step:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// lets add simple route
</span><span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
    from(<span class="code-quote">"direct:hello"</span>).to(<span class="code-quote">"jdbc:testdb?readSize=100"</span>);
}
</pre>
</div></div>

<p>Or you can create a <tt>DataSource</tt> in Spring like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;route&gt;
     &lt;from uri=<span class="code-quote">"timer:<span class="code-comment">//kickoff?period=10000"</span>/&gt;
</span>     &lt;setBody&gt;
       &lt;constant&gt;select * from customer&lt;/constant&gt;
     &lt;/setBody&gt;
     &lt;to uri=<span class="code-quote">"jdbc:testdb"</span>/&gt;
     &lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;
&lt;!-- Just add a demo to show how to bind a date source <span class="code-keyword">for</span> camel in Spring--&gt;
&lt;bean id=<span class="code-quote">"testdb"</span> class=<span class="code-quote">"org.springframework.jdbc.datasource.DriverManagerDataSource"</span>&gt;
	&lt;property name=<span class="code-quote">"driverClassName"</span> value=<span class="code-quote">"org.hsqldb.jdbcDriver"</span>/&gt;
	&lt;property name=<span class="code-quote">"url"</span> value=<span class="code-quote">"jdbc:hsqldb:mem:camel_jdbc"</span> /&gt;
	&lt;property name=<span class="code-quote">"username"</span> value=<span class="code-quote">"sa"</span> /&gt;
  &lt;property name=<span class="code-quote">"password"</span> value="" /&gt;
&lt;/bean&gt;	

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

<p>We create an endpoint, add the SQL query to the body of the IN message, and then send the exchange. The result of the query is returned in the OUT body:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// first we create our exchange using the endpoint
</span>Endpoint endpoint = context.getEndpoint(<span class="code-quote">"direct:hello"</span>);
Exchange exchange = endpoint.createExchange();
<span class="code-comment">// then we set the SQL on the in body
</span>exchange.getIn().setBody(<span class="code-quote">"select * from customer order by ID"</span>);

<span class="code-comment">// now we send the exchange to the endpoint, and receives the response from Camel
</span>Exchange out = template.send(endpoint, exchange);

<span class="code-comment">// assertions of the response
</span>assertNotNull(out);
assertNotNull(out.getOut());
ArrayList&lt;HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;&gt; data = out.getOut().getBody(ArrayList.class);
assertNotNull(<span class="code-quote">"out body could not be converted to an ArrayList - was: "</span>
    + out.getOut().getBody(), data);
assertEquals(2, data.size());
HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; row = data.get(0);
assertEquals(<span class="code-quote">"cust1"</span>, row.get(<span class="code-quote">"ID"</span>));
assertEquals(<span class="code-quote">"jstrachan"</span>, row.get(<span class="code-quote">"NAME"</span>));
row = data.get(1);
assertEquals(<span class="code-quote">"cust2"</span>, row.get(<span class="code-quote">"ID"</span>));
assertEquals(<span class="code-quote">"nsandhu"</span>, row.get(<span class="code-quote">"NAME"</span>));
</pre>
</div></div>

<p>If you want to work on the rows one by one instead of the entire ResultSet at once you need to use the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> EIP such as:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:hello"</span>)
        <span class="code-comment">// here we split the data from the testdb into <span class="code-keyword">new</span> messages one by one
</span>        <span class="code-comment">// so the mock endpoint will receive a message per row in the table
</span>    .to(<span class="code-quote">"jdbc:testdb"</span>).split(body()).to(<span class="code-quote">"mock:result"</span>);

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

<h3><a name="BookComponentAppendix-SamplePollingthedatabaseeveryminute"></a>Sample - Polling the database every minute</h3>
<p>If we want to poll a database using the JDBC component, we need to combine it with a polling scheduler such as the <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a> or <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a> etc. In the following example, we retrieve data from the database every 60 seconds:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"timer:<span class="code-comment">//foo?period=60000"</span>).setBody(constant(<span class="code-quote">"select * from customer"</span>)).to(<span class="code-quote">"jdbc:testdb"</span>).to(<span class="code-quote">"activemq:queue:customers"</span>);</span>
</pre>
</div></div>


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

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

<h2><a name="BookComponentAppendix-JettyComponent"></a>Jetty Component</h2>

<p>The <b>jetty</b> component provides HTTP-based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming HTTP requests. That is, the Jetty component behaves as a simple Web server.</p>

<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>Upgrading from Jetty 6 to 7</b><br />You can read more about upgrading Jetty <a href="http://wiki.eclipse.org/Jetty/Howto/Upgrade_from_Jetty_6_to_Jetty_7" class="external-link" rel="nofollow">here</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">
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'> <b>Camel 1.6.0/2.0:</b> 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>httpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.0/2.0:</b> Reference to an <tt>org.apache.camel.component.http.HttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. <tt>HttpBinding</tt> can be used to customize how a response should be written. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>matchOnUriPrefix</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether or not the <tt>CamelServlet</tt> should try to find a target consumer by matching the URI prefix if no exact match is found. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>handlers</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Specifies a comma-delimited set of <tt>org.mortbay.jetty.Handler</tt> instances in your <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> (such as your Spring <tt>ApplicationContext</tt>). These handlers are added to the Jetty servlet context (for example, to add security). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunked</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnFailure</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Option to disable throwing the <tt>HttpOperationFailedException</tt> in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'><b>Camel 2.1:</b> If the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the <b>throwExcpetionOnFailure</b> to be false to let the HttpProducer send all the fault response back. <br/>
<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>enableMultipartFilter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Canel 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>
</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. This feature was introduced in Camel 1.5.</p>

<p>From Camel 1.6.3 and Camel 2.2.0, you can get the request.parameter from the message header not only from Get Method, but also other HTTP method.</p>

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

<p>The Jetty component only supports consumer endpoints. Therefore a Jetty endpoint URI should be used only as the <b>input</b> for a Camel route (in a <tt>from()</tt> DSL call). To issue HTTP requests against other HTTP endpoints, use the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP Component</a></p>

<h3><a name="BookComponentAppendix-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. </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. </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. </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>Producer only</b>: To use a custom <tt>HttpClient</tt> with the jetty producer. </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. </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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientThreadPool</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Producer only</b>: To use a custom thread pool for the client. </td>
</tr>
</tbody></table>
</div>
</div>


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

<p>In this sample we define a route that exposes a HTTP service at <tt><a href="http://localhost:8080/myapp/myservice" 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:9080/myapp/myservice"</span>).process(<span class="code-keyword">new</span> MyBookService());</span>
</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Usage of localhost</b><br />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">"in.header.one"</span>).to(<span class="code-quote">"mock:one"</span>)
    .otherwise()
    .to(<span class="code-quote">"mock:other"</span>);
</pre>
</div></div>
<p>So if a client sends the HTTP request, <tt><a href="http://serverUri?one=hello" 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>--<del>such as <a href="/confluence/display/CAMEL/EL" title="EL">EL</a> or <a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a></del>--we could also test for the parameter value and do routing based on the header value as well.</p>

<h3><a name="BookComponentAppendix-SessionSupport"></a>Session Support</h3>

<p>The session support option, <tt>sessionSupport</tt>, can be used to enable a <tt>HttpSession</tt> object and access the session object while processing the exchange. For example, the following route enables sessions:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"</span>/&gt;</span>
    <span class="code-tag">&lt;processRef ref=<span class="code-quote">"myCode"</span>/&gt;</span>
<span class="code-tag">&lt;route&gt;</span>
</pre>
</div></div>

<p>The <tt>myCode</tt> <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> can be instantiated by a Spring <tt>bean</tt> element:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"myCode"</span>class=<span class="code-quote">"com.mycompany.MyCodeProcessor"</span>/&gt;</span>
</pre>
</div></div>

<p>Where the processor implementation can access the <tt>HttpSession</tt> as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
    HttpSession session = ((HttpExchange)exchange).getRequest().getSession();
    ...
}
</pre>
</div></div>

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

<p>Jetty provides SSL support out of the box. To enable Jetty to run in SSL mode, simply format the URI with the <tt>https://</tt> prefix---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 Camel 1.6.x and 2.x:</p>

<p><b>Camel 1.x</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-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">"sslSocketConnector"</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">"wantClientAuth"</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;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p><b>until 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>from Camel 2.3 onwards</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>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;properties&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;/properties&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-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;properties&gt;</span>
            <span class="code-tag">&lt;property name=<span class="code-quote">"acceptors"</span> value=<span class="code-quote">"4"</span>/&gt;</span>
            <span class="code-tag">&lt;property name=<span class="code-quote">"maxIdleTime"</span> value=<span class="code-quote">"300000"</span>/&gt;</span>
        <span class="code-tag">&lt;/properties&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><b>Available as of Camel 1.5.1/2.0</b></p>

<p>By default, Camel uses the <tt>org.apache.camel.component.http.DefaultHttpBinding</tt> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <tt>HttpBinding</tt> class or by extending <tt>DefaultHttpBinding</tt> and overriding the appropriate methods.</p>

<p>The following example shows how to customize the <tt>DefaultHttpBinding</tt> in order to change how exceptions are returned:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MyHttpBinding <span class="code-keyword">extends</span> DefaultHttpBinding {

    @Override
    <span class="code-keyword">public</span> void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) <span class="code-keyword">throws</span> IOException {
        <span class="code-comment">// we override the doWriteExceptionResponse as we only want to alter the binding how exceptions is
</span>        <span class="code-comment">// written back to the client. 
</span>
        <span class="code-comment">// we just <span class="code-keyword">return</span> HTTP 200 so the client thinks its okay
</span>        response.setStatus(200);
        <span class="code-comment">// and we <span class="code-keyword">return</span> <span class="code-keyword">this</span> fixed text
</span>        response.getWriter().write(<span class="code-quote">"Something went wrong but we dont care"</span>);
    }
}
</pre>
</div></div>

<p>We can then create an instance of our binding and register it in the Spring registry as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"mybinding"</span>class=<span class="code-quote">"com.mycompany.MyHttpBinding"</span>/&gt;</span>
</pre>
</div></div>

<p>And then we can reference this binding when we define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span><span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://0.0.0.0:8080/myapp/myservice?httpBindingRef=mybinding"</span>/&gt;</span><span class="code-tag">&lt;to uri=<span class="code-quote">"bean:doSomething"</span>/&gt;</span><span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Jettyhandlersandsecurityconfiguration"></a>Jetty handlers and security configuration</h3>

<p><b>Available as of Camel 1.6.1/2.0:</b> You can configure a list of Jetty handlers on the endpoint, which can be useful for enabling advanced Jetty security features. These handlers are configured in Spring XML as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;-- Jetty Security handling --&gt;</span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"userRealm"</span> class=<span class="code-quote">"org.mortbay.jetty.plus.jaas.JAASUserRealm"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"name"</span> value=<span class="code-quote">"tracker-users"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"loginModuleName"</span> value=<span class="code-quote">"ldaploginmodule"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"constraint"</span> class=<span class="code-quote">"org.mortbay.jetty.security.Constraint"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"name"</span> value=<span class="code-quote">"BASIC"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"roles"</span> value=<span class="code-quote">"tracker-users"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"authenticate"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"constraintMapping"</span> class=<span class="code-quote">"org.mortbay.jetty.security.ConstraintMapping"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"constraint"</span> ref=<span class="code-quote">"constraint"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"pathSpec"</span> value=<span class="code-quote">"/*"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"securityHandler"</span> class=<span class="code-quote">"org.mortbay.jetty.security.SecurityHandler"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"userRealm"</span> ref=<span class="code-quote">"userRealm"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"constraintMappings"</span> ref=<span class="code-quote">"constraintMapping"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p><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:8234/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="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:9080/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);
        assertEquals(<span class="code-quote">"Get a wrong content type"</span>, <span class="code-quote">"text/plain"</span>, data.getContentType());
        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'> <b>Camel 2.0:</b> 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 particularly 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>

<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:[temp:][queue:|topic:]destinationName[?options]
</pre>
</div></div>

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

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

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

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

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

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

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

<h4><a name="BookComponentAppendix-UsingTemporaryDestinations"></a>Using Temporary Destinations</h4>

<p>As of Camel 1.4.0, you can access temporary queues using the following URL format:</p>

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

<p>Or temporary topics using the following URL format:</p>

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

<p>This URL format enables multiple routes or processors or beans to refer to the same temporary destination. For example, you can create three temporary destinations and use them in routes as inputs or outputs by referring to them by name.</p>

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


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>If you are using ActiveMQ</b><br />Note that the JMS component reuses Spring 2's <tt>JmsTemplate</tt> for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching in the JMS provider to avoid performance <a href="http://activemq.apache.org/jmstemplate-gotchas.html" class="external-link" rel="nofollow">being lousy</a>.

<p>So 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 configured to use ActiveMQ efficiently, or</li>
	<li>Use the <tt>PoolingConnectionFactory</tt> in ActiveMQ.</li>
</ul>
</td></tr></table></div>

<p>If you wish to use durable topic subscriptions, you need to specify both <b>clientId</b> and <b>durableSubscriptionName</b>. Note that the value of the <tt>clientId</tt> must be unique and can only be used by a single JMS connection instance in your entire network. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" 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>

<p>When using message headers, the JMS specification states that header names must be valid Java identifiers. So, by default, Camel ignores any headers that do not match this rule. So try to name your headers as if they are valid Java identifiers. One benefit of doing this is that you can then use your headers inside a JMS Selector (whose SQL92 syntax mandates Java identifier syntax for headers).</p>

<p>From Camel 1.4 onwards, a simple strategy for mapping header names is used by default. The strategy is to replace any dots in the header name with the underscore character and to reverse the replacement when the header name is restored from a JMS message sent over the wire. What does this mean? No more losing method names to invoke on a bean component, no more losing the filename header for the File Component, and so on. </p>

<p>The current header name strategy for accepting header names in Camel is as follows:</p>
<ul class="alternate" type="square">
	<li>Replace all dots with underscores (for example, <tt>org.apache.camel.MethodName</tt> becomes <tt>org_apache_camel_MethodName</tt>).</li>
	<li>Test if the name is a valid java identifier using the JDK core classes.</li>
	<li>If the test success, the header is added and sent over the wire; otherwise it is dropped (and logged at <tt>DEBUG</tt> level).</li>
</ul>


<p>In Camel 2.0 this strategy has been change a bit to use the following replacement strategy:</p>
<ul class="alternate" type="square">
	<li>Dots are replaced by <tt>&#95;DOT&#95;</tt> and the replacement is reversed when Camel consume the message</li>
	<li>Hyphen is replaced by <tt>&#95;HYPHEN&#95;</tt> and the replacement is reversed when Camel consumes the message</li>
</ul>


<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For Consuming Messages cacheLevelName settings are vital!</b><br />If you are using Spring before 2.5.1 and Camel before 1.3.0, you might want to set the <tt>cacheLevelName</tt> to be <tt>CACHE_CONSUMER</tt> for maximum performance. 

<p>Due to a <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3890" class="external-link" rel="nofollow">bug in earlier Spring versions</a> causing a lack of transactional integrity, previous versions of Camel and Camel versions from 1.3.0 onwwards when used with Spring versions earlier than 2.5.1 will default to using <tt>CACHE_CONNECTION</tt>. See the JIRAs <a href="https://issues.apache.org/activemq/browse/CAMEL-163" class="external-link" rel="nofollow">CAMEL-163</a> and <a href="https://issues.apache.org/activemq/browse/CAMEL-294" class="external-link" rel="nofollow">CAMEL-294</a>.</p>

<p>Also, if you are using XA resources or running in a J2EE container, you may want to set the <tt>cacheLevelName</tt> to be <tt>CACHE_NONE</tt> as we have found that when using JBoss with TibCo EMS and JTA/XA you must disable caching.</p>

<p>Another user reports problems using WebSphere MQ 6.0.2.5, Camel 1.6.0 and Spring 2.5.6. The application does not use XA and is not running inside a J2EE Container, but the <tt>cacheLevelName=CACHE_NONE</tt> setting seems to solve the problem with WebSphere MQ.</p>

<p>See also more about <a href="http://activemq.apache.org/jmstemplate-gotchas.html" class="external-link" rel="nofollow">JmsTemplate gotchas</a>.</p></td></tr></table></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For users with Camel 1.6.1 or older</b><br />JMS consumers have a bad default in Camel 1.6.1 or older. The <tt>maxMessagesPerTask</tt> is set to 1, whereas it really should be -1.<br/>
This issue causes Spring to create a new thread after it has processed a message, causing the thread count to rise continuously. You can see this in the log where a new thread name is used.

<p>To remedy this, change a route such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;from uri=<span class="code-quote">"jms:queue:foo"</span>/&gt;</span>
</pre>
</div></div>

<p>By adding the <tt>maxMessagesPerTask</tt> option and setting its value to -1, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;from uri=<span class="code-quote">"jms:queue:foo&amp;amp;maxMessagesPerTask=-1"</span>/&gt;</span>
</pre>
</div></div>

<p>This has been fixed in Camel 1.6.2/2.0.</p></td></tr></table></div>

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

<p>You can configure many different properties on the JMS endpoint which map to properties on the <a href="http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/JmsConfiguration.html" class="external-link" rel="nofollow">JMSConfiguration POJO</a>. <b>Note:</b> Many of these properties map to properties on Spring JMS, which Camel uses for sending and receiving messages. So you can get more information about these properties by consulting the relevant Spring documentation.</p>

<p>The options is divided into two tables, the first one with the most common options used. The latter contains the rest.</p>

<h4><a name="BookComponentAppendix-Mostcommonlyusedoptions"></a>Most commonly used options</h4>
<div class="confluenceTableSmall"><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>autoStartup</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the consumer container should auto-startup. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>clientId</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. It is typically only required for durable topic subscriptions. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" 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. </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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxConcurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the maximum number of concurrent consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preserveMessageQos</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'>  <b>Camel 2.0</b>: Set to <tt>true</tt>, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered <tt>JMSPriority</tt>, <tt>JMSDeliveryMode</tt>, and <tt>JMSExpiration</tt>. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The <tt>explicitQosEnabled</tt> option, by contrast, will only use options set on the endpoint, and not values from the message header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>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>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestTimeout</tt> </td>
<td class='confluenceTd'> <tt>20000</tt> </td>
<td class='confluenceTd'> 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. </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). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transacted</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to use transacted mode for sending/receiving messages using the InOnly <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>testConnectionOnStartup</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensure that Camel is not started with failed connections. </td>
</tr>
</tbody></table>
</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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementModeName</tt> </td>
<td class='confluenceTd'> <tt>AUTO_ACKNOWLEDGE</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement name, which is one of: <tt>TRANSACTED</tt>, <tt>CLIENT_ACKNOWLEDGE</tt>, <tt>AUTO_ACKNOWLEDGE</tt>, <tt>DUPS_OK_ACKNOWLEDGE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementMode</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement mode defined as an Integer. Allows you to set vendor-specific extensions to the acknowledgment mode. For the regular modes, it is preferable to use the <tt>acknowledgementModeName</tt> instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alwaysCopyMessage</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a <tt>replyToDestinationSelectorName</tt> is set (incidentally, Camel will set the <tt>alwaysCopyMessage</tt> option to <tt>true</tt>, if a <tt>replyToDestinationSelectorName</tt> is set) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevelName</tt> </td>
<td class='confluenceTd'> <tt>CACHE_CONSUMER</tt> </td>
<td class='confluenceTd'> Sets the cache level by name for the underlying JMS resources. Possible values are: <tt>CACHE_AUTO</tt>, <tt>CACHE_CONNECTION</tt>, <tt>CACHE_CONSUMER</tt>, <tt>CACHE_NONE</tt>, and <tt>CACHE_SESSION</tt>. See the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" class="external-link" rel="nofollow">Spring documentation</a> and see the warning above. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevel</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Sets the cache level by ID for the underlying JMS resources. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumerType</tt> </td>
<td class='confluenceTd'> <tt>Default</tt> </td>
<td class='confluenceTd'> The consumer type to use, which can be one of: <tt>Simple</tt>, <tt>Default</tt> or <tt>ServerSessionPool</tt>. The consumer type determines which Spring JMS listener to use. <tt>Default</tt> will use <tt>org.springframework.jms.listener.DefaultMessageListenerContainer</tt>, <tt>Simple</tt> will use <tt>org.springframework.jms.listener.SimpleMessageListenerContainer</tt>, and <tt>ServerSessionPool</tt> will use <tt>org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer</tt>. If the option, <tt>useVersion102=true</tt>, Camel will use the JMS 1.0.2 Spring classes instead. <tt>ServerSessionPool</tt> is <b>@deprecated</b> and will be removed in Camel 2.0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default JMS connection factory to use for the <tt>listenerConnectionFactory</tt> and <tt>templateConnectionFactory</tt>, if neither is specified. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deliveryMode</tt> </td>
<td class='confluenceTd'> <tt>2</tt> </td>
<td class='confluenceTd'> Specifies the delivery mode when sending, where 1 = non-persistent, and 2 = persistent. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether persistent delivery is used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS Destination object to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS destination name to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationResolver</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.springframework.jms.support.destination.DestinationResolver</tt> that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eagerLoadingOfProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enables eager loading of JMS properties as soon as a message is received, which is generally inefficient, because the JMS properties might not be required. But this feature can sometimes catch early any issues with the underlying JMS provider and the use of JMS properties. This feature can also be used for testing purposes, to ensure JMS properties can be understood and handled correctly. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exceptionListener</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>explicitQosEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set if the <tt>deliveryMode</tt>, <tt>priority</tt> or <tt>timeToLive</tt> qualities of service should be used when sending messages. This option is based on Spring's <tt>JmsTemplate</tt>. The <tt>deliveryMode</tt>, <tt>priority</tt> and <tt>timeToLive</tt> options are applied to the current endpoint. This contrasts with the <tt>preserveMessageQos</tt> option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exposeListenerSession</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the listener session should be exposed when consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idleTaskExecutionLimit</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the <tt>maxConcurrentConsumers</tt> setting). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsMessageType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Allows you to force the use of a specific <tt>javax.jms.Message</tt> implementation for sending JMS messages. Possible values are: <tt>Bytes</tt>, <tt>Map</tt>, <tt>Object</tt>, <tt>Stream</tt>, <tt>Text</tt>. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsKeyFormatStrategy</tt> </td>
<td class='confluenceTd'> <tt>default</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: <tt>default</tt> and <tt>passthrough</tt>. The <tt>default</tt> strategy will safely marshal dots and hyphens (<tt>.</tt> and <tt>-</tt>). The <tt>passthrough</tt> strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the <tt>org.apache.camel.component.jms.JmsKeyFormatStrategy</tt> and refer to it using the <tt>#</tt> notation.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsOperations</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to use your own implementation of the <tt>org.springframework.jms.core.JmsOperations</tt> interface. Camel uses <tt>JmsTemplate</tt> as default. Can be used for testing purpose, but not used much as stated in the spring API docs. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lazyCreateTransactionManager</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If <tt>true</tt>, Camel will create a <tt>JmsTransactionManager</tt>, if there is no <tt>transactionManager</tt> injected when option <tt>transacted=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>listenerConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mapJmsMessage</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> Specifies whether Camel should auto map the received JMS message to an appropiate payload type, such as <tt>javax.jms.TextMessage</tt> to a <tt>String</tt> etc. See section about how mapping works below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerTask</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The number of messages per task. -1 is unlimited. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageConverter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> To use a custom Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> so you can be 100% in control how to map to/from a <tt>javax.jms.Message</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageIdEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> When sending, specifies whether message IDs should be added. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageTimestampEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether timestamps should be enabled by default on sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>priority</tt> </td>
<td class='confluenceTd'> <tt>4</tt> </td>
<td class='confluenceTd'> Values greater than 1 specify the message priority when sending (where 0 is the lowest priority and 9 is the highest). The <tt>explicitQosEnabled</tt> option <b>must</b> also be enabled in order for this option to have any effect. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pubSubNoLocal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to inhibit the delivery of messages published by its own connection. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveTimeout</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> The timeout for receiving messages (in milliseconds). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>recoveryInterval</tt> </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDestinationSelectorName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDeliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether to use persistent delivery by default for replies. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subscriptionDurable</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enabled by default, if you specify a <tt>durableSubscriberName</tt> and a <tt>clientId</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>taskExecutor</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to specify a custom task executor for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>templateConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactedInOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated:</b> Specifies whether to use transacted mode for sending messages using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. Applies only to producer endpoints. See section Enabling Transacted Consumption for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The Spring transaction manager to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The name of the transaction to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The timeout value of the transaction, if using transacted mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If enabled and you are using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> messaging (InOut) and an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> failed on the consumer side, then the caused <tt>Exception</tt> will be send back in response as a <tt>javax.jms.ObjectMessage</tt>. If the client is Camel, the returned <tt>Exception</tt> is rethrown. This allows you to use Camel <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have <b>transferExchange</b> enabled, this option takes precedence. The caught exception is required to be serializable. The original <tt>Exception</tt> on the consumer side can be wrapped in an outer exception such as <tt>org.apache.camel.RuntimeCamelException</tt> when returned to the producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at <tt>WARN</tt> level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The username for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useMessageIDAsCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether <tt>JMSMessageID</tt> should always be used as <tt>JMSCorrelationID</tt> for <b>InOut</b> messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useVersion102</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated (removed from Camel 2.5 onwards):</b> Specifies whether the old JMS API should be used. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-MessageMappingbetweenJMSandCamel"></a>Message Mapping between JMS and Camel</h3>
<p>Camel automatically maps messages between <tt>javax.jms.Message</tt> and <tt>org.apache.camel.Message</tt>. </p>

<p>When sending a JMS message, Camel converts the message body to the following JMS message types:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Body Type </th>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Comment </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.w3c.dom.Node</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> The DOM will be converted to <tt>String</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Map</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Serializable</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.File</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Reader</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.InputStream</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.nio.ByteBuffer</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>
</div>


<p>When receiving a JMS message, Camel converts the JMS message to the following body type:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Body Type </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'> <tt>Map&lt;String, Object&gt;</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'> <tt>Object</tt> </td>
</tr>
</tbody></table>
</div>


<h4><a name="BookComponentAppendix-DisablingautomappingofJMSmessages"></a>Disabling auto-mapping of JMS messages</h4>
<p><b>Available as of Camel 1.6.2/2.0</b></p>

<p>You can use the <tt>mapJmsMessage</tt> option to disable the auto-mapping above. If disabled, Camel will not try to map the received JMS message, but instead uses it directly as the payload. This allows you to avoid the overhead of mapping and let Camel just pass through the JMS message. For instance, it even allows you to route <tt>javax.jms.ObjectMessage</tt> JMS messages with classes you do <b>not</b> have on the classpath.</p>

<h4><a name="BookComponentAppendix-UsingacustomMessageConverter"></a>Using a custom MessageConverter</h4>
<p><b>Available as of Camel 1.6.2/2.0</b></p>

<p>You can use the <tt>messageConverter</tt> option to do the mapping yourself in a Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> class. </p>

<p>For example, in the route below we use a custom message converter when sending a message to the JMS order queue:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?messageConverter=#myMessageConverter"</span>);</span>
</pre>
</div></div>

<p>You can also use a custom message converter when consuming from a JMS destination.</p>

<h4><a name="BookComponentAppendix-Controllingthemappingstrategyselected"></a>Controlling the mapping strategy selected</h4>
<p><b>Available as of Camel 2.0</b></p>

<p>You can use the <b>jmsMessageType</b> option on the endpoint URL to force a specific message type for all messages.<br/>
In the route below, we poll files from a folder and send them as <tt>javax.jms.TextMessage</tt> as we have forced the JMS producer endpoint to use text messages:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?jmsMessageType=Text"</span>);</span>
</pre>
</div></div>

<p>You can also specify the message type to use for each messabe by setting the header with the key <tt>CamelJmsMessageType</tt>. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).setHeader(<span class="code-quote">"CamelJmsMessageType"</span>, JmsMessageType.Text).to(<span class="code-quote">"jms:queue:order"</span>);</span>
</pre>
</div></div>

<p>The possible values are defined in the <tt>enum</tt> class, <tt>org.apache.camel.jms.JmsMessageType</tt>.</p>

<h3><a name="BookComponentAppendix-Messageformatwhensending"></a>Message format when sending</h3>
<p>The exchange that is sent over the JMS wire must conform to the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html" class="external-link" rel="nofollow">JMS Message spec</a>.</p>

<p>For the <tt>exchange.in.header</tt> the following rules apply for the header <b>keys</b>:</p>
<ul class="alternate" type="square">
	<li>Keys starting with <tt>JMS</tt> or <tt>JMSX</tt> are reserved.</li>
	<li><tt>exchange.in.headers</tt> keys must be literals and all be valid Java identifiers (do not use dots in the key name).</li>
	<li>From Camel 1.4 until Camel 1.6.x, Camel automatically replaces all dots with underscores in key names. This replacement is reversed when Camel consumes JMS messages.</li>
	<li>From Camel 2.0 onwards, Camel replaces dots &amp; hyphens and the reverse when when consuming JMS messages:<br/>
   <tt>.</tt> is replaced by <tt>&#95;DOT&#95;</tt> and the reverse replacement when Camel consumes the message.<br/>
   <tt>&#45;</tt> is replaced by <tt>&#95;HYPHEN&#95;</tt> and the reverse replacement when Camel consumes the message.</li>
	<li>See also the option <tt>jmsKeyFormatStrategy</tt> introduced in <b>Camel 2.0</b>, which allows you to use your own custom strategy for formatting keys.</li>
</ul>


<p>For the <tt>exchange.in.header</tt>, the following rules apply for the header <b>values</b>:</p>
<ul class="alternate" type="square">
	<li>The values must be primitives or their counter objects (such as <tt>Integer</tt>, <tt>Long</tt>, <tt>Character</tt>). The types, <tt>String</tt>, <tt>CharSequence</tt>, <tt>Date</tt>, <tt>BigDecimal</tt> and <tt>BigInteger</tt> are all converted to their <tt>toString()</tt> representation. All other types are dropped.</li>
</ul>


<p>Camel will log with category <tt>org.apache.camel.component.jms.JmsBinding</tt> at <b>DEBUG</b> level if it drops a given header value. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-07-09 06:43:04,046 [main           ] DEBUG JmsBinding  
  - Ignoring non primitive header: order of class: org.apache.camel.component.jms.issues.DummyOrder with value: DummyOrder{orderId=333, itemId=4444, quantity=2}
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Messageformatwhenreceiving"></a>Message format when receiving</h3>

<p>Camel adds the following properties to the <tt>Exchange</tt> when it receives a message:</p>
<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>org.apache.camel.jms.replyDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The reply destination. </td>
</tr>
</tbody></table>
</div>


<p>Camel adds the following JMS properties to the In message headers when it receives a JMS message:</p>
<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>JMSCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS correlation ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDeliveryMode</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS delivery mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSExpiration</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS expiration. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSMessageID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS unique message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSPriority</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS priority (with 0 as the lowest priority and 9 as the highest). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSRedelivered</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> Is the JMS message redelivered. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS reply-to destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSTimestamp</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS timestamp. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSXGroupID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS group ID. </td>
</tr>
</tbody></table>
</div>


<p>As all the above information is standard JMS you can check the <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html" class="external-link" rel="nofollow">JMS documentation</a> for further details.</p>


<h3><a name="BookComponentAppendix-AboutusingCameltosendandreceivemessagesandJMSReplyTo"></a>About using Camel to send and receive messages and JMSReplyTo </h3>
<p>The JMS component is complex and you have to pay close attention to how it works in some cases. So this is a short summary of some of the areas/pitfalls to look for.</p>

<p>When Camel sends a message using its <tt>JMSProducer</tt>, it checks the following conditions:</p>
<ul class="alternate" type="square">
	<li>The message exchange pattern,</li>
	<li>Whether a <tt>JMSReplyTo</tt> was set in the endpoint or in the message headers,</li>
	<li>Whether any of the following options have been set on the JMS endpoint: <tt>disableReplyTo</tt>, <tt>preserveMessageQos</tt>, <tt>explicitQosEnabled</tt>.</li>
</ul>


<p>All this can be a tad complex to understand and configure to support your use case.</p>

<h4><a name="BookComponentAppendix-JmsProducer"></a>JmsProducer</h4>
<p>The <tt>JmsProducer</tt> behaves as follows, depending on configuration:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will expect a reply, set a temporary <tt>JMSReplyTo</tt>, and after sending the message, it will start to listen for the reply message on the temporary queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is set </td>
<td class='confluenceTd'> Camel will expect a reply and, after sending the message, it will start to listen for the reply message on the specified <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the message and <b>not</b> expect a reply. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is set </td>
<td class='confluenceTd'> Camel sees this as a contradiction and will suppress the <tt>JMSReplyTo</tt>. In fact, Camel will disable it by clearing it before sending. Camel will send the message and <b>not</b> expect a reply. Camel logs this in the log at <tt>WARN</tt> level and you should see: <tt>WARN  JmsProducer - Disabling JMSReplyTo as this Exchange is not OUT capable with JMSReplyTo: myReplyQueue to destination: myQueue</tt>. <b>Note:</b> You can use the <tt>preserveMessageQos=true</tt> setting or the <tt>explicitQosEnabled=true</tt> setting to force Camel to send the <tt>JMSReplyTo</tt> anyway, and the <tt>WARN</tt> log will disappear. </td>
</tr>
</tbody></table>
</div>


<h4><a name="BookComponentAppendix-JmsConsumer"></a>JmsConsumer</h4>
<p>The <tt>JmsConsumer</tt> behaves as follows, depending on configuration:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the reply back to the <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will not send a reply back, as the pattern is <em>InOnly</em>.</td>
</tr>
<tr>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> <tt>disableReplyTo=true</tt> </td>
<td class='confluenceTd'> This option suppresses replies. </td>
</tr>
</tbody></table>
</div>


<p>So pay attention to the message exchange pattern set on your exchanges.</p>

<p>If you send a message to a JMS destination in the middle of your route you can specify the exchange pattern to use, see more at <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>.<br/>
This is useful if you want to send an <tt>InOnly</tt> message to a JMS topic:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:in"</span>)
   .to(<span class="code-quote">"bean:validateOrder"</span>)
   .to(ExchangePattern.InOnly, <span class="code-quote">"activemq:topic:order"</span>)
   .to(<span class="code-quote">"bean:handleOrder"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Reuseendpointandsendtodifferentdestinationscomputedatruntime"></a>Reuse endpoint and send to different destinations computed at runtime</h3>
<p><b>Available as of Camel 1.6.2/2.0</b><br/>
If you need to send messages to a lot of different JMS destinations, it makes sense to reuse a JMS endpoint and specify the real destination in a message header. This allows Camel to reuse the same endpoint, but send to different destinations. This greatly reduces the number of endpoints created and economizes on memory and thread resources.</p>

<p>You can specify the destination in the following headers:</p>
<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>CamelJmsDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> A destination object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelJmsDestinationName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> The destination name. </td>
</tr>
</tbody></table>
</div>



<p>For example, the following route shows how you can compute a destination at run time and use it to override the destination appearing in the JMS URL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inbox"</span>)
</span>  .to(<span class="code-quote">"bean:computeDestination"</span>)
  .to(<span class="code-quote">"activemq:queue:dummy"</span>);
</pre>
</div></div>

<p>The queue name, <tt>dummy</tt>, is just a placeholder. It must be provided as part of the JMS endpoint URL, but it will be ignored in this example.</p>

<p>In the <tt>computeDestination</tt> bean, specify the real destination by setting the <tt>CamelJmsDestinationName</tt> header as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> void setJmsHeader(Exchange exchange) {
   <span class="code-object">String</span> id = ....
   exchange.getIn().setHeader(<span class="code-quote">"CamelJmsDestinationName"</span>, <span class="code-quote">"order:"</span> + id");
}
</pre>
</div></div>

<p>Then Camel will read this header and use it as the destination instead of the one configured on the endpoint. So, in this example Camel sends the message to <tt>activemq:queue:order:2</tt>, assuming the <tt>id</tt> value was 2.</p>

<p>If both the <tt>CamelJmsDestination</tt> and the <tt>CamelJmsDestinationName</tt> headers are set, <tt>CamelJmsDestination</tt> takes priority.</p>


<h3><a name="BookComponentAppendix-ConfiguringdifferentJMSproviders"></a>Configuring different JMS providers</h3>

<p>You can configure your JMS provider in <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a> XML as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span>&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span class="code-quote">"vm://localhost?broker.persistent=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Basically, you can configure as many JMS component instances as you wish and give them <b>a unique name using the <tt>id</tt> attribute</b>. The preceding example configures an <tt>activemq</tt> component. You could do the same to configure MQSeries, TibCo, BEA, Sonic and so on.</p>

<p>Once you have a named JMS component, you can then refer to endpoints within that component using URIs. For example for the component name, <tt>activemq</tt>, you can then refer to destinations using the URI format, <tt>activemq:[queue:&#124;topic:]destinationName</tt>. You can use the same approach for all other JMS providers.</p>

<p>This works by the SpringCamelContext lazily fetching components from the spring context for the scheme name you use for <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a> and having the <a href="/confluence/display/CAMEL/Component" title="Component">Component</a> resolve the endpoint URIs. </p>


<h4><a name="BookComponentAppendix-UsingJNDItofindtheConnectionFactory"></a>Using JNDI to find the ConnectionFactory</h4>

<p>If you are using a J2EE container, you might need to look up JNDI to find the JMS <tt>ConnectionFactory</tt> rather than use the usual <tt>&lt;bean&gt;</tt> mechanism in Spring. You can do this using Spring's factory bean or the new Spring XML namespace. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"weblogic"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span class="code-quote">"myConnectionFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;jee:jndi-lookup id=<span class="code-quote">"myConnectionFactory"</span> jndi-name=<span class="code-quote">"jms/connectionFactory"</span>/&gt;</span>
</pre>
</div></div>

<p>See <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-jee" class="external-link" rel="nofollow">The jee schema</a> in the Spring reference documentation for more details about JNDI lookup.</p>

<h4><a name="BookComponentAppendix-UsingJNDItolookupthephysicalqueues"></a>Using JNDI to lookup the physical queues</h4>
<p>You need to use the <tt>destinationResolver</tt> option to use the Spring JNDI resolver that can lookup in the JNDI, or use your own custom implementation. </p>

<p>See this nabble post for more details:
<a href="http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html" class="external-link" rel="nofollow">http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html</a></p>


<h4><a name="BookComponentAppendix-UsingWebSphereMQ"></a>Using WebSphere MQ</h4>
<p>See this <a href="http://www.nabble.com/Camel-and-IBM-MQ-Series-td24524277.html" class="external-link" rel="nofollow">link at nabble</a> for details of how a Camel user configured <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> to connect to remote WebSphere MQ brokers.</p>


<h3><a name="BookComponentAppendix-ConcurrentConsuming"></a>Concurrent Consuming</h3>

<p>A common requirement with JMS is to consume messages concurrently in multiple threads in order to make an application more responsive. You can set the <tt>concurrentConsumers</tt> option to specify the number of threads servicing the JMS endpoint, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:SomeQueue?concurrentConsumers=20"</span>).
  bean(MyClass.class);
</pre>
</div></div>

<p>You can configure this option in one of the following ways:</p>
<ul>
	<li>On the <tt>JmsComponent</tt>,</li>
	<li>On the endpoint URI or,</li>
	<li>By invoking <tt>setConcurrentConsumers()</tt> directly on the <tt>JmsEndpoint</tt>.</li>
</ul>



<h3><a name="BookComponentAppendix-EnablingTransactedConsumption"></a>Enabling Transacted Consumption</h3>

<p>A common requirement is to consume from a queue in a transaction and then process the message using the Camel route. To do this, just ensure that you set the following properties on the component/endpoint:</p>

<ul>
	<li><tt>transacted</tt> = true</li>
	<li><tt>transactionManager</tt> = a Transsaction Manager - typically the <tt>JmsTransactionManager</tt></li>
</ul>


<p>See also the <a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a> EIP pattern for further details.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Transaction and <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS</b><br />Note that when using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS you cannot use a single transaction; as JMS will not send any messages until a commit is performed, the server side won't receive anything at all until the transaction commits. So, with request/response you must commit a transaction after sending the first request and then use a separate transaction for receiving the response.

<p>This is why the <tt>transacted</tt> property applies only to the InOnly message <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (MEP). If you want to use transactions for the InOut MEP as well, you must set <tt>transactedInOut=true</tt>.</p>

<p>To recap: if you have <tt>transacted=true</tt>, <tt>transactedInOut=false</tt> and are sending an <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">InOut</a>, the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> will <b>not</b> use transactions.</p></td></tr></table></div>

<h3><a name="BookComponentAppendix-UsingJMSReplyToforlatereplies"></a>Using JMSReplyTo for late replies</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>When using Camel as a JMS listener, it sets an Exchange property with the value of the ReplyTo <tt>javax.jms.Destination</tt> object, having the key <tt>ReplyTo</tt>. You can obtain this <tt>Destination</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
</pre>
</div></div>

<p>And then later use it to send a reply using regular JMS or Camel.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we need to pass in the JMS component, and in <span class="code-keyword">this</span> sample we use ActiveMQ
</span>    JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent);
    <span class="code-comment">// now we have the endpoint we can use regular Camel API to send a message to it
</span>    template.sendBody(endpoint, <span class="code-quote">"Here is the late reply."</span>);
</pre>
</div></div>

<p>A different solution to sending a reply is to provide the <tt>replyDestination</tt> object in the same Exchange property when sending. Camel will then pick up this property and use it for the real destination. The endpoint URI must include a dummy destination, however. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we pretend to send it to some non existing dummy queue
</span>    template.send("activemq:queue:dummy, <span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
</span>            exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
            exchange.getIn().setBody(<span class="code-quote">"Here is the late reply."</span>);
        }
    }
</pre>
</div></div>


<h3><a name="BookComponentAppendix-Usingarequesttimeout"></a>Using a request timeout</h3>
<p>In the sample below we send a <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> style message <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> (we use the <tt>requestBody</tt> method = <tt>InOut</tt>) to the slow queue for further processing in Camel and we wait for a return reply: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// send a in-out with a timeout <span class="code-keyword">for</span> 5 sec
</span><span class="code-object">Object</span> out = template.requestBody(<span class="code-quote">"activemq:queue:slow?requestTimeout=5000"</span>, <span class="code-quote">"Hello World"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Samples"></a>Samples</h3>
<p>JMS is used in many examples for other components as well. But we provide a few samples below to get started.</p>

<h4><a name="BookComponentAppendix-ReceivingfromJMS"></a>Receiving from JMS</h4>
<p>In the following sample we configure a route that receives JMS messages and routes the message to a POJO:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   from(<span class="code-quote">"jms:queue:foo"</span>).
     to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<p>You can of course use any of the EIP patterns so the route can be context based. For example, here's how to filter an order topic for the big spenders:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:topic:OrdersTopic"</span>).
  filter().method(<span class="code-quote">"myBean"</span>, <span class="code-quote">"isGoldCustomer"</span>).
    to(<span class="code-quote">"jms:queue:BigSpendersQueue"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-SendingtoaJMS"></a>Sending to a JMS </h4>
<p>In the sample below we poll a file folder and send the file content to a JMS topic. As we want the content of the file as a <tt>TextMessage</tt> instead of a <tt>BytesMessage</tt>, we need to convert the body to a <tt>String</tt>:</p>

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

<h4><a name="BookComponentAppendix-UsingAnnotationsBeanIntegration"></a>Using <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Annotations</a></h4>
<p>Camel also has annotations so you can use <a href="/confluence/display/CAMEL/POJO+Consuming" title="POJO Consuming">POJO Consuming</a> and <a href="/confluence/display/CAMEL/POJO+Producing" title="POJO Producing">POJO Producing</a>. </p>

<h4><a name="BookComponentAppendix-SpringDSLsample"></a>Spring DSL sample</h4>
<p>The preceding examples use the Java DSL. Camel also supports Spring XML DSL. Here is the big spender sample using Spring DSL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"jms:topic:OrdersTopic"</span>/&gt;</span>
  <span class="code-tag">&lt;filter&gt;</span>
    <span class="code-tag">&lt;method bean=<span class="code-quote">"myBean"</span> method=<span class="code-quote">"isGoldCustomer"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"jms:queue:BigSpendersQueue"</span>/&gt;</span>
  <span class="code-tag">&lt;/filter&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Othersamples"></a>Other samples</h4>
<p>JMS appears in many of the examples for other components and EIP patterns, as well in this Camel documentation. So feel free to browse the documentation. If you have time, check out the this tutorial that uses JMS but focuses on how well Spring Remoting and Camel works together <a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a>.</p>

<h4><a name="BookComponentAppendix-UsingJMSasaDeadLetterQueuestoringExchange"></a>Using JMS as a Dead Letter Queue storing Exchange</h4>
<p><b>Available as of Camel 2.0</b><br/>
Normally, when using <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as the transport, it only transfers the body and headers as the payload. If you want to use <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with a <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead Letter Channel</a>, using a JMS queue as the Dead Letter Queue, then normally the caused Exception is not stored in the JMS message. You can, however, use the <b>transferExchange</b> option on the JMS dead letter queue to instruct Camel to store the entire <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> in the queue as a <tt>javax.jms.ObjectMessage</tt> that holds a <tt>org.apache.camel.impl.DefaultExchangeHolder</tt>. This allows you to consume from the Dead Letter Queue and retrieve the caused exception from the Exchange property with the key <tt>Exchange.EXCEPTION_CAUGHT</tt>. The demo below illustrates this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// setup error handler to use JMS as queue and store the entire Exchange
</span>errorHandler(deadLetterChannel(<span class="code-quote">"jms:queue:dead?transferExchange=<span class="code-keyword">true</span>"</span>));
</pre>
</div></div>

<p>Then you can consume from the JMS queue and analyze the problem:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:queue:dead"</span>).to(<span class="code-quote">"bean:myErrorAnalyzer"</span>);

<span class="code-comment">// and in our bean
</span><span class="code-object">String</span> body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
<span class="code-comment">// the cause message is
</span><span class="code-object">String</span> problem = cause.getMessage();
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingJMSasaDeadLetterChannelstoringerroronly"></a>Using JMS as a Dead Letter Channel storing error only</h4>
<p>You can use JMS to store the cause error message or to store a custom body, which you can initialize yourself. The following example uses the <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> EIP to do a transformation on the failed exchange before it is moved to the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> dead letter queue:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// we sent it to a seda dead queue first
</span>errorHandler(deadLetterChannel(<span class="code-quote">"seda:dead"</span>));

<span class="code-comment">// and on the seda dead queue we can <span class="code-keyword">do</span> the custom transformation before its sent to the JMS queue
</span>from(<span class="code-quote">"seda:dead"</span>).transform(exceptionMessage()).to(<span class="code-quote">"jms:queue:dead"</span>);
</pre>
</div></div>
<p>Here we only store the original cause error message in the transform. You can, however, use any <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to send whatever you like. For example, you can invoke a method on a Bean or use a custom processor.</p>

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

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a></li>
	<li><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a></li>
	<li><a href="http://activemq.apache.org/jmstemplate-gotchas.html" class="external-link" rel="nofollow">JMSTemplate gotchas</a></li>
</ul>

<h2><a name="BookComponentAppendix-JPAComponent"></a>JPA Component</h2>

<p>The <b>jpa</b> component enables you to store and retrieve Java objects from persistent storage using EJB 3's Java Persistence Architecture (JPA), which is a standard interface layer that wraps Object/Relational Mapping (ORM) products such as OpenJPA, Hibernate, TopLink, and so on.</p>

<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-jpa<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-Sendingtotheendpoint"></a>Sending to the endpoint</h3>

<p>You can store a Java entity bean in a database by sending it to a JPA producer endpoint. The body of the <em>In</em> message is assumed to be an entity bean (that is, a POJO with an <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Entity.html" class="external-link" rel="nofollow">@Entity</a> annotation on it) or a collection or array of entity beans. </p>

<p>If the body does not contain one of the previous listed types, put a <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> in front of the endpoint to perform the necessary conversion first.</p>

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

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

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

<p>If you would rather perform some update on the entity to mark it as processed (such as to exclude it from a future query) then you can annotate a method with <a href="http://activemq.apache.org/camel/maven/camel-jpa/apidocs/org/apache/camel/component/jpa/Consumed.html" 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">
jpa:[entityClassName][?options]
</pre>
</div></div>

<p>For sending to the endpoint, the <em>entityClassName</em> is optional. If specified, it helps the <a href="/confluence/display/CAMEL/Type+Converter" title="Type Converter">Type Converter</a> to ensure the body is of the correct type.</p>

<p>For consuming, the <em>entityClassName</em> is mandatory.</p>

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

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

<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'> Overrides the <em>entityClassName</em> from the URI. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>persistenceUnit</tt> </td>
<td class='confluenceTd'> <tt>camel</tt> </td>
<td class='confluenceTd'> The JPA persistence unit used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeDelete</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> If <tt>true</tt>, the entity is deleted after it is consumed; if <tt>false</tt>, the entity is not deleted. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumeLockEntity</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>flushOnSend</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>JPA producer only:</b> Flushes the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html" 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'>  <b>JPA consumer only:</b> Set the maximum number of results to retrieve on the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html" class="external-link" rel="nofollow">Query</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1/2.0:</b> Specifies the transaction manager to use. If none provided, Camel will use a <tt>JpaTransactionManager</tt> by default. Can be used to set a JTA transaction manager (for integration with an EJB container). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.useFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>JPA consumer only:</b> Set to <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> <b>JPA consumer only:</b> An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to avoid polling many thousands of messages when starting up the server. Set a value of 0 or negative to disable. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.query</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a custom query when consuming data. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.namedQuery</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a named query when consuming data. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.nativeQuery</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>JPA consumer only:</b> To use a custom native query when consuming data. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>usePersist</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5: JPA producer only:</b> Indicates to use <tt>entityManager.persist(entity)</tt> instead of <tt>entityManager.merge(entity)</tt>. Note: <tt>entityManager.persist(entity)</tt> doesn't work for detached entities (where the EntityManager has to execute an UPDATE instead of an INSERT query)! </td>
</tr>
</tbody></table>
</div>



<h3><a name="BookComponentAppendix-MessageHeaders"></a>Message Headers</h3>
<p>Camel adds the following message headers to the exchange:</p>

<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>CamelJpaTemplate</tt> </td>
<td class='confluenceTd'> <tt>JpaTemplate</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> The <tt>JpaTemplate</tt> object that is used to access the entity bean. You need this object in some situations, for instance in a type converter or when you are doing some custom processing. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-ConfiguringEntityManagerFactory"></a>Configuring EntityManagerFactory</h3>
<p>Its strongly advised to configure the JPA component to use a specific <tt>EntityManagerFactory</tt> instance. If failed to do so each <tt>JpaEndpoint</tt> will auto create their own instance of <tt>EntityManagerFactory</tt> which most often is not what you want.</p>

<p>For example, you can instantiate a JPA component that references the <tt>myEMFactory</tt> entity manager factory, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpa"</span> class=<span class="code-quote">"org.apache.camel.component.jpa.JpaComponent"</span>&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"entityManagerFactory"</span> ref=<span class="code-quote">"myEMFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>In <b>Camel 2.3</b> the <tt>JpaComponent</tt> will auto lookup the <tt>EntityManagerFactory</tt> from the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> which means you do not need to configure this on the <tt>JpaComponent</tt> as shown above. You only need to do so if there is ambiguity, in which case Camel will log a WARN.</p>

<h3><a name="BookComponentAppendix-ConfiguringTransactionManager"></a>Configuring TransactionManager</h3>
<p>Its strongly advised to configure the <tt>TransactionManager</tt> instance used by the JPA component. If failed to do so each <tt>JpaEndpoint</tt> will auto create their own instance of <tt>TransactionManager</tt> which most often is not what you want.</p>

<p>For example, you can instantiate a JPA component that references the <tt>myTransactionManager</tt> transaction manager, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"jpa"</span> class=<span class="code-quote">"org.apache.camel.component.jpa.JpaComponent"</span>&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"entityManagerFactory"</span> ref=<span class="code-quote">"myEMFactory"</span>/&gt;</span>
   <span class="code-tag">&lt;property name=<span class="code-quote">"transactionManager"</span> ref=<span class="code-quote">"myTransactionManager"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>In <b>Camel 2.3</b> the <tt>JpaComponent</tt> will auto lookup the <tt>TransactionManager</tt> from the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> which means you do not need to configure this on the <tt>JpaComponent</tt> as shown above. You only need to do so if there is ambiguity, in which case Camel will log a WARN.</p>

<h3><a name="BookComponentAppendix-Usingaconsumerwithanamedquery"></a>Using a consumer with a named query</h3>
<p>For consuming only selected entities, you can use the <tt>consumer.namedQuery</tt> URI query option. First, you have to define the named query in the JPA Entity class:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Entity
@NamedQuery(name = <span class="code-quote">"step1"</span>, query = <span class="code-quote">"select x from MultiSteps x where x.step = 1"</span>)
<span class="code-keyword">public</span> class MultiSteps {
   ...
}
</pre>
</div></div>

<p>After that you can define a consumer uri like this one:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jpa:<span class="code-comment">//org.apache.camel.examples.MultiSteps?consumer.namedQuery=step1"</span>)
</span>.to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Usingaconsumerwithaquery"></a>Using a consumer with a query</h3>
<p>For consuming only selected entities, you can use the <tt>consumer.query</tt> URI query option. You only have to define the query option:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jpa:<span class="code-comment">//org.apache.camel.examples.MultiSteps?consumer.query=select o from org.apache.camel.examples.MultiSteps o where o.step = 1"</span>)
</span>.to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Usingaconsumerwithanativequery"></a>Using a consumer with a native query</h3>
<p>For consuming only selected entities, you can use the <tt>consumer.nativeQuery</tt> URI query option. You only have to define the native query option:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jpa:<span class="code-comment">//org.apache.camel.examples.MultiSteps?consumer.nativeQuery=select * from MultiSteps where step = 1"</span>)
</span>.to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<p>If you use the native query option, you will receive an object array in the message body.</p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>See <a href="/confluence/display/CAMEL/Tracer+Example" title="Tracer Example">Tracer Example</a> for an example using <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> to store traced messages into a database.</p>

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

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

<h2><a name="BookComponentAppendix-JT%2F400Component"></a>JT/400 Component</h2>

<p>The <b><tt>jt400</tt></b> component allows you to exchanges messages with an AS/400 system using data queues.  This components is only available in Camel 1.5 and above.</p>

<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-jt400&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">
jt400:<span class="code-comment">//user:password@system/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ[?options]</span>
</pre>
</div></div>

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

<h3><a name="BookComponentAppendix-URIoptions"></a>URI options</h3>
<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>ccsid</tt> </td>
<td class='confluenceTd'> default system CCSID </td>
<td class='confluenceTd'> Specifies the CCSID to use for the connection with the AS/400 system. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>format</tt> </td>
<td class='confluenceTd'> <tt>text</tt> </td>
<td class='confluenceTd'> Specifies the data format for sending messages <br class="atl-forced-newline" /> valid options are: <tt>text</tt> (represented by <tt>String</tt>) and <tt>binary</tt> (represented by <tt>byte[]</tt>) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <tt>true</tt> to use fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Usage"></a>Usage</h3>
<p>When configured as a consumer endpoint, the endpoint will poll a data queue on a remote system.  For every entry on the data queue, a new <tt>Exchange</tt> is sent with the entry's data in the <em>In</em> message's body, formatted either as a <tt>String</tt> or a <tt>byte[]</tt>, depending on the format.  For a provider endpoint, the <em>In</em> message body contents will be put on the data queue as either raw bytes or text.</p>

<h3><a name="BookComponentAppendix-Example"></a>Example</h3>
<p>In the snippet below, the data for an exchange sent to the <tt>direct:george</tt> endpoint will be put in the data queue <tt>PENNYLANE</tt> in library <tt>BEATLES</tt> on a system named <tt>LIVERPOOL</tt>.  <br class="atl-forced-newline" />
Another user connects to the same data queue to receive the information from the data queue and forward it to the <tt>mock:ringo</tt> endpoint.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class Jt400RouteBuilder <span class="code-keyword">extends</span> RouteBuilder {

    @Override
    <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception {
       from(<span class="code-quote">"direct:george"</span>).to(<span class="code-quote">"jt400:<span class="code-comment">//GEORGE:EGROEG@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"</span>);
</span>       from(<span class="code-quote">"jt400:<span class="code-comment">//RINGO:OGNIR@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"</span>).to(<span class="code-quote">"mock:ringo"</span>);
</span>    }
}
</pre>
</div></div>

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

<h2><a name="BookComponentAppendix-LDAPComponent"></a>LDAP Component</h2>

<p>The <b>ldap</b> component allows you to perform searches in LDAP servers using filters as the message payload.<br/>
This component uses standard JNDI (<tt>javax.naming</tt> package) to access the server. </p>

<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-ldap&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">
ldap:ldapServerBean[?options]
</pre>
</div></div>

<p>The <em>ldapServerBean</em> portion of the URI refers to a <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html" class="external-link" rel="nofollow">DirContext</a> bean in the registry. The LDAP component only supports producer endpoints, which means that an <tt>ldap</tt> URI cannot appear in the <tt>from</tt> at the start of a route.</p>

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

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

<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>base</tt> </td>
<td class='confluenceTd'> <tt>ou=system</tt> </td>
<td class='confluenceTd'> The base DN for searches. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scope</tt> </td>
<td class='confluenceTd'> <tt>subtree</tt> </td>
<td class='confluenceTd'> Specifies how deeply to search the tree of entries, starting at the base DN.  Value can be <tt>object</tt>, <tt>onelevel</tt>, or <tt>subtree</tt>. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Result"></a>Result</h3>
<p>The result is returned in the Out body as a <tt>ArrayList&lt;javax.naming.directory.SearchResult&gt;</tt> object. </p>

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

<p>The URI, <tt>ldap:ldapserver</tt>, references a Spring bean with the ID, <tt>ldapserver</tt>. The <tt>ldapserver</tt> bean may be defined as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"ldapserver"</span> class=<span class="code-quote">"javax.naming.directory.InitialDirContext"</span> scope=<span class="code-quote">"prototype"</span>&gt;
  &lt;constructor-arg&gt;
    &lt;props&gt;
      &lt;prop key=<span class="code-quote">"java.naming.factory.initial"</span>&gt;com.sun.jndi.ldap.LdapCtxFactory&lt;/prop&gt;
      &lt;prop key=<span class="code-quote">"java.naming.provider.url"</span>&gt;ldap:<span class="code-comment">//localhost:10389&lt;/prop&gt;
</span>      &lt;prop key=<span class="code-quote">"java.naming.security.authentication"</span>&gt;none&lt;/prop&gt;
    &lt;/props&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p>The preceding example declares a regular Sun based LDAP <tt>DirContext</tt> that connects anonymously to a locally hosted LDAP server.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><tt>DirContext</tt> objects are <b>not</b> required to support concurrency by contract. It is therefore important that the directory context is declared with the setting, <tt>scope="prototype"</tt>, in the <tt>bean</tt> definition or that the context supports concurrency. In the Spring framework, <tt>prototype</tt> scoped objects are instantiated each time they are looked up.</td></tr></table></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Camel 1.6.1 and Camel 2.0 include a <a href="https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=51503" class="external-link" rel="nofollow">fix</a> to support concurrency for LDAP producers. <em>ldapServerBean</em> contexts are now looked up each time a request is sent to the LDAP server. In addition, the contexts are released as soon as the producer completes.</td></tr></table></div>

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

<p>Following on from the Spring configuration above, the code sample below sends an LDAP request to filter search a group for a member. The Common Name is then extracted from the response.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
ProducerTemplate&lt;Exchange&gt; template = exchange
  .getContext().createProducerTemplate();

Collection&lt;?&gt; results = (Collection&lt;?&gt;) (template
  .sendBody(
    <span class="code-quote">"ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system"</span>,
    <span class="code-quote">"(member=uid=huntc,ou=users,ou=system)"</span>));

<span class="code-keyword">if</span> (results.size() &gt; 0) {
  <span class="code-comment">// Extract what we need from the device's profile
</span>
  Iterator&lt;?&gt; resultIter = results.iterator();
  SearchResult searchResult = (SearchResult) resultIter
      .next();
  Attributes attributes = searchResult
      .getAttributes();
  Attribute deviceCNAttr = attributes.get(<span class="code-quote">"cn"</span>);
  <span class="code-object">String</span> deviceCN = (<span class="code-object">String</span>) deviceCNAttr.get();

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

<p>If no specific filter is required - for example, you just need to look up a single entry - specify a wildcard filter expression. For example, if the LDAP entry has a Common Name, use a filter expression like:</p>

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

<h4><a name="BookComponentAppendix-Bindingusingcredentials"></a>Binding using credentials</h4>

<p>A Camel end user donated this sample code he used to bind to the ldap server using credentials.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Properties props = <span class="code-keyword">new</span> Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, <span class="code-quote">"com.sun.jndi.ldap.LdapCtxFactory"</span>);
props.setProperty(Context.PROVIDER_URL, <span class="code-quote">"ldap:<span class="code-comment">//localhost:389"</span>);
</span>props.setProperty(Context.URL_PKG_PREFIXES, <span class="code-quote">"com.sun.jndi.url"</span>);
props.setProperty(Context.REFERRAL, <span class="code-quote">"ignore"</span>);
props.setProperty(Context.SECURITY_AUTHENTICATION, <span class="code-quote">"simple"</span>);
props.setProperty(Context.SECURITY_PRINCIPAL, <span class="code-quote">"cn=Manager"</span>);
props.setProperty(Context.SECURITY_CREDENTIALS, <span class="code-quote">"secret"</span>);

SimpleRegistry reg = <span class="code-keyword">new</span> SimpleRegistry();
reg.put(<span class="code-quote">"myldap"</span>, <span class="code-keyword">new</span> InitialLdapContext(props, <span class="code-keyword">null</span>));

CamelContext context = <span class="code-keyword">new</span> DefaultCamelContext(reg);
context.addRoutes(
    <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:start"</span>).to(<span class="code-quote">"ldap:myldap?base=ou=test"</span>);
        }
    }
);
context.start();

ProducerTemplate template = context.createProducerTemplate();

Endpoint endpoint = context.getEndpoint(<span class="code-quote">"direct:start"</span>);
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody(<span class="code-quote">"(uid=test)"</span>);
Exchange out = template.send(endpoint, exchange);

Collection&lt;SearchResult&gt; data = out.getOut().getBody(Collection.class);
<span class="code-keyword">assert</span> data != <span class="code-keyword">null</span>;
<span class="code-keyword">assert</span> !data.isEmpty();

<span class="code-object">System</span>.out.println(out.getOut().getBody());

context.stop();
</pre>
</div></div>

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

<h2><a name="BookComponentAppendix-LogComponent"></a>Log Component</h2>

<p>The <b>log:</b> component logs message exchanges to the underlying logging mechanism.</p>

Camel uses <a href="http://commons.apache.org/logging/" class="external-link" rel="nofollow">commons-logging</a> which allows you to configure logging via 

<ul>
	<li><a href="http://logging.apache.org/log4j/" class="external-link" rel="nofollow">Log4j</a></li>
	<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html" class="external-link" rel="nofollow">JDK 1.4 logging</a></li>
	<li>Avalon</li>
	<li>SimpleLog - a simple provider in commons-logging</li>
</ul>


<p>Refer to the <a href="http://commons.apache.org/logging/commons-logging-1.1.1/guide.html" class="external-link" rel="nofollow">commons-logging user guide</a> for a more complete overview of how to use and configure commons-logging.</p>


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

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

<p>Where <b>loggingCategory</b> is the name of the logging category to use. You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<p>For example, a log endpoint typically specifies the logging level using the <tt>level</tt> option, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
log:org.apache.camel.example?level=DEBUG
</pre>
</div></div>

<p>The default logger logs every exchange (<em>regular logging</em>). But Camel also ships with the <tt>Throughput</tt> logger, which is used whenever the <tt>groupSize</tt> option is specified.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Also a log in the DSL</b><br />In <b>Camel 2.2</b> onwards there is a <tt>log</tt> directly in the DSL, but it has a different purpose. Its meant for lightweight and human logs. See more details at <a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a>.</td></tr></table></div>

<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'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>level</tt> </td>
<td class='confluenceTd'> <tt>INFO</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Logging level to use. Possible values: <tt>FATAL</tt>, <tt>ERROR</tt>, <tt>WARN</tt>, <tt>INFO</tt>, <tt>DEBUG</tt>, <tt>TRACE</tt>, <tt>OFF</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> An integer that specifies a group size for throughput logging. By default, regular logging is used. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Formatting"></a>Formatting</h3>
<p>The log formats the execution of exchanges to log lines. <br/>
By default, the log uses <tt>LogFormatter</tt> to format the log output, where <tt>LogFormatter</tt> has the following options:</p>

<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>showAll</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Quick option for turning all options on. (multiline, maxChars has to be manually set if to be used) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showExchangeId</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the unique exchange ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showExchangePattern</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Shows the Message Exchange Pattern (or MEP for short). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the exchange properties. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showHeaders</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBodyType</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body Java type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBody</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If the exchange has an Out message, show the Out message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If the exchange has an exception, show the exception message (no stack trace). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showCaughtException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If the exchange has a caught exception, show the exception message (no stack trace). A caught exception is stored as a property on the exchange and for instance a <tt>doCatch</tt> can catch exceptions. See <a href="/confluence/display/CAMEL/Try+Catch+Finally" title="Try Catch Finally">Try Catch Finally</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showStackTrace</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Show the stack trace, if an exchange has an exception. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showFuture</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Whether Camel should show <tt>java.util.concurrent.Future</tt> bodies or not. If enabled Camel could potentially wait until the <tt>Future</tt> task is done. Will by default not wait. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, each piece of information is logged on a new line. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxChars</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Limits the number of characters logged per line. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-Regularloggersample"></a>Regular logger sample</h3>
<p>In the route below we log the incoming orders at <tt>DEBUG</tt> level before the order is processed:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<p>Or using Spring XML to define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:orders"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processOrder"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span> 
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Regularloggerwithformattersample"></a>Regular logger with formatter sample</h3>
<p>In the route below we log the incoming orders at <tt>INFO</tt> level before the order is processed.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?showAll=<span class="code-keyword">true</span>&amp;multiline=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Throughputloggersample"></a>Throughput logger sample</h3>
<p>In the route below we log the throughput of the incoming orders at <tt>DEBUG</tt> level grouped by 10 messages.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG?groupSize=10"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

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

<ul>
	<li><a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+log4j" title="How do I use log4j">How do I use log4j</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+Java+1.4+logging" title="How do I use Java 1.4 logging">How do I use Java 1.4 logging</a></li>
	<li><a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a> for using <tt>log</tt> directly in the DSL for human logs.</li>
</ul>


<h2><a name="BookComponentAppendix-Lucene%28IndexerandSearch%29Component"></a>Lucene (Indexer and Search) Component</h2>

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

<p>The <b>lucene</b> component is based on the Apache Lucene project. Apache Lucene is a powerful high-performance, full-featured text search engine library written entirely in Java. For more details about Lucene, please see the following links </p>
<ul>
	<li><a href="http://lucene.apache.org/java/docs/" class="external-link" rel="nofollow">http://lucene.apache.org/java/docs/</a></li>
	<li><a href="http://lucene.apache.org/java/docs/features.html" class="external-link" rel="nofollow">http://lucene.apache.org/java/docs/features.html</a></li>
</ul>


<p>The lucene component in camel facilitates integration and utilization of Lucene endpoints in enterprise integration patterns and scenarios. The lucene component does the following</p>
<ul>
	<li>builds a searchable index of documents when payloads are sent to the Lucene Endpoint</li>
	<li>facilitates performing of indexed searches in Camel</li>
</ul>


<p>This component only supports producer endpoints. </p>

<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-lucene&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">
lucene:searcherName:insert[?options]
lucene:searcherName:query[?options]
</pre>
</div></div>

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

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

<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>analyzer</tt> </td>
<td class='confluenceTd'> <tt>StandardAnalyzer</tt> </td>
<td class='confluenceTd'> An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class org.apache.lucene.analysis.Analyzer. Lucene also offers a rich set of analyzers out of the box </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>indexDir</tt> </td>
<td class='confluenceTd'> <tt>./indexDirectory</tt> </td>
<td class='confluenceTd'> A file system directory in which index files are created upon analysis of the document by the specified analyzer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>srcDir</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> An optional directory containing files to be used to be analyzed and added to the index at producer startup. </td>
</tr>
</tbody></table>
</div>


<h3><a name="BookComponentAppendix-QueryOptions"></a>Query 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>analyzer</tt> </td>
<td class='confluenceTd'> <tt>StandardAnalyzer</tt> </td>
<td class='confluenceTd'> An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class org.apache.lucene.analysis.Analyzer. Lucene also offers a rich set of analyzers out of the box </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>indexDir</tt> </td>
<td class='confluenceTd'> <tt>./indexDirectory</tt> </td>
<td class='confluenceTd'> A file system directory in which index files are created upon analysis of the document by the specified analyzer </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxHits</tt> </td>
<td class='confluenceTd'> <tt>10</tt> </td>
<td class='confluenceTd'> An integer value that limits the result set of the search operation </td>
</tr>
</tbody></table>
</div>


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

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

<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>QUERY</tt> </td>
<td class='confluenceTd'> The Lucene Query to performed on the index. The query may include wildcards and phrases </td>
</tr>
</tbody></table>
</div>


<h4><a name="BookComponentAppendix-LuceneProducers"></a>Lucene Producers </h4>
<p>This component supports 2 producer endpoints.</p>
<ul>
	<li><b>insert</b> - The insert producer builds a searchable index by analyzing the body in incoming exchanges and associating it with a token ("content").</li>
	<li><b>query</b> - The query producer performs searches on a pre-created index. The query uses the searchable index to perform score &amp; relevance based searches. Queries are sent via the incoming exchange contains a header property name called 'QUERY'. The value of the header property 'QUERY' is a Lucene Query. For more details on how to create Lucene Queries check out <a href="http://lucene.apache.org/java/3_0_0/queryparsersyntax.html" class="external-link" rel="nofollow">http://lucene.apache.org/java/3_0_0/queryparsersyntax.html</a></li>
</ul>


<h4><a name="BookComponentAppendix-LuceneProcessor"></a>Lucene Processor </h4>
<p>There is a processor called LuceneQueryProcessor available to perform queries against lucene without the need to create a producer.</p>

<h3><a name="BookComponentAppendix-LuceneUsageSamples"></a>Lucene Usage Samples</h3>

<h4><a name="BookComponentAppendix-Example1%3ACreatingaLuceneindex"></a>Example 1: Creating a Lucene index</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(<span class="code-quote">"direct:start"</span>).
           to(<span class="code-quote">"lucene:whitespaceQuotesIndex:insert?analyzer=#whitespaceAnalyzer&amp;indexDir=#whitespace&amp;srcDir=#load_dir"</span>).
           to(<span class="code-quote">"mock:result"</span>);
    }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3ALoadingpropertiesintotheJNDIregistryintheCamelContext"></a>Example 2: Loading properties into the JNDI registry in the Camel Context </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Override
<span class="code-keyword">protected</span> JndiRegistry createRegistry() <span class="code-keyword">throws</span> Exception {
  JndiRegistry registry =
         <span class="code-keyword">new</span> JndiRegistry(createJndiContext());
  registry.bind(<span class="code-quote">"whitespace"</span>, <span class="code-keyword">new</span> File(<span class="code-quote">"./whitespaceIndexDir"</span>));
  registry.bind(<span class="code-quote">"load_dir"</span>,
        <span class="code-keyword">new</span> File(<span class="code-quote">"src/test/resources/sources"</span>));
  registry.bind(<span class="code-quote">"whitespaceAnalyzer"</span>,
        <span class="code-keyword">new</span> WhitespaceAnalyzer());
  <span class="code-keyword">return</span> registry;
}
...
CamelContext context = <span class="code-keyword">new</span> DefaultCamelContext(createRegistry());
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example2%3APerformingsearchesusingaQueryProducer"></a>Example 2: Performing searches using a Query Producer</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
       from(<span class="code-quote">"direct:start"</span>).
          setHeader(<span class="code-quote">"QUERY"</span>, constant(<span class="code-quote">"Seinfeld"</span>)).
          to(<span class="code-quote">"lucene:searchIndex:query?analyzer=#whitespaceAnalyzer&amp;indexDir=#whitespace&amp;maxHits=20"</span>).
          to(<span class="code-quote">"direct:next"</span>);
                
       from(<span class="code-quote">"direct:next"</span>).process(<span class="code-keyword">new</span> Processor() {
          <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
             Hits hits = exchange.getIn().getBody(Hits.class);
             printResults(hits);
          }

          <span class="code-keyword">private</span> void printResults(Hits hits) {
              LOG.debug(<span class="code-quote">"<span class="code-object">Number</span> of hits: "</span> + hits.getNumberOfHits());
              <span class="code-keyword">for</span> (<span class="code-object">int</span> i = 0; i &lt; hits.getNumberOfHits(); i++) {
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Index Location:"</span> + hits.getHit().get(i).getHitLocation());
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Score:"</span> + hits.getHit().get(i).getScore());
                 LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Data:"</span> + hits.getHit().get(i).getData());
              }
           }
       }).to(<span class="code-quote">"mock:searchResult"</span>);
   }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Example3%3APerformingsearchesusingaQueryProcessor"></a>Example 3: Performing searches using a Query Processor </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {            
        <span class="code-keyword">try</span> {
            from(<span class="code-quote">"direct:start"</span>).
                setHeader(<span class="code-quote">"QUERY"</span>, constant(<span class="code-quote">"Rodney Dangerfield"</span>)).
                process(<span class="code-keyword">new</span> LuceneQueryProcessor(<span class="code-quote">"target/stdindexDir"</span>, analyzer, <span class="code-keyword">null</span>, 20)).
                to(<span class="code-quote">"direct:next"</span>);
        } <span class="code-keyword">catch</span> (Exception e) {
            e.printStackTrace();
        }
                
        from(<span class="code-quote">"direct:next"</span>).process(<span class="code-keyword">new</span> Processor() {
            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                Hits hits = exchange.getIn().getBody(Hits.class);
                printResults(hits);
            }
                    
            <span class="code-keyword">private</span> void printResults(Hits hits) {
                LOG.debug(<span class="code-quote">"<span class="code-object">Number</span> of hits: "</span> + hits.getNumberOfHits());
                <span class="code-keyword">for</span> (<span class="code-object">int</span> i = 0; i &lt; hits.getNumberOfHits(); i++) {
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Index Location:"</span> + hits.getHit().get(i).getHitLocation());
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Score:"</span> + hits.getHit().get(i).getScore());
                    LOG.debug(<span class="code-quote">"Hit "</span> + i + <span class="code-quote">" Data:"</span> + hits.getHit().get(i).getData());
                }
            }
       }).to(<span class="code-quote">"mock:searchResult"</span>);
   }
};
</pre>
</div></div>
<h2><a name="BookComponentAppendix-MailComponent"></a>Mail Component</h2>

<p>The mail component provides access to Email via Spring's Mail support and the underlying JavaMail system.</p>

<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-mail<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='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Geronimo mail .jar</b><br />We have discovered that the geronimo mail <tt>.jar</tt> (v1.6) has a bug when polling mails with attachments. It cannot correctly identify the <tt>Content-Type</tt>. So, if you attach a <tt>.jpeg</tt> file to a mail and you poll it, the <tt>Content-Type</tt> is resolved as <tt>text/plain</tt> and not as <tt>image/jpeg</tt>. For that reason, we have added an <tt>org.apache.camel.component.ContentTypeResolver</tt> SPI interface which enables you to provide your own implementation and fix this bug by returning the correct Mime type based on the file name. So if the file name ends with <tt>jpeg/jpg</tt>, you can return <tt>image/jpeg</tt>.

<p>You can set your custom resolver on the <tt>MailComponent</tt> instance or on the <tt>MailEndpoint</tt> instance. This feature is added in Camel 1.6.2/2.0.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>POP3 or IMAP</b><br />POP3 has some limitations and end users are encouraged to use IMAP if possible.</td></tr></table></div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using mock-mail for testing</b><br />You can use a mock framework for unit testing, which allows you to test without the need for a real mail server. However you should remember to not include the mock-mail when you go into production or other environments where you need to send mails to a real mail server. Just the presence of the mock-javamail.jar on the classpath means that it will kick in and avoid sending the mails.</td></tr></table></div>

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

<p>Mail endpoints can have one of the following URI formats (for the protocols, SMTP, POP3, or IMAP, respectively):</p>

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

<p>The mail component also supports secure variants of these protocols (layered over SSL). You can enable the secure protocols by adding <tt>s</tt> to the scheme:</p>

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

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

<h4><a name="BookComponentAppendix-Sampleendpoints"></a>Sample endpoints</h4>

<p>Typically, you specify a URI with login credentials as follows (taking SMTP as an example):</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//[username@]host[:port][?password=somepwd]</span>
</pre>
</div></div>

<p>Alternatively, it is possible to specify both the user name and the password as query options:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//host[:port]?password=somepwd&amp;username=someuser</span>
</pre>
</div></div>

<p>For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//mycompany.mailserver:30?password=tiger&amp;username=scott</span>
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Defaultports"></a><a name="BookComponentAppendix-DefaultPorts"></a>Default ports</h4>
<p>As of Camel 1.4, default port numbers are supported. If the port number is omitted, Camel determines the port number to use based on the protocol.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Protocol </th>
<th class='confluenceTh'> Default Port Number </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMTP</tt> </td>
<td class='confluenceTd'> <tt>25</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMTPS</tt> </td>
<td class='confluenceTd'> <tt>465</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3</tt> </td>
<td class='confluenceTd'> <tt>110</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3S</tt> </td>
<td class='confluenceTd'> <tt>995</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAP</tt> </td>
<td class='confluenceTd'> <tt>143</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAPS</tt> </td>
<td class='confluenceTd'> <tt>993</tt> </td>
</tr>
</tbody></table>
</div>


<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>host</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The host name or IP address to connect to. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>port</tt> </td>
<td class='confluenceTd'> See <a href="#BookComponentAppendix-DefaultPorts">DefaultPorts</a> </td>
<td class='confluenceTd'> The TCP port number to connect on. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The user name on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUriScheme</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>false</tt>, Camel uses the scheme to determine the transport protocol (POP, IMAP, SMTP etc.) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultEncoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default encoding to use for Mime Messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentType</tt> </td>
<td class='confluenceTd'> <tt>text/plain</tt> </td>
<td class='confluenceTd'> New option in <b>Camel 1.5</b>. The mail message content type. Use <tt>text/html</tt> for HTML mails. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>folderName</tt> </td>
<td class='confluenceTd'> <tt>INBOX</tt> </td>
<td class='confluenceTd'> The folder to poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b> Use the <tt>to</tt> option instead. The <tt>TO</tt> recipients (receivers of the email). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>to</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the TO recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the CC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>BCC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the BCC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>from</tt> </td>
<td class='confluenceTd'> <tt>camel@localhost</tt> </td>
<td class='confluenceTd'> The FROM email address. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subject</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> As of <b>Camel 2.3</b>, the Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deleteProcessedMessages</tt> </td>
<td class='confluenceTd'> <tt>true</tt>/<tt>false</tt> </td>
<td class='confluenceTd'> Deletes the messages after they have been processed. This is done by setting the <tt>DELETED</tt> flag on the mail message. If <tt>false</tt>, the <tt>SEEN</tt> flag is set instead. As of <b>Camel 1.5</b>, the default setting is <tt>false</tt>. This option is named <tt>delete</tt> in Camel 2.0 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delete</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Deletes the messages after they have been processed. This is done by setting the <tt>DELETED</tt> flag on the mail message. If <tt>false</tt>, the <tt>SEEN</tt> flag is set instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>processOnlyUnseenMessages</tt> </td>
<td class='confluenceTd'> <tt>false</tt>/<tt>true</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, it is possible to configure a consumer endpoint so that it processes only unseen messages (that is, new messages) or all messages. Note that Camel always skips deleted messages. Setting this option to <tt>true</tt> will filter to only unseen messages. As of Camel 1.5, the default setting is <tt>true</tt>. POP3 does not support the <tt>SEEN</tt> flag, so this option is not supported in POP3; use IMAP instead. This option is named <tt>unseen</tt> in Camel 2.0 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>unseen</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Is used to fetch only unseen messages (that is, new messages). Note that POP3 does not support the <tt>SEEN</tt> flag; use IMAP instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fetchSize</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, this option sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server, if a mailbox folder contains a lot of messages. Default value of <tt>-1</tt> means no fetch size and all messages will be consumed. Setting the value to 0 is a special corner case, where Camel will not consume any messages at all. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alternateBodyHeader</tt> </td>
<td class='confluenceTd'> <tt>mail_alternateBody</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.1</b>: Specifies the key to an IN message header that contains an alternative email body. For example, if you send emails in <tt>text/html</tt> format and want to provide an alternative mail body for non-HTML email clients, set the alternative mail body with this key as a header. In Camel 2.0, this option has been renamed to <tt>alternativeBodyHeader</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alternativeBodyHeader</tt> </td>
<td class='confluenceTd'> <tt>CamelMailAlternativeBody</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0</b>: Specifies the key to an IN message header that contains an alternative email body. For example, if you send emails in <tt>text/html</tt> format and want to provide an alternative mail body for non-HTML email clients, set the alternative mail body with this key as a header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>debugMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, it is possible to enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to <tt>System.out</tt> by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the connection timeout can be configured in milliseconds. Default is 30 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before the polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> As of <b>Camel 1.4</b>, the default consumer delay is now 60 seconds. Camel will therefore only poll the mailbox once a minute to avoid overloading the mail server. The default value in Camel 1.3 is 500 milliseconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.useFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use a fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mail.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of <b>Camel 2.0</b>, you can set any <a href="http://java.sun.com/products/javamail/javadocs/index.html" class="external-link" rel="nofollow">additional java mail properties</a>. For instance if you want to set a special property when using POP3 you can now provide the option directly in the URI such as: <tt>mail.pop3.forgettopheaders=true</tt>. You can set multiple such options, for example: <tt>mail.pop3.forgettopheaders=true&amp;mail.mime.encodefilename=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid downloading thousands of files when the server starts up. Set a value of 0 or negative to disable this option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javaMailSender</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies a pluggable <tt>org.springframework.mail.javamail.JavaMailSender</tt> instance in order to use a custom email implementation. If none provided, Camel uses the default, <tt>org.springframework.mail.javamail.JavaMailSenderImpl</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUnsupportedCharset</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then <tt>charset=XXX</tt> (where <tt>XXX</tt> represents the unsupported charset) is removed from the <tt>content-type</tt> and it relies on the platform default instead. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-SSLsupport"></a>SSL support</h3>
<p>The underlying mail framework is responsible for providing SSL support. Camel uses SUN JavaMail, which only trusts certificates issued by well known Certificate Authorities. So if you issue your own certificate, you have to import it into the local Java keystore file (see <tt>SSLNOTES.txt</tt> in JavaMail for details).</p>

<h3><a name="BookComponentAppendix-DefaultschangedinCamel1.4"></a>Defaults changed in Camel 1.4</h3>
<p>As of Camel 1.4 the default consumer delay is now 60 seconds. Camel will therefore only poll the mailbox once a minute to avoid overloading the mail server. The default value in Camel 1.3 is 500 milliseconds.</p>

<h3><a name="BookComponentAppendix-DefaultschangedinCamel1.5"></a>Defaults changed in Camel 1.5</h3>
<p>In Camel 1.5 the following default options have changed:</p>
<ul class="alternate" type="square">
	<li><tt>deleteProcessedMessages</tt> is now <b>false</b>, as we felt Camel should not delete mails on the mail server by default.</li>
	<li><tt>processOnlyUnseenMessages</tt> is now <b>true</b>, as we felt Camel should only poll new mails by default.</li>
</ul>


<h3><a name="BookComponentAppendix-MailMessageContent"></a>Mail Message Content</h3>
<p>Camel uses the message exchange's IN body as the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> text content. The body is converted to <tt>String.class</tt>.</p>

<p>Camel copies all of the exchange's IN headers to the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> headers. </p>

<p>The subject of the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> can be configured using a header property on the IN message. The code below demonstrates this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:a"</span>).setHeader(<span class="code-quote">"subject"</span>, constant(subject)).to(<span class="code-quote">"smtp:<span class="code-comment">//james2@localhost"</span>);</span>
</pre>
</div></div>

<p>The same applies for other MimeMessage headers such as recipients, so you can use a header property as <tt>To</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Map&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">"To"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"jstrachan@apache.org"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel rocks"</span>);

<span class="code-object">String</span> body = <span class="code-quote">"Hello Claus.\nYes it does.\n\nRegards James."</span>;
template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//davsclaus@apache.org"</span>, body, map);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Headerstakeprecedenceoverpreconfiguredrecipients"></a>Headers take precedence over pre-configured recipients</h3>
<p>From Camel 1.5 onwards, the recipients specified in the message headers always take precedence over recipients pre-configured in the endpoint URI. The idea is that if you provide any recipients in the message headers, that is what you get. The recipients pre-configured in the endpoint URI are treated as a fallback.</p>

<p>In the sample code below, the email message is sent to <tt>davsclaus@apache.org</tt>, because it takes precedence over the pre-configured recipient, <tt>info@mycompany.com</tt>. Any <tt>CC</tt> and <tt>BCC</tt> settings in the endpoint URI are also ignored and those recipients will not receive any mail. The choice between headers and pre-configured settings is all or nothing: the mail component <em>either</em> takes the recipients exclusively from the headers or exclusively from the pre-configured settings. It is not possible to mix and match headers and pre-configured settings.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);

        template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//admin@localhost?to=info@mycompany.com"</span>, <span class="code-quote">"Hello World"</span>, headers);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Multiplerecipientsforeasierconfiguration"></a>Multiple recipients for easier configuration</h3>
<p>As of Camel 1.5, it is possible to set multiple recipients using a comma-separated or a semicolon-separated list. This applies both to header settings and to settings in an endpoint URI. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org ; jstrachan@apache.org ; ningjiang@apache.org"</span>);
</pre>
</div></div>

<p>The preceding example uses a semicolon, <tt>;</tt>, as the separator character.</p>

<h3><a name="BookComponentAppendix-Settingsendernameandemail"></a>Setting sender name and email</h3>
<p>You can specify recipients in the format, <tt>name &lt;email&gt;</tt>, to include both the name and the email address of the recipient.</p>

<p>For example, you define the following headers on the a <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Map headers = <span class="code-keyword">new</span> HashMap();
map.put(<span class="code-quote">"To"</span>, <span class="code-quote">"Claus Ibsen &lt;davsclaus@apache.org&gt;"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"James Strachan &lt;jstrachan@apache.org&gt;"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel is cool"</span>);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SUNJavaMail"></a>SUN JavaMail </h3>
<p><a href="http://java.sun.com/products/javamail/" class="external-link" rel="nofollow">SUN JavaMail</a> is used under the hood for consuming and producing mails. <br/>
We encourage end-users to consult these references when using either POP3 or IMAP protocol. Note particularly that POP3 has a much more limited set of features than IMAP.</p>
<ul class="alternate" type="square">
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/pop3/package-summary.html" class="external-link" rel="nofollow">SUN POP3 API</a></li>
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html" class="external-link" rel="nofollow">SUN IMAP API</a></li>
	<li>And generally about the <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/Flags.html" class="external-link" rel="nofollow">MAIL Flags</a></li>
</ul>


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

<p>We start with a simple route that sends the messages received from a JMS queue as emails. The email account is the <tt>admin</tt> account on <tt>mymailserver.com</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:<span class="code-comment">//queue:subscription"</span>).to(<span class="code-quote">"smtp://admin@mymailserver.com?password=secret"</span>);</span>
</pre>
</div></div>

<p>In the next sample, we poll a mailbox for new emails once every minute. Notice that we use the special <tt>consumer</tt> option for setting the poll interval, <tt>consumer.delay</tt>, as 60000 milliseconds = 60 seconds.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imap:<span class="code-comment">//admin@mymailserver.com?password=secret&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).to(<span class="code-quote">"seda://mails"</span>);</span>
</pre>
</div></div>

<p>In this sample we want to send a mail to multiple recipients. This feature was introduced in camel 1.4:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// all the recipients of <span class="code-keyword">this</span> mail are:
</span><span class="code-comment">// To: camel@riders.org , easy@riders.org
</span><span class="code-comment">// CC: me@you.org
</span><span class="code-comment">// BCC: someone@somewhere.org
</span><span class="code-object">String</span> recipients = <span class="code-quote">"&amp;To=camel@riders.org,easy@riders.org&amp;CC=me@you.org&amp;BCC=someone@somewhere.org"</span>;

from(<span class="code-quote">"direct:a"</span>).to(<span class="code-quote">"smtp:<span class="code-comment">//you@mymailserver.com?password=secret&amp;From=you@apache.org"</span> + recipients);</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Sendingmailwithattachmentsample"></a>Sending mail with attachment sample</h3>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Attachments are not support by all Camel components</b><br />The <em>Attachments API</em> is based on the Java Activation Framework and is generally only used by the Mail API. Since many of the other Camel components do not support attachments, the attachments could potentially be lost as they propagate along the route. The rule of thumb, therefore, is to add attachments just before sending a message to the mail endpoint.</td></tr></table></div>

<p>The mail component supports attachments, which is a feature that was introduced in Camel 1.4. In the sample below, we send a mail message containing a plain text message with a logo file attachment.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// create an exchange with a normal body and attachment to be produced as email
</span>Endpoint endpoint = context.getEndpoint(<span class="code-quote">"smtp:<span class="code-comment">//james@mymailserver.com?password=secret"</span>);
</span>
<span class="code-comment">// create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
</span>Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
in.setBody(<span class="code-quote">"Hello World"</span>);
in.addAttachment(<span class="code-quote">"logo.jpeg"</span>, <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> FileDataSource(<span class="code-quote">"src/test/data/logo.jpeg"</span>)));

<span class="code-comment">// create a producer that can produce the exchange (= send the mail)
</span>Producer producer = endpoint.createProducer();
<span class="code-comment">// start the producer
</span>producer.start();
<span class="code-comment">// and let it go (processes the exchange by sending the email)
</span>producer.process(exchange);

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

<h3><a name="BookComponentAppendix-SSLsample"></a>SSL sample</h3>

<p>In this sample, we want to poll our Google mail inbox for mails. To download mail onto a local mail client, Google mail requires you to enable and configure SSL. This is done by logging into your Google mail account and changing your settings to allow IMAP access. Google have extensive documentation on how to do this.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;deleteProcessedMessages=<span class="code-keyword">false</span>&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).to(<span class="code-quote">"log:newmail"</span>);
</pre>
</div></div>

<p>The preceding route polls the Google mail inbox for new mails once every minute and logs the received messages to the <tt>newmail</tt> logger category.<br/>
Running the sample with <tt>DEBUG</tt> logging enabled, we can monitor the progress in the logs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-05-08 06:32:09,640 DEBUG MailConsumer - Connecting to MailStore imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX
</span>2008-05-08 06:32:11,203 DEBUG MailConsumer - Polling mailfolder: imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX 
</span>2008-05-08 06:32:11,640 DEBUG MailConsumer - Fetching 1 messages. Total 1 messages. 
2008-05-08 06:32:12,171 DEBUG MailConsumer - Processing message: messageNumber=[332], from=[James Bond &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[... 
2008-05-08 06:32:12,187 INFO  newmail - Exchange[MailMessage: messageNumber=[332], from=[James Bond &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[...
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Consumingmailswithattachmentsample"></a>Consuming mails with attachment sample</h3>
<p>In this sample we poll a mailbox and store all attachments from the mails as files. First, we define a route to poll the mailbox. As this sample is based on google mail, it uses the same route as shown in the SSL sample:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;deleteProcessedMessages=<span class="code-keyword">false</span>&amp;processOnlyUnseenMessages=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).process(<span class="code-keyword">new</span> MyMailProcessor());
</pre>
</div></div>

<p>Instead of logging the mail we use a processor where we can process the mail from java code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// the API is a bit clunky so we need to loop
</span>        Map&lt;<span class="code-object">String</span>, DataHandler&gt; attachments = exchange.getIn().getAttachments();
        <span class="code-keyword">if</span> (attachments.size() &gt; 0) {
            <span class="code-keyword">for</span> (<span class="code-object">String</span> name : attachments.keySet()) {
                DataHandler dh = attachments.get(name);
                <span class="code-comment">// get the file name
</span>                <span class="code-object">String</span> filename = dh.getName();

                <span class="code-comment">// get the content and convert it to <span class="code-object">byte</span>[]
</span>                 <span class="code-object">byte</span>[] data = exchange.getContext().getTypeConverter().convertTo(<span class="code-object">byte</span>[].class, dh.getInputStream());

                <span class="code-comment">// write the data to a file
</span>                FileOutputStream out = <span class="code-keyword">new</span> FileOutputStream(filename);
                out.write(data);
                out.flush();
                out.close();
            }
        }
   }
</pre>
</div></div>
<p>As you can see the API to handle attachments is a bit clunky but it's there so you can get the <tt>javax.activation.DataHandler</tt> so you can handle the attachments using standard API.        </p>

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

<h2><a name="BookComponentAppendix-MINAComponent"></a>MINA Component</h2>

<p>The <b>mina:</b> component is a transport for working with <a href="http://mina.apache.org/" class="external-link" rel="nofollow">Apache MINA</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-mina<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">
mina:tcp:<span class="code-comment">//hostname[:port][?options]
</span>mina:udp:<span class="code-comment">//hostname[:port][?options]
</span>mina:vm:<span class="code-comment">//hostname[:port][?options]</span>
</pre>
</div></div>
<p>From Camel 1.3 onwards you can specify a codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> using the <b>codec</b> option. If you are using TCP and no codec is specified then the <tt>textline</tt> flag is used to determine if text line based codec or object serialization should be used instead. By default the object serialization is used.</p>

<p>For UDP if no codec is specified the default uses a basic <tt>ByteBuffer</tt> based codec.</p>

<p>The VM protocol is used as a direct forwarding mechanism in the same JVM. See the <a href="http://mina.apache.org/report/1.1/apidocs/org/apache/mina/transport/vmpipe/package-summary.html" class="external-link" rel="nofollow">MINA VM-Pipe API documentation</a> for details.</p>

<p>A Mina producer has a default timeout value of 30 seconds, while it waits for a response from the remote server.</p>

<p>In normal use, <tt>camel-mina</tt> only supports marshalling the body content&mdash;message headers and exchange properties are not sent.<br/>
However, the option, <b>transferExchange</b>, does allow you to transfer the exchange itself over the wire. See options below.</p>

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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<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>codec</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of 1.3, you can refer to a named <tt>ProtocolCodecFactory</tt> instance in your <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> such as your Spring <tt>ApplicationContext</tt>, which is then used for the marshalling. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>codec</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> You must use the <tt>&#35;</tt> notation to look up your codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. For example, use <tt>#myCodec</tt> to look up a bean with the <tt>id</tt> value, <tt>myCodec</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Whether or not to disconnect(close) from Mina session right after use. Can be used for both consumer and producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Only used for TCP. If no codec is specified, you can use this flag in 1.3 or later to indicate a text line based codec; if not specified or the value is <tt>false</tt>, then Object Serialization is assumed over TCP. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textlineDelimiter</tt> </td>
<td class='confluenceTd'> <tt>DEFAULT</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.0/2.0</b> Only used for TCP and if <b>textline=true</b>. Sets the text line delimiter to use. Possible values are: <tt>DEFAULT</tt>, <tt>AUTO</tt>, <tt>WINDOWS</tt>, <tt>UNIX</tt> or <tt>MAC</tt>. If none provided, Camel will use <tt>DEFAULT</tt>. This delimiter is used to mark the end of text. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sync</tt> </td>
<td class='confluenceTd'> <tt>false</tt>/<tt>true</tt> </td>
<td class='confluenceTd'> As of 1.3, you can configure the exchange pattern to be either InOnly (default) or InOut. Setting <tt>sync=true</tt> means a synchronous exchange (InOut), where the client can read the response from MINA (the exchange Out message). The default value has changed in Camel 1.5 to <tt>true</tt>. In older releases, the default value is <tt>false</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lazySessionCreation</tt> </td>
<td class='confluenceTd'> <em>See description</em> </td>
<td class='confluenceTd'> As of 1.3, sessions can be lazily created to avoid exceptions, if the remote server is not up and running when the Camel producer is started. From Camel 2.0 onwards, the default is <tt>true</tt>. In Camel 1.x, the default is <tt>false</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> As of 1.3, you can configure the timeout that specifies how long to wait for a response from a remote server. The timeout unit is in milliseconds, so 60000 is 60 seconds. The timeout is only used for Mina producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <em>JVM Default</em> </td>
<td class='confluenceTd'> As of 1.3, you can configure the encoding (a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" class="external-link" rel="nofollow">charset name</a>) to use for the TCP textline codec and the UDP protocol. If not provided, Camel will use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()" class="external-link" rel="nofollow">JVM default Charset</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Only used for TCP. As of 1.3, you can transfer the exchange over the wire instead of just the body. The following fields are transferred: In body, Out body, fault body, In headers, Out headers, fault headers, exchange properties, exchange exception. This requires that the objects are <em>serializable</em>. Camel will exclude any non-serializable objects and log it at <tt>WARN</tt> level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>minaLogger</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> As of 1.3, you can enable the Apache MINA logging filter. Apache MINA uses <tt>slf4j</tt> logging at <tt>INFO</tt> level to log all input and output. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> As of 2.0, you can set a list of <a href="http://mina.apache.org/iofilter.html" class="external-link" rel="nofollow">Mina IoFilters</a> to register. The <tt>filters</tt> value must be one of the following: 
<ul>
	<li><b>Camel 2.2:</b> comma-separated list of bean references (e.g. <tt>#filterBean1,#filterBean2</tt>) where each bean must be of type <tt>org.apache.mina.common.IoFilter</tt>.</li>
	<li><b>Camel 2.0:</b> a reference to a bean of type <tt>List&lt;org.apache.mina.common.IoFilter&gt;</tt>.</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoderMaxLineLength</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of 2.1, you can set the textline protocol encoder max line length. By default the default value of Mina itself is used which are <tt>Integer.MAX_VALUE</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decorderMaxLineLength</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> As of 2.1, you can set the textline protocol decoder max line length. By default the default value of Mina itself is used which are 1024. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>producerPoolSize</tt> </td>
<td class='confluenceTd'> 16 </td>
<td class='confluenceTd'> <b>1.6.2 (only in 1.6.x)</b>: The TCP producer is now thread safe and supports concurrency much better. This option allows you to configure the number of threads in its thread pool for concurrent producers. <b>Note:</b> Camel 2.0 have a pooled service which ensured it was already thread safe and supported concurrency already. So this is a special patch for 1.6.x. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowDefaultCodec</tt> </td>
<td class='confluenceTd'><tt>true</tt></td>
<td class='confluenceTd'> The mina component installs a default codec if both, <tt>codec</tt> is <tt>null</tt> and <tt>textline</tt> is <tt>false</tt>. Setting <tt>allowDefaultCodec</tt> to <tt>false</tt> prevents the mina component from installing a default codec as the first element in the filter chain. This is useful in scenarios where another filter must be the first in the filter chain, like the SSL filter.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnectOnNoReply</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If sync is enabled then this option dictates MinaConsumer if it should disconnect where there is no reply to send back. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>noReplyLogLevel</tt> </td>
<td class='confluenceTd'> <tt>WARN</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If sync is enabled this option dictates MinaConsumer which logging level to use when logging a there is no reply to send back. Values are: <tt>FATAL, ERROR, INFO, DEBUG, OFF</tt>. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-Defaultbehaviorchanged"></a>Default behavior changed</h3>
<p>In Camel 2.0 the <b>codec</b> option must use <tt>&#35;</tt> notation for lookup of the codec bean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.<br/>
In Camel 2.0 the <b>lazySessionCreation</b> option now defaults to <tt>true</tt>.</p>

<p>In Camel 1.5 the <tt>sync</tt> option has changed its default value from <tt>false</tt> to <tt>true</tt>, as we felt it was confusing for end-users when they used <a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a> to call remote servers and Camel wouldn't wait for the response.</p>

<p>In Camel 1.4 or later <tt>codec=textline</tt> is no longer supported. Use the <tt>textline=true</tt> option instead.</p>

<h3><a name="BookComponentAppendix-Usingacustomcodec"></a>Using a custom codec</h3>
<p>See the <a href="http://mina.apache.org/tutorial-on-protocolcodecfilter.html" class="external-link" rel="nofollow">Mina documentation</a> how to write your own codec. To use your custom codec with <tt>camel-mina</tt>, you should register your codec in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>; for example, by creating a bean in the Spring XML file. Then use the <tt>codec</tt> option to specify the bean ID of your codec. See <a href="/confluence/display/CAMEL/HL7" title="HL7">HL7</a> that has a custom codec.</p>

<h3><a name="BookComponentAppendix-Samplewithsync%3Dfalse"></a>Sample with sync=false</h3>

<p>In this sample, Camel exposes a service that listens for TCP connections on port 6200. We use the <b>textline</b> codec. In our route, we create a Mina consumer endpoint that listens on port 6200:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6200?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">false</span>"</span>).to(<span class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<p>As the sample is part of a unit test, we test it by sending some data to it on port 6200. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">MockEndpoint mock = getMockEndpoint(<span class="code-quote">"mock:result"</span>);
mock.expectedBodiesReceived(<span class="code-quote">"Hello World"</span>);

template.sendBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:6200?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">false</span>"</span>, <span class="code-quote">"Hello World"</span>);
</span>
assertMockEndpointsSatisfied();
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Samplewithsync%3Dtrue"></a>Sample with sync=true</h3>

<p>In the next sample, we have a more common use case where we expose a TCP service on port 6201 also use the textline codec. However, this time we want to return a response, so we set the <tt>sync</tt> option to <tt>true</tt> on the consumer. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:9201?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">true</span>"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
        exchange.getOut().setBody(<span class="code-quote">"Bye "</span> + body);
    }
});
</pre>
</div></div>

<p>Then we test the sample by sending some data and retrieving the response using the <tt>template.requestBody()</tt> method. As we know the response is a <tt>String</tt>, we cast it to <tt>String</tt> and can assert that the response is, in fact, something we have dynamically set in our processor code logic.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-object">String</span> response = (<span class="code-object">String</span>)template.requestBody(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:9201?textline=<span class="code-keyword">true</span>&amp;sync=<span class="code-keyword">true</span>"</span>, <span class="code-quote">"World"</span>);
</span>assertEquals(<span class="code-quote">"Bye World"</span>, response);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-SamplewithSpringDSL"></a>Sample with Spring DSL</h3>
<p>Spring DSL can, of course, also be used for <a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a>. In the sample below we expose a TCP server on port 5555:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;route&gt;</span>
     <span class="code-tag">&lt;from uri=<span class="code-quote">"mina:tcp://localhost:5555?textline=true"</span>/&gt;</span>
     <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myTCPOrderHandler"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>In the route above, we expose a TCP server on port 5555 using the textline codec. We let the Spring bean with ID, <tt>myTCPOrderHandler</tt>, handle the request and return a reply. For instance, the handler bean could be implemented as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> <span class="code-object">String</span> handleOrder(<span class="code-object">String</span> payload) {
        ...
        <span class="code-keyword">return</span> <span class="code-quote">"Order: OK"</span>
   }
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ConfiguringMinaendpointsusingSpringbeanstyle"></a>Configuring Mina endpoints using Spring bean style</h3>
<p><b>Available as of Camel 2.0</b></p>

<p>Configuration of Mina endpoints is now possible using regular Spring bean style configuration in the Spring DSL.</p>

<p>However, in the underlying Apache Mina toolkit, it is relatively difficult to set up the acceptor and the connector, because you can <em>not</em> use simple setters. To resolve this difficulty, we leverage the <tt>MinaComponent</tt> as a Spring factory bean to configure this for us. If you really need to configure this yourself, there are setters on the <tt>MinaEndpoint</tt> to set these when needed.</p>

<p>The sample below shows the factory approach:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
     as a factory bean to create our endpoint, this is the easiest to do --&gt;
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaFactory"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaComponent"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- we must provide a camel context so we refer to it by its id --&gt;</span></span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myCamel"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

&lt;!-- This is our mina endpoint configured with spring, we will use the factory above
     to create it for us. The goal is to invoke the createEndpoint method with the
     mina configuration parameter we defined using the constructor-arg option --&gt;
&lt;bean id=<span class="code-quote">"myMinaEndpoint"</span>
      factory-bean=<span class="code-quote">"myMinaFactory"</span>
      factory-method=<span class="code-quote">"createEndpoint"</span>&gt;
    <span class="code-tag"><span class="code-comment">&lt;!-- and here we can pass it our configuration --&gt;</span></span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myMinaConfig"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- this is our mina configuration with plain properties --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaConfig"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaConfiguration"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"protocol"</span> value=<span class="code-quote">"tcp"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"host"</span> value=<span class="code-quote">"localhost"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"port"</span> value=<span class="code-quote">"1234"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sync"</span> value=<span class="code-quote">"false"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>And then we can refer to our endpoint directly in the route, as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- here we route from or mina endpoint we have defined above --&gt;</span></span>
    <span class="code-tag">&lt;from ref=<span class="code-quote">"myMinaEndpoint"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="BookComponentAppendix-ClosingSessionWhenComplete"></a>Closing Session When Complete</h3>
<p><b>Available as of Camel 1.6.1</b></p>

<p>When acting as a server you sometimes want to close the session when, for example, a client conversion is finished. To instruct Camel to close the session, you should add a header with the key <tt>CamelMinaCloseSessionWhenComplete</tt> set to a boolean <tt>true</tt> value.</p>

<p>For instance, the example below will close the session after it has written the <tt>bye</tt> message back to the client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        from(<span class="code-quote">"mina:tcp:<span class="code-comment">//localhost:8080?sync=<span class="code-keyword">true</span>&amp;textline=<span class="code-keyword">true</span>"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
                exchange.getOut().setBody(<span class="code-quote">"Bye "</span> + body);
                exchange.getOut().setHeader(MinaConsumer.HEADER_CLOSE_SESSION_WHEN_COMPLETE, <span class="code-keyword">true</span>);
            }
        });
</pre>
</div></div>

<h3><a name="BookComponentAppendix-GettheIoSessionformessage"></a>Get the IoSession for message</h3>
<p><b>Available since Camel 2.1</b><br/>
You can get the IoSession from the message header with this key MinaEndpoint.HEADER_MINA_IOSESSION, and also get the local host address with the key MinaEndpoint.HEADER_LOCAL_ADDRESS and remote host address with the key MinaEndpoint.HEADER_REMOTE_ADDRESS.</p>

<h3><a name="BookComponentAppendix-ConfiguringMinafilters"></a>Configuring Mina filters</h3>
<p><b>Available since Camel 2.0</b></p>

<p>Filters permit you to use some Mina Filters, such as <tt>SslFilter</tt>. You can also implement some customized filters. Please note that <tt>codec</tt> and <tt>logger</tt> are also implemented as Mina filters of type, <tt>IoFilter</tt>. Any filters you may define are appended to the end of the filter chain; that is, after <tt>codec</tt> and <tt>logger</tt>.</p>

<p>For instance, the example below will send a keep-alive message after 10 seconds of inactivity:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class KeepAliveFilter <span class="code-keyword">extends</span> IoFilterAdapter {
    @Override
    <span class="code-keyword">public</span> void sessionCreated(NextFilter nextFilter, IoSession session)
            <span class="code-keyword">throws</span> Exception {
        session.setIdleTime(IdleStatus.BOTH_IDLE, 10);

        nextFilter.sessionCreated(session);
    }

    @Override
    <span class="code-keyword">public</span> void sessionIdle(NextFilter nextFilter, IoSession session,
            IdleStatus status) <span class="code-keyword">throws</span> Exception {
        session.write(<span class="code-quote">"NOOP"</span>); <span class="code-comment">// NOOP is a FTP command <span class="code-keyword">for</span> keep alive
</span>        nextFilter.sessionIdle(session, status);
    }
}
</pre>
</div></div>

<p>As Camel Mina may use a request-reply scheme, the endpoint as a client would like to drop some message, such as greeting when the connection is established. For example, when you connect to an FTP server, you will get a <tt>220</tt> message with a greeting (<tt>220 Welcome to Pure-FTPd</tt>). If you don't drop the message, your request-reply scheme will be broken.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class DropGreetingFilter <span class="code-keyword">extends</span> IoFilterAdapter {
 
    @Override
    <span class="code-keyword">public</span> void messageReceived(NextFilter nextFilter, IoSession session,
            <span class="code-object">Object</span> message) <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">if</span> (message <span class="code-keyword">instanceof</span> <span class="code-object">String</span>) {
            <span class="code-object">String</span> ftpMessage = (<span class="code-object">String</span>) message;
            <span class="code-comment">// <span class="code-quote">"220"</span> is given as greeting. <span class="code-quote">"200 Zzz"</span> is given as a response to <span class="code-quote">"NOOP"</span> (keep alive)
</span>            <span class="code-keyword">if</span> (ftpMessage.startsWith(<span class="code-quote">"220"</span>) || or ftpMessage.startsWith(<span class="code-quote">"200 Zzz"</span>)) {
                <span class="code-comment">// Dropping greeting
</span>                <span class="code-keyword">return</span>;
            }
        }
        nextFilter.messageReceived(session, message);
    }
}
</pre>
</div></div>

<p>Then, you can configure your endpoint using Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaFactory"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaComponent"</span>&gt;</span>
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"camelContext"</span> /&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
    
&lt;bean id=<span class="code-quote">"myMinaEndpoint"</span>
      factory-bean=<span class="code-quote">"myMinaFactory"</span>
      factory-method=<span class="code-quote">"createEndpoint"</span>&gt;
    <span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"myMinaConfig"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"myMinaConfig"</span> class=<span class="code-quote">"org.apache.camel.component.mina.MinaConfiguration"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"protocol"</span> value=<span class="code-quote">"tcp"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"host"</span> value=<span class="code-quote">"localhost"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"port"</span> value=<span class="code-quote">"2121"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"sync"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"minaLogger"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"filters"</span> ref=<span class="code-quote">"listFilters"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"listFilters"</span> class=<span class="code-quote">"java.util.ArrayList"</span> &gt;</span>
    <span class="code-tag">&lt;constructor-arg&gt;</span>
        <span class="code-tag">&lt;list value-type=<span class="code-quote">"org.apache.mina.common.IoFilter"</span>&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"com.example.KeepAliveFilter"</span>/&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"com.example.DropGreetingFilter"</span>/&gt;</span>
        <span class="code-tag">&lt;/list&gt;</span>
    <span class="code-tag">&lt;/constructor-arg&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

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

<ul class="alternate" type="square">
	<li><a href="http://camel.apache.org/netty.html" class="external-link" rel="nofollow">Camel Netty</a></li>
</ul>

<h2><a name="BookComponentAppendix-MockComponent"></a>Mock Component</h2>

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

<p>The Mock component provides a powerful declarative testing mechanism, which is similar to <a href="http://jmock.org" class="external-link" rel="nofollow">jMock</a> in that it allows declarative expectations to be created on any Mock endpoint before a test begins. Then the test is run, which typically fires messages to one or more endpoints, and finally the expectations can be asserted in a test case to ensure the system  worked as expected. </p>

<p>This allows you to test various things like:</p>
<ul>
	<li>The correct number of messages are received on each endpoint,</li>
	<li>The correct payloads are received, in the right order,</li>
	<li>Messages arrive on an endpoint in order, using some <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to create an order testing function,</li>
	<li>Messages arrive match some kind of <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> such as that specific headers have certain values, or that parts of the messages match some predicate, such as by evaluating an <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a> or <a href="/confluence/display/CAMEL/XQuery" title="XQuery">XQuery</a> <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>.</li>
</ul>


<p><b>Note</b> that there is also the <a href="/confluence/display/CAMEL/Test" title="Test">Test endpoint</a> which is a Mock endpoint, but which uses a second endpoint to provide the list of expected message bodies and automatically sets up the Mock endpoint assertions. In other words, it's a Mock endpoint that automatically sets up its assertions from some sample messages in a <a href="/confluence/display/CAMEL/File" title="File">File</a> or <a href="/confluence/display/CAMEL/JPA" title="JPA">database</a>, for example.</p>

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

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

<p>Where <b>someName</b> can be any string that uniquely identifies the endpoint.</p>

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

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

<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>reportGroup</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A size to use a <a href="/confluence/display/CAMEL/Log" title="Log">throughput logger</a> for reporting </td>
</tr>
</tbody></table>
</div>


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

<p>Here's a simple example of Mock endpoint in use. First, the endpoint is resolved on the context. Then we set an expectation, and then, after the test has run, we assert that our expectations have been met.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
MockEndpoint resultEndpoint = context.resolveEndpoint(<span class="code-quote">"mock:foo"</span>, MockEndpoint.class);

resultEndpoint.expectedMessageCount(2);

<span class="code-comment">// send some messages
</span>...

<span class="code-comment">// now lets <span class="code-keyword">assert</span> that the mock:foo endpoint received 2 messages
</span>resultEndpoint.assertIsSatisfied();
</pre>
</div></div>

<p>You typically always call the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#assertIsSatisfied()" class="external-link" rel="nofollow">assertIsSatisfied() method</a> to test that the expectations were met after running a test.</p>

<p>Camel will by default wait 20 seconds when the <tt>assertIsSatisfied()</tt> is invoked. This can be configured by setting the <tt>setResultWaitTime(millis)</tt> method.</p>

<h3><a name="BookComponentAppendix-Settingexpectations"></a>Setting expectations</h3>

<p>You can see from the javadoc of <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html" class="external-link" rel="nofollow">MockEndpoint</a> the various helper methods you can use to set expectations. The main methods are as follows: </p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Method </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedMessageCount(int)" class="external-link" rel="nofollow">expectedMessageCount(int)</a> </td>
<td class='confluenceTd'> To define the expected message count on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedMinimumMessageCount(int)" class="external-link" rel="nofollow">expectedMinimumMessageCount(int)</a> </td>
<td class='confluenceTd'> To define the minimum number of expected messages on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedBodiesReceived(java.lang.Object...)" class="external-link" rel="nofollow">expectedBodiesReceived(...)</a> </td>
<td class='confluenceTd'> To define the expected bodies that should be received (in order). </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectedHeaderReceived(java.lang.String,%20java.lang.String)" class="external-link" rel="nofollow">expectedHeaderReceived(...)</a> </td>
<td class='confluenceTd'> To define the expected header that should be received </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsAscending(org.apache.camel.Expression)" class="external-link" rel="nofollow">expectsAscending(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that messages are received in order, using the given <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to compare messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsDescending(org.apache.camel.Expression)" class="external-link" rel="nofollow">expectsDescending(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that messages are received in order, using the given <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to compare messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#expectsNoDuplicates(org.apache.camel.Expression)" class="external-link" rel="nofollow">expectsNoDuplicates(Expression)</a> </td>
<td class='confluenceTd'> To add an expectation that no duplicate messages are received; using an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to calculate a unique identifier for each message. This could be something like the <tt>JMSMessageID</tt> if using JMS, or some unique reference number within the message. </td>
</tr>
</tbody></table>
</div>


<p>Here's another example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
resultEndpoint.expectedBodiesReceived(<span class="code-quote">"firstMessageBody"</span>, <span class="code-quote">"secondMessageBody"</span>, <span class="code-quote">"thirdMessageBody"</span>);
</pre>
</div></div>

<h4><a name="BookComponentAppendix-Addingexpectationstospecificmessages"></a>Adding expectations to specific messages</h4>

<p>In addition, you can use the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#message(int)" class="external-link" rel="nofollow">message(int messageIndex)</a> method to add assertions about a specific message that is received.</p>

<p>For example, to add expectations of the headers or body of the first message (using zero-based indexing like <tt>java.util.List</tt>), you can use the following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
resultEndpoint.message(0).header(<span class="code-quote">"foo"</span>).isEqualTo(<span class="code-quote">"bar"</span>);
</pre>
</div></div>

<p>There are some examples of the Mock endpoint in use in the <a href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/" class="external-link" rel="nofollow">camel-core processor tests</a>.</p>

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

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

<h2><a name="BookComponentAppendix-MSVComponent"></a>MSV Component</h2>

<p>The MSV component performs XML validation of the message body using the <a href="https://msv.dev.java.net/" class="external-link" rel="nofollow">MSV Library</a> and any of the supported XML schema languages, such as <a href="http://www.w3.org/XML/Schema" class="external-link" rel="nofollow">XML Schema</a> or <a href="http://relaxng.org/" class="external-link" rel="nofollow">RelaxNG XML Syntax</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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-msv&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/Jing" title="Jing">Jing</a> component also supports <a href="http://relaxng.org/compact-tutorial-20030326.html" class="external-link" rel="nofollow">RelaxNG Compact Syntax</a></p>

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

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

<p>Where <b>someLocalOrRemoteResource</b> is some URL to a local resource on the classpath or a full URL to a remote resource or resource on the file system. For example</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
msv:org/foo/bar.rng
msv:file:../foo/bar.rng
msv:http:<span class="code-comment">//acme.com/cheese.rng</span>
</pre>
</div></div>

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

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<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>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether DOMSource/DOMResult or SaxSource/SaxResult should be used by the validator. <b>Note:</b> DOM must be used by the <a href="/confluence/display/CAMEL/MSV" title="MSV">MSV</a> component. </td>
</tr>
</tbody></table>
</div>



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

<p>The following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml" class="external-link" rel="nofollow">example</a> shows how to configure a route from endpoint <b>direct:start</b> which then goes to one of two endpoints, either <b>mock:valid</b> or <b>mock:invalid</b> based on whether or not the XML matches the given <a href="http://relaxng.org/" class="external-link" rel="nofollow">RelaxNG XML Schema</a> (which is supplied on the classpath).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;doTry&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"msv:org/apache/camel/component/validator/msv/schema.rng"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:valid"</span>/&gt;</span>

            <span class="code-tag">&lt;doCatch&gt;</span>
                <span class="code-tag">&lt;exception&gt;</span>org.apache.camel.ValidationException<span class="code-tag">&lt;/exception&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:invalid"</span>/&gt;</span>
            <span class="code-tag">&lt;/doCatch&gt;</span>
            <span class="code-tag">&lt;doFinally&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:finally"</span>/&gt;</span>
            <span class="code-tag">&lt;/doFinally&gt;</span>
        <span class="code-tag">&lt;/doTry&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

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

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

<p>The <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component allows you to send passive checks to <a href="http://nagios.org" class="external-link" rel="nofollow">Nagios</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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-nagios&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">
nagios:<span class="code-comment">//host[:port][?Options]</span>
</pre>
</div></div>

<p>Camel provides two abilities with the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component. You can send passive check messages by sending a message to its endpoint.<br/>
Camel also provides a <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">EventNotifer</a> which allows you to send notifications to Nagios.</p>

<h3><a name="BookComponentAppendix-Options"></a>Options</h3>
<div class="confluenceTableSmall"><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>host</tt> </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> This is the address of the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> host where checks should be send. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>port</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The port number of the host. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Password to be authenticated when sending checks to Nagios. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> 5000 </td>
<td class='confluenceTd'> Connection timeout in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> 5000 </td>
<td class='confluenceTd'> Sending timeout in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nagiosSettings</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To use an already configured <tt>com.googlecode.jsendnsca.core.NagiosSettings</tt> object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendSync</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether or not to use synchronous when sending a passive check. Setting it to <tt>false</tt> will allow Camel to continue routing the message and the passive check message will be send asynchronously. </td>
</tr>
</tbody></table>
</div>
</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>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosHostName</tt> </td>
<td class='confluenceTd'> This is the address of the <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> host where checks should be send. This header will override any existing hostname configured on the endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosLevel</tt> </td>
<td class='confluenceTd'> This is the severity level. You can use values <tt>CRITICAL, WARNING, OK</tt>. Camel will by default use <tt>OK</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelNagiosServiceName</tt> </td>
<td class='confluenceTd'> The servie name. Will default use the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> name. </td>
</tr>
</tbody></table>
</div>
</div>


<h3><a name="BookComponentAppendix-Sendingmessageexamples"></a>Sending message examples</h3>
<p>You can send a message to Nagios where the message payload contains the message. By default it will be <tt>OK</tt> level and use the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> name as the service name. You can overrule these values using headers as shown above.</p>

<p>For example we send the <tt>Hello Nagios</tt> message to Nagios as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    template.sendBody(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Hello Nagios"</span>);

    from(<span class="code-quote">"direct:start"</span>).to(<span class="code-quote">"nagios:127.0.0.1:5667?password=secret"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>To send a <tt>CRITICAL</tt> message you can send the headers such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map headers = <span class="code-keyword">new</span> HashMap();
        headers.put(NagiosConstants.LEVEL, <span class="code-quote">"CRITICAL"</span>);
        headers.put(NagiosConstants.HOST_NAME, <span class="code-quote">"myHost"</span>);
        headers.put(NagiosConstants.SERVICE_NAME, <span class="code-quote">"myService"</span>);
        template.sendBodyAndHeaders(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Hello Nagios"</span>, headers);
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Using%7B%7BNagiosEventNotifer%7D%7D"></a>Using <tt>NagiosEventNotifer</tt></h3>
<p>The <a href="/confluence/display/CAMEL/Nagios" title="Nagios">Nagios</a> component also provides an <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">EventNotifer</a> which you can use to send events to Nagios. For example we can enable this from Java as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        NagiosEventNotifier notifier = <span class="code-keyword">new</span> NagiosEventNotifier();
        notifier.getConfiguration().setHost(<span class="code-quote">"localhost"</span>);
        notifier.getConfiguration().setPort(5667);
        notifier.getConfiguration().setPassword(<span class="code-quote">"password"</span>);

        CamelContext context = ... 
        context.getManagementStrategy().addEventNotifier(notifier);
        <span class="code-keyword">return</span> context;
</pre>
</div></div>

<p>In Spring XML its just a matter of defining a Spring bean with the type <tt>EventNotifier</tt> and Camel will pick it up as documented here: <a href="/confluence/display/CAMEL/Advanced+configuration+of+CamelContext+using+Spring" title="Advanced configuration of CamelContext using Spring">Advanced configuration of CamelContext using Spring</a>.</p>

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

<h2><a name="BookComponentAppendix-NettyComponent"></a>Netty Component</h2>

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

<p>The <b>netty</b> component in Camel is a socket communication component, based on the JBoss Netty community offering (available under an Apache 2.0 license).<br/>
Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients.<br/>
Netty greatly simplifies and streamlines network programming such as TCP and UDP socket server.</p>

<p>This camel component supports both producer and consumer endpoints.</p>

<p>The netty component has several options and allows fine-grained control of a number of TCP/UDP communication parameters (buffer sizes, keepAlives, tcpNoDelay etc) and facilitates both In-Only and In-Out communication on a Camel route.</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-netty<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 netty component is as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
netty:tcp:<span class="code-comment">//localhost:99999[?options]
</span>netty:udp:<span class="code-comment">//remotehost:99999/[?options]</span>
</pre>
</div></div>

<p>This component supports producer and consumer endpoints for both TCP and UDP.</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>keepAlive</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Setting to ensure socket is not closed due to inactivity </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tcpNoDelay</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Setting to improve TCP protocol performance </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>broadcast</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Setting to choose Multicast over UDP </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectTimeout</tt> </td>
<td class='confluenceTd'> <tt>10000</tt> </td>
<td class='confluenceTd'> Time to wait for a socket connection to be available. Value is in millis. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reuseAddress</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Setting to facilitate socket multiplexing </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sync</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Setting to set endpoint as one-way or request-response </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ssl</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Setting to specify whether SSL encryption is applied to this endpoint </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendBufferSize</tt> </td>
<td class='confluenceTd'> <tt>65536 bytes</tt> </td>
<td class='confluenceTd'> The TCP/UDP buffer sizes to be used during outbound communication. Size is bytes. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveBufferSize</tt> </td>
<td class='confluenceTd'> <tt>65536 bytes</tt> </td>
<td class='confluenceTd'> The TCP/UDP buffer sizes to be used during inbound communication. Size is bytes. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>corePoolSize</tt> </td>
<td class='confluenceTd'> <tt>10</tt> </td>
<td class='confluenceTd'> The number of allocated threads at component startup. Defaults to 10 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxPoolSize</tt> </td>
<td class='confluenceTd'> <tt>100</tt> </td>
<td class='confluenceTd'> The maximum number of threads that may be allocated to this endpoint. Defaults to 100 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether or not to disconnect(close) from Netty Channel right after use. Can be used for both consumer and producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lazyChannelCreation</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Channels can be lazily created to avoid exceptions, if the remote server is not up and running when the Camel producer is started. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Only used for TCP. You can transfer the exchange over the wire instead of just the body. The following fields are transferred: In body, Out body, fault body, In headers, Out headers, fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnectOnNoReply</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If sync is enabled then this option dictates NettyConsumer if it should disconnect where there is no reply to send back. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>noReplyLogLevel</tt> </td>
<td class='confluenceTd'> <tt>WARN</tt> </td>
<td class='confluenceTd'> If sync is enabled this option dictates NettyConsumer which logging level to use when logging a there is no reply to send back. Values are: <tt>FATAL, ERROR, INFO, DEBUG, OFF</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowDefaultCodec</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> The netty component installs a default codec if both, encoder/deocder is null and textline is false. Setting allowDefaultCodec to false prevents the netty component from installing a default codec as the first element in the filter chain. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Only used for TCP. If no codec is specified, you can use this flag to indicate a text line based codec; if not specified or the value is false, then Object Serialization is assumed over TCP. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delimiter</tt> </td>
<td class='confluenceTd'> <tt>LINE</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> The delimiter to use for the textline codec. Possible values are <tt>LINE</tt> and <tt>NULL</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decoderMaxLineLength</tt> </td>
<td class='confluenceTd'> <tt>1024</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> The max line length to use for the textline codec. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>autoAppendDelimiter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Whether or not to auto append missing end delimiter when sending using the textline codec. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> The encoding (a charset name) to use for the textline codec. If not provided, Camel will use the JVM default Charset. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-RegistrybasedOptions"></a>Registry based Options</h3>

<p>Codec Handlers and SSL Keystores can be enlisted in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>, such as in the Spring XML file.<br/>
The values that could be passed in, are the following:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>passphrase</tt> </td>
<td class='confluenceTd'> password setting to use in order to encrypt/decrypt payloads sent using SSH </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyStoreFormat</tt> </td>
<td class='confluenceTd'> keystore format to be used for payload encryption. Defaults to "JKS" if not set </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityProvider</tt> </td>
<td class='confluenceTd'> Security provider to be used for payload encryption. Defaults to "SunX509" if not set. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyStoreFile</tt> </td>
<td class='confluenceTd'> Client side certificate keystore to be used for encryption </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trustStoreFile</tt> </td>
<td class='confluenceTd'> Server side certificate keystore to be used for encryption </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslHandler</tt> </td>
<td class='confluenceTd'> Reference to a class that could be used to return an SSL Handler </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoder</tt> </td>
<td class='confluenceTd'> A custom Handler class that can be used to perform special marshalling of outbound payloads. Must override <tt>org.jboss.netty.channel.ChannelDownStreamHandler</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encorders</tt> </td>
<td class='confluenceTd'> A list of encoder to be used. You can use a String which have values separated by comma, and have the values be looked up in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. Just remember to prefix the value with # so Camel knows it should lookup. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decoder</tt> </td>
<td class='confluenceTd'> A custom Handler class that can be used to perform special marshalling of inbound payloads. Must override <tt>org.jboss.netty.channel.ChannelUpStreamHandler</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decoders</tt> </td>
<td class='confluenceTd'> A list of decorder to be used. You can use a String which have values separated by comma, and have the values be looked up in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. Just remember to prefix the value with # so Camel knows it should lookup. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BookComponentAppendix-SendingMessagesto%2FfromaNettyendpoint"></a>Sending Messages to/from a Netty endpoint</h3>

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

<p>In Producer mode, the component provides the ability to send payloads to a socket endpoint<br/>
using either TCP or UDP protocols (with optional SSL support).</p>

<p>The producer mode supports both one-way and request-response based operations.</p>

<h4><a name="BookComponentAppendix-NettyConsumer"></a>Netty Consumer</h4>

<p>In Consumer mode, the component provides the ability to:</p>
<ul class="alternate" type="square">
	<li>listen on a specified socket using either TCP or UDP protocols (with optional SSL support),</li>
	<li>receive requests on the socket using text/xml, binary and serialized object based payloads and</li>
	<li>send them along on a route as message exchanges.</li>
</ul>


<p>The consumer mode supports both one-way and request-response based operations.</p>

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

<h4><a name="BookComponentAppendix-AUDPNettyendpointusingRequestReplyandserializedobjectpayload"></a>A UDP Netty endpoint using Request-Reply and serialized object payload</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">"netty:udp:<span class="code-comment">//localhost:5155?sync=<span class="code-keyword">true</span>"</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 {
           Poetry poetry = (Poetry) exchange.getIn().getBody();
           poetry.setPoet(<span class="code-quote">"Dr. Sarojini Naidu"</span>);
           exchange.getOut().setBody(poetry);
         }
       }
    }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-ATCPbasedNettyconsumerendpointusingOnewaycommunication"></a>A TCP based Netty consumer endpoint using One-way communication</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">"netty:tcp:<span class="code-comment">//localhost:5150"</span>)
</span>           .to(<span class="code-quote">"mock:result"</span>);
  }
};
</pre>
</div></div>

<h4><a name="BookComponentAppendix-AnSSL%2FTCPbasedNettyconsumerendpointusingRequestReplycommunication"></a>An SSL/TCP based Netty consumer endpoint using Request-Reply communication</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JndiRegistry registry = <span class="code-keyword">new</span> JndiRegistry(createJndiContext());
registry.bind(<span class="code-quote">"password"</span>, <span class="code-quote">"changeit"</span>);
registry.bind(<span class="code-quote">"ksf"</span>, <span class="code-keyword">new</span> File(<span class="code-quote">"src/test/resources/keystore.jks"</span>));
registry.bind(<span class="code-quote">"tsf"</span>, <span class="code-keyword">new</span> File(<span class="code-quote">"src/test/resources/keystore.jks"</span>));

context.createRegistry(registry);
context.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
  <span class="code-keyword">public</span> void configure() {
      <span class="code-object">String</span> netty_ssl_endpoint =
         <span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150?sync=<span class="code-keyword">true</span>&amp;ssl=<span class="code-keyword">true</span>&amp;passphrase=#password"</span>
</span>         + <span class="code-quote">"&amp;keyStoreFile=#ksf&amp;trustStoreFile=#tsf"</span>;
      <span class="code-object">String</span> return_string =
         <span class="code-quote">"When You Go Home, Tell Them Of Us And Say,"</span>
         + <span class="code-quote">"For Your Tomorrow, We Gave Our Today."</span>;

      from(netty_ssl_endpoint)
       .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(return_string);
          }
       }
  }
});
</pre>
</div></div>

<h4><a name="BookComponentAppendix-UsingMultipleCodecs"></a>Using Multiple Codecs</h4>

<p>In certain cases it may be necessary to add chains of encoders and decoders to the netty pipeline. To add multpile codecs to a camel netty endpoint the 'encoders' and 'decoders' uri parameters should be used. Like the 'encoder' and 'decoder' parameters they are used to supply references (to lists of ChannelUpstreamHandlers and ChannelDownstreamHandlers) that should be added to the  pipeline. Note that if encoders is specified then the encoder param will be ignored, similarly for decoders and the decoder param.</p>

<p>The lists of codecs need to be added to the Camel's registry so they can be resolved when the endpoint is created.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">LengthFieldBasedFrameDecoder lengthDecoder = <span class="code-keyword">new</span> LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4);
StringDecoder stringDecoder = <span class="code-keyword">new</span> StringDecoder();
registry.bind(<span class="code-quote">"length-decoder"</span>, lengthDecoder);
registry.bind(<span class="code-quote">"string-decoder"</span>, stringDecoder);

LengthFieldPrepender lengthEncoder = <span class="code-keyword">new</span> LengthFieldPrepender(4);
StringEncoder stringEncoder = <span class="code-keyword">new</span> StringEncoder();
registry.bind(<span class="code-quote">"length-encoder"</span>, lengthEncoder);
registry.bind(<span class="code-quote">"string-encoder"</span>, stringEncoder);

List&lt;ChannelUpstreamHandler&gt; decoders = <span class="code-keyword">new</span> ArrayList&lt;ChannelUpstreamHandler&gt;();
decoders.add(lengthDecoder);
decoders.add(stringDecoder);

List&lt;ChannelDownstreamHandler&gt; encoders = <span class="code-keyword">new</span> ArrayList&lt;ChannelDownstreamHandler&gt;();
encoders.add(lengthEncoder);
encoders.add(stringEncoder);

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

<p>Spring's native collections support can be used to specify the codec lists in an application context</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">"decoders"</span> list-class=<span class="code-quote">"java.util.LinkedList"</span>&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder"</span>&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"1048576"</span>/&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"0"</span>/&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"0"</span>/&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
        <span class="code-tag">&lt;/bean&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.jboss.netty.handler.codec.string.StringDecoder"</span>/&gt;</span>
    <span class="code-tag">&lt;/util:list&gt;</span>

    <span class="code-tag">&lt;util:list id=<span class="code-quote">"encoders"</span> list-class=<span class="code-quote">"java.util.LinkedList"</span>&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.jboss.netty.handler.codec.frame.LengthFieldPrepender"</span>&gt;</span>
            <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
        <span class="code-tag">&lt;/bean&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.jboss.netty.handler.codec.string.StringEncoder"</span>/&gt;</span>
    <span class="code-tag">&lt;/util:list&gt;</span>

    <span class="code-tag">&lt;bean id=<span class="code-quote">"length-encoder"</span> class=<span class="code-quote">"org.jboss.netty.handler.codec.frame.LengthFieldPrepender"</span>&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
    <span class="code-tag">&lt;bean id=<span class="code-quote">"string-encoder"</span> class=<span class="code-quote">"org.jboss.netty.handler.codec.string.StringEncoder"</span>/&gt;</span>

    <span class="code-tag">&lt;bean id=<span class="code-quote">"length-decoder"</span> class=<span class="code-quote">"org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder"</span>&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"1048576"</span>/&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"0"</span>/&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"0"</span>/&gt;</span>
        <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"4"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
    <span class="code-tag">&lt;bean id=<span class="code-quote">"string-decoder"</span> class=<span class="code-quote">"org.jboss.netty.handler.codec.string.StringDecoder"</span>/&gt;</span>

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

<p>The bean names can then be used in netty endpoint definitions either as a comma separated list or contained in a List e.g.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">                from(<span class="code-quote">"direct:multiple-codec"</span>).to(<span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150?encoders=#encoders&amp;sync=<span class="code-keyword">false</span>"</span>);
</span>                
                from(<span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150?decoders=#length-decoder,#string-decoder&amp;sync=<span class="code-keyword">false</span>"</span>).to(<span class="code-quote">"mock:multiple-codec"</span>);
</span>            }
        };
    }
}
</pre>
</div></div>

<p>or via spring.</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">"multiple-netty-codecs-context"</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:multiple-codec"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"netty:tcp://localhost:5150?encoders=#encoders&amp;amp;sync=false"</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">"netty:tcp://localhost:5150?decoders=#length-decoder,#string-decoder&amp;amp;sync=false"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:multiple-codec"</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-ClosingChannelWhenComplete"></a>Closing Channel When Complete</h3>

<p>When acting as a server you sometimes want to close the channel when, for example, a client conversion is finished.<br/>
You can do this by simply setting the endpoint option <tt>disconnect=true</tt>.</p>

<p>However you can also instruct Camel on a per message basis as follows.<br/>
To instruct Camel to close the channel, you should add a header with the key <tt>CamelNettyCloseChannelWhenComplete</tt> set to a boolean <tt>true</tt> value.<br/>
For instance, the example below will close the channel after it has written the bye message back to the client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        from(<span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:8080"</span>).process(<span class="code-keyword">new</span> Processor() {
</span>            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                <span class="code-object">String</span> body = exchange.getIn().getBody(<span class="code-object">String</span>.class);
                exchange.getOut().setBody(<span class="code-quote">"Bye "</span> + body);
                <span class="code-comment">// some condition which determines <span class="code-keyword">if</span> we should close
</span>                <span class="code-keyword">if</span> (close) {
                    exchange.getOut().setHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, <span class="code-keyword">true</span>);
                }
            }
        });
</pre>
</div></div>

<h3><a name="BookComponentAppendix-Addingcustomchannelpipelinefactoriestogaincompletecontroloveracreatedpipeline"></a>Adding custom channel pipeline factories to gain complete control over a created pipeline</h3>

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

<p>Custom channel pipelines provide complete control to the user over the handler/interceptor chain by inserting custom handler(s), encoder(s) &amp; decoders without having to specify them in the Netty Endpoint URL in a very simple way.</p>

<p>In order to add a custom pipeline, a custom channel pipeline factory must be created and registered with the context via the context registry (JNDIRegistry,or the camel-spring ApplicationContextRegistry etc).</p>

<p>A custom pipeline factory must be constructed as follows</p>
<ul>
	<li>A Producer linked channel pipeline factory must extend the abstract class ClientPipelineFactory.</li>
	<li>A Consumer linked channel pipeline factory must extend the abstract class ServerPipelineFactory.</li>
	<li>The classes can optionally override the getPipeline() method in order to insert custom handler(s), encoder(s) and decoder(s). Not overriding the getPipeline() method creates a pipeline with no handlers, encoders or decoders wired to the pipeline.</li>
</ul>


<p>The example below shows how ServerChannel Pipeline factory may be created</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class SampleServerChannelPipelineFactory <span class="code-keyword">extends</span> ServerPipelineFactory {
    <span class="code-keyword">private</span> <span class="code-object">int</span> maxLineSize = 1024;
    <span class="code-keyword">private</span> <span class="code-object">boolean</span> invoked;

    <span class="code-keyword">public</span> ChannelPipeline getPipeline() <span class="code-keyword">throws</span> Exception {
        invoked = <span class="code-keyword">true</span>;

        ChannelPipeline channelPipeline = Channels.pipeline();

        channelPipeline.addLast(<span class="code-quote">"encoder-SD"</span>, <span class="code-keyword">new</span> StringEncoder(CharsetUtil.UTF_8));
        channelPipeline.addLast(<span class="code-quote">"decoder-DELIM"</span>, <span class="code-keyword">new</span> DelimiterBasedFrameDecoder(maxLineSize, <span class="code-keyword">true</span>, Delimiters.lineDelimiter()));
        channelPipeline.addLast(<span class="code-quote">"decoder-SD"</span>, <span class="code-keyword">new</span> StringDecoder(CharsetUtil.UTF_8));
        channelPipeline.addLast(<span class="code-quote">"handler"</span>, <span class="code-keyword">new</span> ServerChannelHandler(consumer));

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

    <span class="code-keyword">public</span> <span class="code-object">boolean</span> isfactoryInvoked() {
        <span class="code-keyword">return</span> invoked;
    }
}
</pre>
</div></div>

<p>The custom channel pipeline factory can then be added to the registry and instantiated/utilized on a camel route in the following way</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Registry registry = camelContext.getRegistry();
serverPipelineFactory = <span class="code-keyword">new</span> TestServerChannelPipelineFactory();
registry.bind(<span class="code-quote">"spf"</span>, serverPipelineFactory);
context.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
  <span class="code-keyword">public</span> void configure() {
      <span class="code-object">String</span> netty_ssl_endpoint =
         <span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150?serverPipelineFactory=#spf"</span>
</span>      <span class="code-object">String</span> return_string =
         <span class="code-quote">"When You Go Home, Tell Them Of Us And Say,"</span>
         + <span class="code-quote">"For Your Tomorrow, We Gave Our Today."</span>;

      from(netty_ssl_endpoint)
       .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(return_string);
          }
       }
  }
});

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

<p>The con</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/MINA" title="MINA">MINA</a></li>
</ul>

<h2><a name="BookComponentAppendix-NMRComponent"></a>NMR Component</h2>

<p>The <b>nmr</b> component is an adapter to the Normalized Message Router (NMR) in <a href="http://servicemix.apache.org/home.html" class="external-link" rel="nofollow">ServiceMix</a>, which is intended for use by Camel applications deployed directly into the OSGi container. By contrast, the <a href="/confluence/display/CAMEL/JBI" title="JBI">JBI</a> component is intended for use by Camel applications deployed into the ServiceMix JBI container.</p>

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

<p>The NMR component is provided with Apache ServiceMix. It is <b>not</b> distributed with Camel. To install the NMR component in ServiceMix, enter the following command in the ServiceMix console window:</p>

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

<p>You also need to instantiate the NMR component. You can do this by editing your Spring configuration file, <tt>META-INF/spring/*.xml</tt>, and adding the following <tt>bean</tt> instance:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;beans xmlns:osgi=<span class="code-quote">"http:<span class="code-comment">//www.springframework.org/schema/osgi"</span> ... &gt;
</span>    ...
    &lt;bean id=<span class="code-quote">"nmr"</span> class=<span class="code-quote">"org.apache.servicemix.camel.nmr.ServiceMixComponent"</span>&gt;
        &lt;property name=<span class="code-quote">"nmr"</span>&gt;
            &lt;osgi:reference <span class="code-keyword">interface</span>=<span class="code-quote">"org.apache.servicemix.nmr.api.NMR"</span> /&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
    ...
&lt;/beans&gt;
</pre>
</div></div>

<h3><a name="BookComponentAppendix-NMRconsumerandproducerendpoints"></a>NMR consumer and producer endpoints</h3>

<p>The following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"nmr:MyServiceEndpoint"</span>)
</pre>
</div></div>

<p>Automatically exposes a new endpoint to the bus with endpoint name <tt>MyServiceEndpoint</tt> (see <a href="#BookComponentAppendix-URIformat">URI&#45;format</a>).</p>

<p>When an NMR endpoint appears at the end of a route, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
to(<span class="code-quote">"nmr:MyServiceEndpoint"</span>)
</pre>
</div></div>

<p>The messages sent by this producer endpoint are sent to the already deployed JBI endpoint.</p>

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

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

<h4><a name="BookComponentAppendix-URIOptions"></a>URI Options</h4>
<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>synchronous</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> When this is set to <b><tt>true</tt></b> on a consumer endpoint, an incoming, synchronous NMR Exchange will be handled on the sender's thread instead of being handled on a new thread of the NMR endpoint's thread pool </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">
from(<span class="code-quote">"nmr:MyServiceEndpoint"</span>)
from(<span class="code-quote">"nmr:MyServiceEndpoint?synchronous=<span class="code-keyword">true</span>"</span>).to(<span class="code-quote">"nmr:AnotherEndpoint"</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">"nmr:MyEndpoint"</span>).streamCaching().to(<span class="code-quote">"xslt:transform.xsl"</span>, <span class="code-quote">"bean:doSomething"</span>);
</pre>
</div></div>

<p>From <b>Camel 1.5</b> onwards, the stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt> option.<br/>
In <b>Camel 2.0</b> we store big input streams (by default, over 64K) in a <tt>temp</tt> file using <tt>CachedOutputStream</tt>. When you close the input stream, the temp file will be deleted.</p>

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

<h2><a name="BookComponentAppendix-QuartzComponent"></a>Quartz Component</h2>

<p>The <b>quartz:</b> component provides a scheduled delivery of messages using the <a href="http://www.opensymphony.com/quartz/" class="external-link" rel="nofollow">Quartz scheduler</a>. <br/>
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).</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-quartz<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>Using cron expressions</b><br />Configuring the cron expression in Camel 1.x is based on path separators. We changed this to an URI option in Camel 2.0, allowing a more elegant configuration.<br/>
Also it is <b>not</b> possible to use the <tt>/</tt> cron special character (for increments) in Camel 1.x, which Camel 2.0 also fixes.</td></tr></table></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
quartz:<span class="code-comment">//timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName/cronExpression       (@deprecated)
</span>quartz:<span class="code-comment">//groupName/timerName/?cron=expression     (Camel 2.0)
</span>quartz:<span class="code-comment">//timerName?cron=expression                (Camel 2.0)</span>
</pre>
</div></div>

<p>The component uses either a <tt>CronTrigger</tt> or a <tt>SimpleTrigger</tt>. If no cron expression is provided, the component uses a simple trigger. If no <tt>groupName</tt> is provided, the quartz component uses the <tt>Camel</tt> group name.</p>

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

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

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Parameter </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cron</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> Specifies a <tt>cron</tt> expression (not compatible with the <tt>trigger.&#42;</tt> or <tt>job.&#42;</tt> options). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatCount</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: How many times should the timer repeat? </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatInterval</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: The amount of time in milliseconds between repeated triggers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.name</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job option with the <tt><em>XXX</em></tt> setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the trigger option with the <tt><em>XXX</em></tt> setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>stateful</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Uses a Quartz <tt>StatefulJob</tt> instead of the default job. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fireNow</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> New to Camel 2.2.0, if it is true will fire the trigger when the route is start when using SimpleTrigger.</td>
</tr>
</tbody></table>
</div>


<p>For example, the following routing rule will fire two timer events to the <tt>mock:results</tt> endpoint:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">from(<span class="code-quote">"quartz://myGroup/myTimerName?trigger.repeatInterval=2&amp;trigger.repeatCount=1"</span>).routeId(<span class="code-quote">"myRoute"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>When using a <a href="http://www.quartz-scheduler.org/docs/api/org/quartz/StatefulJob.html" class="external-link" rel="nofollow">StatefulJob</a>, the <a href="http://www.quartz-scheduler.org/docs/api/org/quartz/JobDataMap.html" class="external-link" rel="nofollow">JobDataMap</a> is re-persisted after every execution of the job, thus preserving state for the next execution.</p>


<h3><a name="BookComponentAppendix-Configuringquartz.propertiesfile"></a>Configuring quartz.properties file</h3>

<p>By default Quartz