camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Simple
Date Tue, 25 Jun 2013 08:39:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/Simple">Simple</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" >{code} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">And you can call the size method on the list with <br>{code} <br>simple(&quot;${body.address.lines.size}&quot;) <br>{code} <br> <br>From *Camel 2.11.1* onwards we added support for the length field for Java arrays as well, eg: <br>{code} <br>String[] lines = new String[]{&quot;foo&quot;, &quot;bar&quot;, &quot;cat&quot;}; <br>exchange.getIn().setBody(lines); <br> <br>simple(&quot;There are ${body.length} lines&quot;) <br>{code} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >And yes you can combine this with the operator support as shown below: <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Simple-SimpleExpressionLanguage"></a>Simple Expression Language</h2>

<p>The Simple Expression Language was a really simple language you can use, but has since grown more powerful. Its primarily intended for being a really small and simple language for evaluating <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> and <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> without requiring any new dependencies or knowledge of <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a>; so its ideal for testing in camel-core. Its ideal to cover 95% of the common use cases when you need a little bit of expression based script in your Camel routes.</p>

<p>However for much more complex use cases you are generally recommended to choose a more expressive and powerful language such as: </p>
<ul>
	<li><a href="/confluence/display/CAMEL/SpEL" title="SpEL">SpEL</a></li>
	<li><a href="/confluence/display/CAMEL/Mvel" title="Mvel">Mvel</a></li>
	<li><a href="/confluence/display/CAMEL/Groovy" title="Groovy">Groovy</a></li>
	<li><a href="/confluence/display/CAMEL/JavaScript" title="JavaScript">JavaScript</a></li>
	<li><a href="/confluence/display/CAMEL/EL" title="EL">EL</a></li>
	<li><a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a></li>
	<li>one of the supported <a href="/confluence/display/CAMEL/Scripting+Languages" title="Scripting Languages">Scripting Languages</a></li>
</ul>


<p>The simple language uses <tt>${body</tt>} placeholders for complex expressions where the expression contains constant literals. The ${ } placeholders can be omitted if the expression is only the token itself.</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>Alternative syntax</b><br />From Camel 2.5 onwards you can also use the alternative syntax which uses $simple{ } as placeholders.<br/>
This can be used in situations to avoid clashes when using for example Spring property placeholder together with Camel.</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>Configuring result type</b><br />From Camel 2.8 onwards you can configure the result type of the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> expression. For example to set the type as a <tt>java.lang.Boolean</tt> or a <tt>java.lang.Integer</tt> etc.</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>File language is now merged with Simple language</b><br />From Camel 2.2 onwards, the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a> is now merged with <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language which means you can use all the file syntax directly within the simple language.</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>Simple Language Changes in Camel 2.9 onwards</b><br />The <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language have been improved from Camel 2.9 onwards to use a better syntax parser, which can do index precise error messages, so you know exactly what is wrong and where the problem is. For example if you have made a typo in one of the operators, then previously the parser would not be able to detect this, and cause the evaluation to be true. There is a few changes in the syntax which are no longer backwards compatible. When using <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language as a <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> then the literal text <b>must</b> be enclosed in either single or double quotes. For example: <tt>"${body} == 'Camel'"</tt>. Notice how we have single quotes around the literal. The old style of using <tt>"body"</tt> and <tt>"header.foo"</tt> to refer to the message body and header is @deprecated, and its encouraged to always use ${ } tokens for the built-in functions.<br/>
The range operator now requires the range to be in single quote as well as shown: <tt>"${header.zip} between '30000..39999'"</tt>.</td></tr></table></div>

<p>To get the body of the in message: <tt>"body"</tt>, or <tt>"in.body"</tt> or <tt>"${body}"</tt>.</p>

<p>A complex expression must use ${ } placeholders, such as: <tt>"Hello ${in.header.name} how are you?"</tt>.</p>

