Modified: websites/production/camel/content/velocity.html
==============================================================================
--- websites/production/camel/content/velocity.html (original)
+++ websites/production/camel/content/velocity.html Tue Jul 8 08:18:06 2014
@@ -86,151 +86,70 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Velocity-Velocity">Velocity</h2>
-
-<p>The <strong>velocity:</strong> component allows you to process a message
using an <a shape="rect" class="external-link"
href="http://velocity.apache.org/">Apache Velocity</a> template. This can be
ideal when using <a shape="rect" href="templating.html">Templating</a> to
generate responses for requests.</p>
-
-<p>Maven users will need to add the following dependency to their
<code>pom.xml</code> for this component:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[
-<dependency>
+<div class="wiki-content maincontent"><h2
id="Velocity-Velocity">Velocity</h2><p>The <strong>velocity:</strong> component
allows you to process a message using an <a shape="rect" class="external-link"
href="http://velocity.apache.org/">Apache Velocity</a> template. This can be
ideal when using <a shape="rect" href="templating.html">Templating</a> to
generate responses for requests.</p><p>Maven users will need to add the
following dependency to their <code>pom.xml</code> for this component:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-velocity</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
]]></script>
-</div></div>
-
-<h3 id="Velocity-URIformat">URI format</h3>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-velocity:templateName[?options]
+</div></div><h3 id="Velocity-URIformat">URI format</h3><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[velocity:templateName[?options]
]]></script>
-</div></div>
-
-<p>Where <strong>templateName</strong> is the classpath-local URI of the
template to invoke; or the complete URL of the remote template (eg: <a
shape="rect" class="external-link" href="file://folder/myfile.vm"
rel="nofollow">file://folder/myfile.vm</a>).</p>
-
-<p>You can append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p>
-
-<h3 id="Velocity-Options">Options</h3>
-<div class="confluenceTableSmall">
+</div></div><p>Where <strong>templateName</strong> is the classpath-local URI
of the template to invoke; or the complete URL of the remote template (eg: <a
shape="rect" class="external-link" href="file://folder/myfile.vm"
rel="nofollow">file://folder/myfile.vm</a>).</p><p>You can append query options
to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="Velocity-Options">Options</h3><div class="confluenceTableSmall">
<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p> Option </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> Default </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>loaderCache</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>true</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Velocity based file loader
cache. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>contentCache</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>true</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Cache for the resource content when it is loaded. <br
clear="none" class="atl-forced-newline"> Note : as of Camel 2.9 cached resource
content can be cleared via JMX using the endpoint's
<code>clearContentCache</code> operation. </p></td></t
r><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>encoding</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Character encoding of the resource content.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>propertiesFile</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> New option in Camel 2.1: The URI of the properties
file which is used for VelocityEngine initialization.
</p></td></tr></tbody></table>
-</div>
-
-<h3 id="Velocity-MessageHeaders">Message Headers</h3>
-
-<p>The velocity component sets a couple headers on the message (you can't set
these yourself and from Camel 2.1 velocity component will not set these headers
which will cause some side effect on the dynamic template support):</p>
-<div class="confluenceTableSmall">
+</div><h3 id="Velocity-MessageHeaders">Message Headers</h3><p>The velocity
component sets a couple headers on the message (you can't set these yourself
and from Camel 2.1 velocity component will not set these headers which will
cause some side effect on the dynamic template support):</p><div
class="confluenceTableSmall">
<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p> Header </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>CamelVelocityResourceUri</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The
<strong>templateName</strong> as a <code>String</code> object.
</p></td></tr></tbody></table>
-</div>
-
-<p>Headers set during the Velocity evaluation are returned to the message and
added as headers. Then its kinda possible to return values from Velocity to the
Message.</p>
-
-<p>For example, to set the header value of <code>fruit</code> in the Velocity
template <code>.tm</code>:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-$in.setHeader('fruit', 'Apple')
+</div><p>Headers set during the Velocity evaluation are returned to the
message and added as headers. Then its kinda possible to return values from
Velocity to the Message.</p><p>For example, to set the header value of
<code>fruit</code> in the Velocity template <code>.tm</code>:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[$in.setHeader('fruit',
'Apple')
]]></script>
-</div></div>
-
-<p>The <code>fruit</code> header is now accessible from the
<code>message.out.headers</code>.</p>
-
-<h3 id="Velocity-VelocityContext">Velocity Context</h3>
-<p>Camel will provide exchange information in the Velocity context (just a
<code>Map</code>). The <code>Exchange</code> is transfered as:</p>
-<div class="confluenceTableSmall">
+</div></div><p>The <code>fruit</code> header is now accessible from the
<code>message.out.headers</code>.</p><h3 id="Velocity-VelocityContext">Velocity
Context</h3><p>Camel will provide exchange information in the Velocity context
(just a <code>Map</code>). The <code>Exchange</code> is transfered as:</p><div
class="confluenceTableSmall">
<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p> key </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> value </p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>exchange</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The <code>Exchange</code> itself.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>exchange.properties</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The <code>Exchange</code> properties.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>headers</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The headers of the In message. </p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>camelContext</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The Camel Context
intance. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"
><p> <code>request</code> </p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p> The In message. </p></td></tr><tr><td colspan="1"
>rowspan="1" class="confluenceTd"><p> <code>in</code> </p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p> The In message. </p></td></tr><tr><td
>colspan="1" rowspan="1" class="confluenceTd"><p> <code>body</code>
></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The In message
>body. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
><code>out</code> </p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p> The Out message (only for InOut message exchange
>pattern). </p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p> <code>response</code> </p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p> The Out message (only for InOut message
>exchange pattern). </p></td></tr></tbody></table>
-</div>
-
-<h3 id="Velocity-Hotreloading">Hot reloading</h3>
-<p>The Velocity template resource is, by default, hot reloadable for both file
and classpath resources (expanded jar). If you set
<code>contentCache=true</code>, Camel will only load the resource once, and
thus hot reloading is not possible. This scenario can be used in production,
when the resource never changes.</p>
-
-<h3 id="Velocity-Dynamictemplates">Dynamic templates</h3>
-<p><strong>Available as of Camel 2.1</strong><br clear="none">
-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><p>Since Camel-2.14, you can setup a custom Velocity Context yourself by
setting the message header <strong>CamelVelocityContext </strong>just like
this</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[ VelocityContext velocityContext = new
VelocityContext(variableMap);
+ exchange.getIn().setHeader("CamelVelocityContext",
velocityContext);
+]]></script>
+</div></div><p> </p><h3 id="Velocity-Hotreloading">Hot
reloading</h3><p>The Velocity template resource is, by default, hot reloadable
for both file and classpath resources (expanded jar). If you set
<code>contentCache=true</code>, Camel will only load the resource once, and
thus hot reloading is not possible. This scenario can be used in production,
when the resource never changes.</p><h3 id="Velocity-Dynamictemplates">Dynamic
templates</h3><p><strong>Available as of Camel 2.1</strong><br clear="none">
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">
<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p> Header </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> Type </p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> CamelVelocityResourceUri </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> String </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel 2.1:</strong> A
URI for the template resource to use instead of the endpoint configured.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
CamelVelocityTemplate </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> String </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <strong>Camel 2.1:</strong> The template to use
instead of the endpoint configured. </p></td></tr></tbody></table>
-</div>
-
-<h3 id="Velocity-Samples">Samples</h3>
-
-<p>For example you could use something like</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
+</div><h3 id="Velocity-Samples">Samples</h3><p>For example you could use
something like</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm");
]]></script>
-</div></div>
-
-<p>To use a Velocity template to formulate a response to a message for InOut
message exchanges (where there is a <code>JMSReplyTo</code> 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 pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
+</div></div><p>To use a Velocity template to formulate a response to a message
for InOut message exchanges (where there is a <code>JMSReplyTo</code>
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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm").
to("activemq:Another.Queue");
]]></script>
-</div></div>
-
-<p>And to use the content cache, e.g. for use in production, where the
<code>.vm</code> template never changes:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
+</div></div><p>And to use the content cache, e.g. for use in production, where
the <code>.vm</code> template never changes:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
]]></script>
-</div></div>
-
-<p>And a file based resource:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
+</div></div><p>And a file based resource:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("activemq:My.Queue").
to("velocity:file://myfolder/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
]]></script>
-</div></div>
-
-<p>In <strong>Camel 2.1</strong> it's possible to specify what template the
component should use dynamically via a header, so for example:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("direct:in").
+</div></div><p>In <strong>Camel 2.1</strong> it's possible to specify what
template the component should use dynamically via a header, so for
example:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("direct:in").
setHeader("CamelVelocityResourceUri").constant("path/to/my/template.vm").
to("velocity:dummy");
]]></script>
-</div></div>
-
-<p>In <strong>Camel 2.1</strong> 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 pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-from("direct:in").
+</div></div><p>In <strong>Camel 2.1</strong> 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 pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[from("direct:in").
setHeader("CamelVelocityTemplate").constant("Hi this is a
velocity template that can do templating ${body}").
to("velocity:dummy");
]]></script>
-</div></div>
-
-<h3 id="Velocity-TheEmailSample">The Email Sample</h3>
-<p>In this sample we want to use Velocity templating for an order confirmation
email. The email template is laid out in Velocity as:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-Dear ${headers.lastName}, ${headers.firstName}
+</div></div><h3 id="Velocity-TheEmailSample">The Email Sample</h3><p>In this
sample we want to use Velocity templating for an order confirmation email. The
email template is laid out in Velocity as:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[Dear ${headers.lastName}, ${headers.firstName}
Thanks for the order of ${headers.item}.
Regards Camel Riders Bookstore
${body}
]]></script>
-</div></div>
-
-<p>And the java code:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><p>And the java code:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
private Exchange createLetter() {
Exchange exchange =
context.getEndpoint("direct:a").createExchange();
@@ -261,9 +180,7 @@ protected RouteBuilder createRouteBuilde
};
}
]]></script>
-</div></div>
-
-<h3 id="Velocity-SeeAlso">See Also</h3>
+</div></div><p></p><h3 id="Velocity-SeeAlso">See Also</h3>
<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul></div>
</td>
<td valign="top">