camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Scalate
Date Tue, 19 Jul 2011 17:54:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><s>Scalate</s></h2>
     <h4>Page <b>removed</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
     <br/>
     <div class="notificationGreySide">
         <h2><a name="Scalate-Scalate"></a>Scalate</h2>
<p><b>Available as of Camel 2.3</b></p>

<p>The <b>scalate:</b> component allows you to process a message using <a
href="http://scalate.fusesource.org/" class="external-link" rel="nofollow">Scalate</a>
template, which supports either SSP or Scaml format templates. This can be ideal when using
<a href="/confluence/display/CAMEL/Templating" title="Templating">Templating</a>
to generate responses for requests.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component, and use the correct version of Scalate:</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.fusesource.scalate<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>scalate-camel<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>1.3.2<span class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

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

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

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

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

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

<p>The scalate component sets a couple headers on the message (you can't set these yourself
and from Camel 2.1 scalate component will not set these headers which will cause some side
effect on the dynamic template support):</p>
<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>CamelScalateResource</tt> </td>
<td class='confluenceTd'> The resource as an <tt>org.springframework.core.io.Resource</tt>
object. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelScalateResourceUri</tt> </td>
<td class='confluenceTd'> The <b>templateName</b> as a <tt>String</tt>
object. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>For example, to set the header value of <tt>fruit</tt> in the Scalate
template <tt>.tm</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;% in.setHeader('fruit', 'Apple') %&gt;
</pre>
</div></div>

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

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

<h3><a name="Scalate-Hotreloading"></a>Hot reloading</h3>
<p>The Scalate template resource is, by default, hot reloadable for both file and classpath
resources (expanded jar). </p>

<h3><a name="Scalate-Dynamictemplates"></a>Dynamic templates</h3>

<p>Camel provides two headers by which you can define a different resource location
for a template or the template content itself. If any of these headers is set then Camel uses
this over the endpoint configured resource. This allows you to provide a dynamic template
at runtime.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> CamelScalateResourceUri </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> An URI for the template resource to use instead of the endpoint
configured. </td>
</tr>
<tr>
<td class='confluenceTd'> CamelScalateTemplate </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The template to use instead of the endpoint configured. </td>
</tr>
</tbody></table>
</div>
</div>

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

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

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

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

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

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

<p>It's possible to specify what template the component should use dynamically via a
header, so for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:in"</span>).
  setHeader(<span class="code-quote">"CamelScalateResourceUri"</span>).constant(<span
class="code-quote">"path/to/my/template.scaml"</span>).
  to(<span class="code-quote">"scalate:dummy"</span>);
</pre>
</div></div>

<p>It's possible to specify a template directly as a header the component should use
dynamically via a header, so for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:in"</span>).
  setHeader(<span class="code-quote">"CamelScalateTemplate"</span>).constant(<span
class="code-quote">"&lt;%@ attribute body: <span class="code-object">Object</span>
%&gt;\nHi <span class="code-keyword">this</span> is a scalate template that
can <span class="code-keyword">do</span> templating ${body}"</span>).
  to(<span class="code-quote">"scalate:dummy"</span>);
</pre>
</div></div>

<h3><a name="Scalate-TheEmailSample"></a>The Email Sample</h3>
<p>In this sample we want to use Scalate templating for an order confirmation email.
The email template is laid out in Scalate as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;%@ attribute in: org.apache.camel.scala.RichMessage %&gt;
Dear ${in(<span class="code-quote">"lastName"</span>}, ${in(<span class="code-quote">"firstName"</span>)}

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

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

<h3><a name="Scalate-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>

     </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message