<p>You can have multiple functions in the same expression: <tt>"Hello ${in.header.name} this is ${in.header.me} speaking"</tt>.<br/>
However you can <b>not</b> nest functions in Camel 2.8.x or older (i.e. having another ${ } placeholder in an existing, is not allowed).<br/>
>From <b>Camel 2.9</b> onwards you can nest functions.</p>

<h3><a name="Simple-Variables"></a>Variables</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Variable </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'>  Description </th>
</tr>
<tr>
<td class='confluenceTd'> camelId </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> name </td>
</tr>
<tr>
<td class='confluenceTd'> camelContext.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> the CamelContext invoked using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> exchangeId </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> the exchange id </td>
</tr>
<tr>
<td class='confluenceTd'> id </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> the input message id </td>
</tr>
<tr>
<td class='confluenceTd'> body </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> the input body </td>
</tr>
<tr>
<td class='confluenceTd'> in.body </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> the input body </td>
</tr>
<tr>
<td class='confluenceTd'> body.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> the input body invoked using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> in.body.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> the input body invoked using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> bodyAs(<em>type</em>) </td>
<td class='confluenceTd'> Type </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Converts the body to the given type determined by its classname. The converted body can be null. </td>
</tr>
<tr>
<td class='confluenceTd'> mandatoryBodyAs(<em>type</em>) </td>
<td class='confluenceTd'> Type </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Converts the body to the given type determined by its classname, and expects the body to be not null. </td>
</tr>
<tr>
<td class='confluenceTd'> out.body </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> the output body </td>
</tr>
<tr>
<td class='confluenceTd'> header.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> header[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> headers.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> headers[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> in.header.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> in.header[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> in.headers.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> in.headers[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the input foo header </td>
</tr>
<tr>
<td class='confluenceTd'> header.foo[bar] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> regard input foo header as a map and perform lookup on the map with bar as key </td>
</tr>
<tr>
<td class='confluenceTd'> in.header.foo[bar] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> regard input foo header as a map and perform lookup on the map with bar as key </td>
</tr>
<tr>
<td class='confluenceTd'> in.headers.foo[bar] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> regard input foo header as a map and perform lookup on the map with bar as key </td>
</tr>
<tr>
<td class='confluenceTd'> header.foo.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> refer to the input foo header and invoke its value using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> in.header.foo.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> refer to the input foo header and invoke its value using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> in.headers.foo.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> refer to the input foo header and invoke its value using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> out.header.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the out header foo </td>
</tr>
<tr>
<td class='confluenceTd'> out.header[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the out header foo </td>
</tr>
<tr>
<td class='confluenceTd'> out.headers.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the out header foo </td>
</tr>
<tr>
<td class='confluenceTd'> out.headers[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the out header foo </td>
</tr>
<tr>
<td class='confluenceTd'> headerAs(<em>key</em>,<em>type</em>) </td>
<td class='confluenceTd'> Type </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Converts the header to the given type determined by its classname </td>
</tr>
<tr>
<td class='confluenceTd'> headers </td>
<td class='confluenceTd'> Map </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> refer to the input headers </td>
</tr>
<tr>
<td class='confluenceTd'> in.headers </td>
<td class='confluenceTd'> Map </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> refer to the input headers </td>
</tr>
<tr>
<td class='confluenceTd'> property.foo </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> refer to the foo property on the exchange </td>
</tr>
<tr>
<td class='confluenceTd'> property[foo] </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.9.2:</b> refer to the foo property on the exchange </td>
</tr>
<tr>
<td class='confluenceTd'> property.foo.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> refer to the foo property on the exchange and invoke its value using a Camel OGNL expression. </td>
</tr>
<tr>
<td class='confluenceTd'> sys.foo </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> refer to the system property </td>
</tr>
<tr>
<td class='confluenceTd'> sysenv.foo </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> refer to the system environment </td>
</tr>
<tr>
<td class='confluenceTd'> exception </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Refer to the exception object on the exchange, is <b>null</b> if no exception set on exchange. Will fallback and grab caught exceptions (<tt>Exchange.EXCEPTION_CAUGHT</tt>) if the Exchange has any. </td>
</tr>
<tr>
<td class='confluenceTd'> exception.<b>OGNL</b> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Refer to the exchange exception invoked using a Camel OGNL expression object </td>
</tr>
<tr>
<td class='confluenceTd'> exception.message </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> Refer to the exception.message on the exchange, is <b>null</b> if no exception set on exchange. Will fallback and grab caught exceptions (<tt>Exchange.EXCEPTION_CAUGHT</tt>) if the Exchange has any. </td>
</tr>
<tr>
<td class='confluenceTd'> exception.stacktrace </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.6.</b> Refer to the exception.stracktrace on the exchange, is <b>null</b> if no exception set on exchange. Will fallback and grab caught exceptions (<tt>Exchange.EXCEPTION_CAUGHT</tt>) if the Exchange has any. </td>
</tr>
<tr>
<td class='confluenceTd'> date:<em>command:pattern</em> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> Date formatting using the <tt>java.text.SimpleDataFormat</tt> patterns. Supported commands are: <b>now</b> for current timestamp, <b>in.header.xxx</b> or <b>header.xxx</b> to use the Date object in the IN header with the key xxx. <b>out.header.xxx</b> to use the Date object in the OUT header with the key xxx.</td>
</tr>
<tr>
<td class='confluenceTd'> bean:<em>bean expression</em> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> Invoking a bean expression using the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> language. Specifying a method name you must use dot as separator. We also support the ?method=methodname syntax that is used by the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component. </td>
</tr>
<tr>
<td class='confluenceTd'> properties:<em>locations:key</em> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Lookup a property with the given key. The <tt>locations</tt> option is optional. See more at <a href="/confluence/display/CAMEL/Using+PropertyPlaceholder" title="Using PropertyPlaceholder">Using PropertyPlaceholder</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> routeId </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Returns the id of the current route the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is being routed. </td>
</tr>
<tr>
<td class='confluenceTd'> threadName </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Returns the name of the current thread. Can be used for logging purpose. </td>
</tr>
<tr>
<td class='confluenceTd'> ref:xxx </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> To lookup a bean from the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> with the given id. </td>
</tr>
<tr>
<td class='confluenceTd'> type:name.field </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To refer to a type or field by its FQN name. To refer to a field you can append .FIELD_NAME. For example you can refer to the constant field from Exchange as: <tt>org.apache.camel.Exchange.FILE_NAME</tt> </td>
<td class='confluenceTd'>.</td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Simple-OGNLexpressionsupport"></a>OGNL expression support</h3>
<p><b>Available as of Camel 2.3</b></p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Camel's OGNL support is for invoking methods only. You cannot access fields.<br/>
>From <b>Camel 2.11.1</b> onwards we added special support for accessing the length field of Java arrays.</td></tr></table></div>

<p>The <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> and <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> language now supports a Camel OGNL notation for invoking beans in a chain like fashion.<br/>
Suppose the Message IN body contains a POJO which has a <tt>getAddress()</tt> method.</p>

<p>Then you can use Camel OGNL notation to access the address object:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address}")
simple("${body.address.street}")
simple("${body.address.zip}")
</pre>
</div></div>

<p>Camel understands the shorthand names for getters, but you can invoke any method or use the real name such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address}")
simple("${body.getAddress.getStreet}")
simple("${body.address.getZip}")
simple("${body.doSomething}")
</pre>
</div></div>

<p>You can also use the null safe operator (<tt>?.</tt>) to avoid NPE if for example the body does NOT have an address</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body?.address?.street}")
</pre>
</div></div>

<p>Its also possible to index in <tt>Map</tt> or <tt>List</tt> types, so you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body[foo].name}")
</pre>
</div></div>
<p>To assume the body is <tt>Map</tt> based and lookup the value with <tt>foo</tt> as key, and invoke the <tt>getName</tt> method on that value.</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>If the key has space, then you <b>must</b> enclose the key with quotes, for example 'foo bar':
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body['foo bar'].name}")
</pre>
</div></div></td></tr></table></div>

<p>You can access the <tt>Map</tt> or <tt>List</tt> objects directly using their key name (with or without dots) :</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body[foo]}")
simple("${body[this.is.foo]}")
</pre>
</div></div>

