camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Language Component
Date Mon, 06 Sep 2010 11:06: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/Language+Component">Language
Component</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="LanguageComponent-LanguageComponent"></a>Language
Component</h2>
<p><b>Available as of Camel 2.5</b></p>

<p>The language component allows you to send <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> to an endpoint which executes a script by any of the
supported <a href="/confluence/display/CAMEL/Languages" title="Languages">Languages</a>
in Camel.<br/>
By having a component to execute language scripts, it allows more dynamic routing capabilities.
For example by using the <a href="/confluence/display/CAMEL/Routing+Slip" title="Routing
Slip">Routing Slip</a> or <a href="/confluence/display/CAMEL/Dynamic+Router" title="Dynamic
Router">Dynamic Router</a> EIPs you can send messages to <tt>language</tt>
endpoints where the script is dynamic defined as well.</p>

<p>This component is provided out of the box in <tt>camel-core</tt> and
hence no additional JARs is needed. You only have to include additional Camel components if
the language of choice mandates it, such as using <a href="/confluence/display/CAMEL/Groovy"
title="Groovy">Groovy</a> or <a href="/confluence/display/CAMEL/JavaScript" title="JavaScript">JavaScript</a>
languages.</p>

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

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

<h3><a name="LanguageComponent-URIOptions"></a>URI Options</h3>
<p>The component supports 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'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>languageName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The name of the <a href="/confluence/display/CAMEL/Languages"
title="Languages">Language</a> to use, such as <tt>simple</tt>, <tt>groovy</tt>,
<tt>javascript</tt> etc. This option is mandatory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>script</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The script to execute. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transform</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> Whether or not the result of the script should be used as
the new message body. By setting to <tt>false</tt> the script is executed but
the result of the script is discarded. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="LanguageComponent-MessageHeaders"></a>Message Headers</h3>
<p>The following message headers can be used to affect the behavior of the component</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelLanguageScript</tt> </td>
<td class='confluenceTd'> The script to execute provided in the header. Takes precedence
over script configured on the endpoint. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>For example you can use the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language to <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message
Translator</a> a 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">"language:simple:Hello ${body}"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>In case you want to convert the message body type you can do this as well:</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">"language:simple:${mandatoryBodyAs(<span class="code-object">String</span>)}"</span>).to(<span
class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>You can also use the <a href="/confluence/display/CAMEL/Groovy" title="Groovy">Groovy</a>
language, such as this example where the input message will by multiplied with 2:</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">"language:groovy:request.body * 2"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>You can also provide the script as a header as shown below. Here we use <a href="/confluence/display/CAMEL/XPath"
title="XPath">XPath</a> language to extract the text from the <tt>&lt;foo&gt;</tt>
tag.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">Object</span> out = producer.requestBodyAndHeader(<span
class="code-quote">"language:xpath"</span>, <span class="code-quote">"&lt;foo&gt;Hello
World&lt;/foo&gt;"</span>, Exchange.LANGUAGE_SCRIPT, <span class="code-quote">"/foo/text()"</span>);
assertEquals(<span class="code-quote">"Hello World"</span>, out);
</pre>
</div></div>

<h3><a name="LanguageComponent-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/Languages" title="Languages">Languages</a></li>
	<li><a href="/confluence/display/CAMEL/Routing+Slip" title="Routing Slip">Routing
Slip</a></li>
	<li><a href="/confluence/display/CAMEL/Dynamic+Router" title="Dynamic Router">Dynamic
Router</a></li>
</ul>

    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Language+Component">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Language+Component?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message