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 Wed, 03 Feb 2010 17:40:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Scalate">Scalate</a></h2>
    <h4>Page  <b>added</b> by             <a href="http://cwiki.apache.org/confluence/display/~jstrachan">James
Strachan</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="Scalate-Scalate"></a>Scalate</h2>

<p>The <b>scalate:</b> component allows you to process a message using <a
href="http://scalate.fusesource.org/" 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>

<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"
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>
<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'> Camel 2.0: 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'> Camel 2.0: The <b>templateName</b> as a <tt>String</tt>
object. </td>
</tr>
</tbody></table>

<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">
$in.setHeader('fruit', 'Apple')
</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>

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

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

<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'> <b>Camel 2.1:</b> A 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'> <b>Camel 2.1:</b> The template to use instead
of the endpoint configured. </td>
</tr>
</tbody></table>

<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.haml"</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.vm"</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("firstName)}

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

Mime
View raw message