<p>Suppose there was no value with the key <tt>foo</tt> then you can use the null safe operator to avoid the NPE as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body[foo]?.name}")
</pre>
</div></div>

<p>You can also access <tt>List</tt> types, for example to get lines from the address you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.lines[0]}")
simple("${body.address.lines[1]}")
simple("${body.address.lines[2]}")
</pre>
</div></div>

<p>There is a special <tt>last</tt> keyword which can be used to get the last value from a list.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.lines[last]}")
</pre>
</div></div>

<p>And to get the 2nd last you can subtract a number, so we can use <tt>last-1</tt> to indicate this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.lines[last-1]}")
</pre>
</div></div>

<p>And the 3rd last is of course:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.lines[last-2]}")
</pre>
</div></div>

<p>And you can call the size method on the list with</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.lines.size}")
</pre>
</div></div>

<p>From <b>Camel 2.11.1</b> onwards we added support for the length field for Java arrays as well, eg:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
String[] lines = new String[]{"foo", "bar", "cat"};
exchange.getIn().setBody(lines);

simple("There are ${body.length} lines")
</pre>
</div></div>

<p>And yes you can combine this with the operator support as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${body.address.zip} &gt; 1000")
</pre>
</div></div>

<h3><a name="Simple-Operatorsupport"></a>Operator support</h3>
<p>The parser is limited to only support a single operator. </p>

<p>To enable it the left value must be enclosed in ${ }. The syntax is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
${leftValue} OP rightValue
</pre>
</div></div>
<p>Where the <tt>rightValue</tt> can be a String literal enclosed in <tt>' '</tt>, <tt>null</tt>, a constant value or another expression enclosed in ${ }.</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>Important</b><br />There <b>must</b> be spaces around the operator.</td></tr></table></div>

<p>Camel will automatically type convert the rightValue type to the leftValue type, so its able to eg. convert a string into a numeric so you can use &gt; comparison for numeric values.</p>

<p>The following operators are supported:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Operator </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> == </td>
<td class='confluenceTd'> equals </td>
</tr>
<tr>
<td class='confluenceTd'> &gt; </td>
<td class='confluenceTd'> greater than </td>
</tr>
<tr>
<td class='confluenceTd'> &gt;= </td>
<td class='confluenceTd'> greater than or equals </td>
</tr>
<tr>
<td class='confluenceTd'> &lt; </td>
<td class='confluenceTd'> less than </td>
</tr>
<tr>
<td class='confluenceTd'> &lt;= </td>
<td class='confluenceTd'> less than or equals </td>
</tr>
<tr>
<td class='confluenceTd'> != </td>
<td class='confluenceTd'> not equals </td>
</tr>
<tr>
<td class='confluenceTd'> contains </td>
<td class='confluenceTd'> For testing if contains in a string based value </td>
</tr>
<tr>
<td class='confluenceTd'> not contains </td>
<td class='confluenceTd'> For testing if not contains in a string based value </td>
</tr>
<tr>
<td class='confluenceTd'> regex </td>
<td class='confluenceTd'> For matching against a given regular expression pattern defined as a String value </td>
</tr>
<tr>
<td class='confluenceTd'> not regex </td>
<td class='confluenceTd'> For not matching against a given regular expression pattern defined as a String value </td>
</tr>
<tr>
<td class='confluenceTd'> in </td>
<td class='confluenceTd'> For matching if in a set of values, each element must be separated by comma. </td>
</tr>
<tr>
<td class='confluenceTd'> not in </td>
<td class='confluenceTd'> For matching if not in a set of values, each element must be separated by comma. </td>
</tr>
<tr>
<td class='confluenceTd'> is </td>
<td class='confluenceTd'> For matching if the left hand side type is an instanceof the value. </td>
</tr>
<tr>
<td class='confluenceTd'> not is </td>
<td class='confluenceTd'> For matching if the left hand side type is not an instanceof the value. </td>
</tr>
<tr>
<td class='confluenceTd'> range </td>
<td class='confluenceTd'> For matching if the left hand side is within a range of values defined as numbers: <tt>from..to</tt>. From <b>Camel 2.9</b> onwards the range values must be enclosed in single quotes. </td>
</tr>
<tr>
<td class='confluenceTd'> not range </td>
<td class='confluenceTd'> For matching if the left hand side is not within a range of values defined as numbers: <tt>from..to</tt>. From <b>Camel 2.9</b> onwards the range values must be enclosed in single quotes. </td>
</tr>
</tbody></table>
</div>


<p>And the following unary operators can be used:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Operator </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> &#43;&#43; </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> To increment a number by one. The left hand side must be a function, otherwise parsed as literal. </td>
</tr>
<tr>
<td class='confluenceTd'> &#45;&#45; </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> To decrement a number by one. The left hand side must be a function, otherwise parsed as literal. </td>
</tr>
<tr>
<td class='confluenceTd'> \ </td>
<td class='confluenceTd'> <b>Camel 2.9.3 to 2.10.x</b> To escape a value, eg \$, to indicate a $ sign. Special: Use \n for new line, \t for tab, and \r for carriage return. <b>Notice:</b> Escaping is <b>not</b> supported using the <a href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>. <b>Notice:</b> From Camel 2.11 onwards the escape character is no longer support, but replaced with the following three special escaping. </td>
</tr>
<tr>
<td class='confluenceTd'> \n </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use newline character. </td>
</tr>
<tr>
<td class='confluenceTd'> \t </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use tab character. </td>
</tr>
<tr>
<td class='confluenceTd'> \r </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To use carriage return character. </td>
</tr>
</tbody></table>
</div>



<p>And the following logical operators can be used to group expressions:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Operator </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> and </td>
<td class='confluenceTd'> <b>deprecated</b> use &amp;&amp; instead. The logical and operator is used to group two expressions. </td>
</tr>
<tr>
<td class='confluenceTd'> or </td>
<td class='confluenceTd'> <b>deprecated</b> use &#124;&#124; instead. The logical or operator is used to group two expressions. </td>
</tr>
<tr>
<td class='confluenceTd'> &amp;&amp; </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> The logical and operator is used to group two expressions. </td>
</tr>
<tr>
<td class='confluenceTd'> &#124;&#124; </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> The logical or operator is used to group two expressions. </td>
</tr>
</tbody></table>
</div>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using and,or operators</b><br />In <b>Camel 2.4 or older</b> the <tt>and</tt> or <tt>or</tt> can only be used <b>once</b> in a simple language expression. From <b>Camel 2.5</b> onwards you can use these operators multiple times.</td></tr></table></div>

<p>The syntax for AND is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
${leftValue} OP rightValue and ${leftValue} OP rightValue 
</pre>
</div></div>

<p>And the syntax for OR is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
${leftValue} OP rightValue or ${leftValue} OP rightValue 
</pre>
</div></div>

<p>Some examples:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.foo} == 'foo'")

// here Camel will type convert '100' into the type of in.header.bar and if its an Integer '100' will also be converter to an Integer
simple("${in.header.bar} == '100'")

simple("${in.header.bar} == 100")

// 100 will be converter to the type of in.header.bar so we can do &gt; comparison
simple("${in.header.bar} &gt; 100")
</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>Comparing with different types</b><br />When you compare with different types such as String and int, then you have to take a bit care. Camel will use the type from the left hand side as 1st priority. And fallback to the right hand side type if both values couldn't be compared based on that type.<br/>
This means you can flip the values to enforce a specific type. Suppose the bar value above is a String. Then you can flip the equation:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("100 &lt; ${in.header.bar}")
</pre>
</div></div>
<p>which then ensures the int type is used as 1st priority.</p>

<p>This may change in the future if the Camel team improves the binary comparison operations to prefer numeric types over String based. It's most often the String type which causes problem when comparing with numbers.</p></td></tr></table></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
// testing for null
simple("${in.header.baz} == null")

// testing for not null
simple("${in.header.baz} != null")
</pre>
</div></div>

<p>And a bit more advanced example where the right value is another expression</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.date} == ${date:now:yyyyMMdd}")

simple("${in.header.type} == ${bean:orderService?method=getOrderType}")
</pre>
</div></div>

<p>And an example with contains, testing if the title contains the word Camel</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.title} contains 'Camel'")
</pre>
</div></div>

<p>And an example with regex, testing if the number header is a 4 digit value:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.number} regex '\\d{4}'")
</pre>
</div></div>

<p>And finally an example if the header equals any of the values in the list. Each element must be separated by comma, and no space around.<br/>
This also works for numbers etc, as Camel will convert each element into the type of the left hand side.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.type} in 'gold,silver'")
</pre>
</div></div>

<p>And for all the last 3 we also support the negate test using not:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.type} not in 'gold,silver'")
</pre>
</div></div>

<p>And you can test if the type is a certain instance, eg for instance a String</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.type} is 'java.lang.String'")
</pre>
</div></div>
<p>We have added a shorthand for all <tt>java.lang</tt> types so you can write it as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.type} is 'String'")
</pre>
</div></div>

<p>Ranges are also supported. The range interval requires numbers and both from and end are inclusive. For instance to test whether a value is between 100 and 199:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.number} range 100..199")
</pre>
</div></div>
<p>Notice we use <tt>..</tt> in the range without spaces. Its based on the same syntax as Groovy.</p>

<p>From <b>Camel 2.9</b> onwards the range value must be in single quotes</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.number} range '100..199'")
</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>Can be used in Spring XML</b><br />As the Spring XML does not have all the power as the Java DSL with all its various builder methods, you have to resort to use some other languages<br/>
for testing with simple operators. Now you can do this with the simple language. In the sample below we want to test if the header is a widget order: 
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    &lt;from uri="seda:orders"&gt;
       &lt;filter&gt;
           &lt;simple&gt;${in.header.type} == 'widget'&lt;/simple&gt;
           &lt;to uri="bean:orderService?method=handleWidget"/&gt;
       &lt;/filter&gt;
    &lt;/from&gt;
</pre>
</div></div></td></tr></table></div> 

<h4><a name="Simple-Usingand%2For"></a>Using and / or</h4>
<p>If you have two expressions you can combine them with the <tt>and</tt> or <tt>or</tt> operator.</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>Camel 2.9 onwards</b><br />Use &amp;&amp; or &#124;&#124; from Camel 2.9 onwards.</td></tr></table></div>

<p>For instance:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.title} contains 'Camel' and ${in.header.type'} == 'gold'")
</pre>
</div></div>

<p>And of course the <tt>or</tt> is also supported. The sample would be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.title} contains 'Camel' or ${in.header.type'} == 'gold'")
</pre>
</div></div>

<p><b>Notice:</b> Currently <tt>and</tt> or <tt>or</tt> can only be used <b>once</b> in a simple language expression. This might change in the future.<br/>
So you <b>cannot</b> do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
simple("${in.header.title} contains 'Camel' and ${in.header.type'} == 'gold' and ${in.header.number} range 100..200")
</pre>
</div></div>

<h3><a name="Simple-Samples"></a>Samples</h3>
<p>In the Spring XML sample below we filter based on a header value:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    &lt;from uri="seda:orders"&gt;
       &lt;filter&gt;
           &lt;simple&gt;${in.header.foo}&lt;/simple&gt;
           &lt;to uri="mock:fooOrders"/&gt;
       &lt;/filter&gt;
    &lt;/from&gt;
</pre>
</div></div>

<p>The Simple language can be used for the predicate test above in the <a href="/confluence/display/CAMEL/Message+Filter" title="Message Filter">Message Filter</a> pattern, where we test if the in message has a <tt>foo</tt> header (a header with the key <tt>foo</tt> exists). If the expression evaluates to <b>true</b> then the message is routed to the <tt>mock:fooOrders</tt> endpoint, otherwise its lost in the deep blue sea <img class="emoticon" src="/confluence/images/icons/emoticons/wink.gif" height="20" width="20" align="absmiddle" alt="" border="0"/>.</p>

<p>The same example in Java DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    from("seda:orders")
        .filter().simple("${in.header.foo}").to("seda:fooOrders");
</pre>
</div></div>

<p>You can also use the simple language for simple text concatenations such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   from("direct:hello").transform().simple("Hello ${in.header.user} how are you?").to("mock:reply");
</pre>
</div></div>
<p>Notice that we must use ${ } placeholders in the expression now to allow Camel to parse it correctly. </p>

<p>And this sample uses the date command to output current date.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   from("direct:hello").transform().simple("The today is ${date:now:yyyyMMdd} and its a great day.").to("mock:reply");
</pre>
</div></div>

<p>And in the sample below we invoke the bean language to invoke a method on a bean to be included in the returned string:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator}").to("mock:reply");
</pre>
</div></div>
<p>Where <tt>orderIdGenerator</tt> is the id of the bean registered in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. If using Spring then its the Spring bean id.</p>

<p>If we want to declare which method to invoke on the order id generator bean we must prepend <tt>.method name</tt> such as below where we invoke the <tt>generateId</tt> method.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator.generateId}").to("mock:reply");
</pre>
</div></div>

<p>We can use the <tt>?method=methodname</tt> option that we are familiar with the <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> component itself:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator?method=generateId}").to("mock:reply");
</pre>
</div></div>

<p>And from Camel 2.3 onwards you can also convert the body to a given type, for example to ensure its a String you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
  &lt;transform&gt;
    &lt;simple&gt;Hello ${bodyAs(String)} how are you?&lt;/simple&gt;
  &lt;/transform&gt;
</pre>
</div></div>

<p>There are a few types which have a shorthand notation, so we can use <tt>String</tt> instead of <tt>java.lang.String</tt>. These are: <tt>byte[], String, Integer, Long</tt>. All other types must use their FQN name, e.g. <tt>org.w3c.dom.Document</tt>.</p>

<p>Its also possible to lookup a value from a header <tt>Map</tt> in <b>Camel 2.3</b> onwards:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
  &lt;transform&gt;
    &lt;simple&gt;The gold value is ${header.type[gold]}&lt;/simple&gt;
  &lt;/transform&gt;
</pre>
</div></div>

<p>In the code above we lookup the header with name <tt>type</tt> and regard it as a <tt>java.util.Map</tt> and we then lookup with the key <tt>gold</tt> and return the value.<br/>
If the header is not convertible to Map an exception is thrown. If the header with name <tt>type</tt> does not exist <tt>null</tt> is returned.</p>

<p>From Camel 2.9 onwards you can nest functions, such as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;setHeader headerName="myHeader"&gt;
  &lt;simple&gt;${properties:${header.someKey}}&lt;/simple&gt;
&lt;/setHeader&gt;
</pre>
</div></div>

<h4><a name="Simple-Referringtoconstantsorenums"></a>Referring to constants or enums</h4>
<p><b>Available as of Camel 2.11</b></p>

<p>Suppose you have an enum for customers</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
public enum Customer {

    GOLD, SILVER, BRONZE
}
]]></script>
</div></div>

<p>And in a <a href="/confluence/display/CAMEL/Content+Based+Router" title="Content Based Router">Content Based Router</a> we can use the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language to refer to this enum, to check the message which enum it matches.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
from("direct:start")
    .choice()
        .when().simple("${header.customer} == ${type:org.apache.camel.processor.Customer.GOLD}")
            .to("mock:gold")
        .when().simple("${header.customer} == ${type:org.apache.camel.processor.Customer.SILVER}")
            .to("mock:silver")
        .otherwise()
            .to("mock:other");
]]></script>
</div></div>

<h3><a name="Simple-UsingnewlinesortabsinXMLDSLs"></a>Using new lines or tabs in XML DSLs</h3>
<p><b>Available as of Camel 2.9.3</b></p>

<p>From Camel 2.9.3 onwards its easier to specify new lines or tabs in XML DSLs as you can escape the value now</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;transform&gt;
  &lt;simple&gt;The following text\nis on a new line&lt;/simple&gt;
&lt;/transform&gt;
</pre>
</div></div>


<h3><a name="Simple-Settingresulttype"></a>Setting result type</h3>
<p><b>Available as of Camel 2.8</b></p>

<p>You can now provide a result type to the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> expression, which means the result of the evaluation will be converted to the desired type. This is most useable to define types such as booleans, integers, etc.</p>

<p>For example to set a header as a boolean type you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
.setHeader("cool", simple("true", Boolean.class))
</pre>
</div></div>

<p>And in XML DSL</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
      &lt;setHeader headerName="cool"&gt;
        &lt;!-- use resultType to indicate that the type should be a java.lang.Boolean --&gt;
        &lt;simple resultType="java.lang.Boolean"&gt;true&lt;/simple&gt;
      &lt;/setHeader&gt;
</pre>
</div></div>

<h3><a name="Simple-Changingfunctionstartandendtokens"></a>Changing function start and end tokens</h3>
<p><b>Available as of Camel 2.9.1</b></p>

<p>You can configure the function start and end tokens - ${ } using the setters <tt>changeFunctionStartToken</tt> and <tt>changeFunctionEndToken</tt> on <tt>SimpleLanguage</tt>, using Java code. From Spring XML you can define a &lt;bean&gt; tag with the new changed tokens in the properties as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    &lt;!-- configure Simple to use custom prefix/suffix tokens --&gt;
    &lt;bean id="simple" class="org.apache.camel.language.simple.SimpleLanguage"&gt;
      &lt;property name="functionStartToken" value="["/&gt;
      &lt;property name="functionEndToken" value="]"/&gt;
    &lt;/bean&gt;
</pre>
</div></div>

<p>In the example above we use [ ] as the changed tokens.</p>

<p>Notice by changing the start/end token you change those in all the Camel applications which share the same <b>camel-core</b> on their classpath.<br/>
For example in an OSGi server this may affect many applications, where as a Web Application as a WAR file it only affects the Web Application.</p>

<h3><a name="Simple-Loadingscriptfromexternalresource"></a>Loading script from external resource</h3>
<p><b>Available as of Camel 2.11</b></p>

<p>You can externalize the script and have Camel load it from a resource such as <tt>"classpath:"</tt>, <tt>"file:"</tt>, or <tt>"http:"</tt>.<br/>
This is done using the following syntax: <tt>"resource:scheme:location"</tt>, eg to refer to a file on the classpath you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
.setHeader("myHeader").simple("resource:classpath:mysimple.txt")
</pre>
</div></div>

<h3><a name="Simple-Dependencies"></a>Dependencies</h3>
<p>The <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language is part of <b>camel-core</b>.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Simple">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=70160&revisedVersion=80&originalVersion=79">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Simple?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message