Modified: websites/production/camel/content/velocity.html
==============================================================================
--- websites/production/camel/content/velocity.html (original)
+++ websites/production/camel/content/velocity.html Fri Aug 25 09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Velocity
@@ -86,106 +75,40 @@
<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="brush: xml; gutter: false; theme: Default"
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><parameter
ac:name="">xml</parameter><plain-text-body><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="brush: java; gutter: false; theme: Default"
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
class="table-wrap"><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></tr><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></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 class="table-wrap"><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><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelVelocitySupplementalContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong>
To add additional information to the used Velo
cityContext. The value of this header should be a <code>Map</code> with
key/values that will added (override any existing key with the same name).<br
clear="none">This can be used to pre setup some common key/values you want to
reuse in your velocity endpoints.</p></td></tr></tbody></table></div></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="brush: java; gutter: false; theme: Default"
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 class="table-wrap"><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</c
ode></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
instance.</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></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="brush: java; gutter: false; theme: Default"
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"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1" class="co
nfluenceTh"><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></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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
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="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[Dear ${headers.lastName}, ${headers.firstName}
+</plain-text-body><h3 id="Velocity-URIformat">URI
format</h3><plain-text-body>velocity:templateName[?options]
+</plain-text-body><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><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><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="confl
uenceTd"><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></tr><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></rich-text-body><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><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><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><tr><td colspan="1" r
owspan="1"
class="confluenceTd"><p><code>CamelVelocitySupplementalContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong>
To add additional information to the used VelocityContext. The value of this
header should be a <code>Map</code> with key/values that will added (override
any existing key with the same name).<br clear="none">This can be used to pre
setup some common key/values you want to reuse in your velocity
endpoints.</p></td></tr></tbody></table></div></rich-text-body><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><plain-text-body>$in.setHeader("fruit", "Apple")
+</plain-text-body><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><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><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" rowsp
an="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
instance.</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 InOu
t 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></rich-text-body><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><parameter ac:name="language">java</parameter><plain-text-body>
VelocityContext velocityContext = new VelocityContext(variableMap);
+ exchange.getIn().setHeader("CamelVelocityContext", velocityContext);
+</plain-text-body><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><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Heade
r</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></rich-text-body><h3
id="Velocity-Samples">Samples</h3><p>For example you could use something
like</p><plain-text-body>from("activemq:My.Queue").
+ to("velocity:com/acme/MyResponse.vm");
+</plain-text-body><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><plain-text-body>from("activemq:My.Queue").
+ to("velocity:com/acme/MyResponse.vm").
+ to("activemq:Another.Queue");
+</plain-text-body><p>And to use the content cache, e.g. for use in production,
where the <code>.vm</code> template never
changes:</p><plain-text-body>from("activemq:My.Queue").
+ to("velocity:com/acme/MyResponse.vm?contentCache=true").
+ to("activemq:Another.Queue");
+</plain-text-body><p>And a file based
resource:</p><plain-text-body>from("activemq:My.Queue").
+ to("velocity:file://myfolder/MyResponse.vm?contentCache=true").
+ to("activemq:Another.Queue");
+</plain-text-body><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><plain-text-body>from("direct:in").
+ setHeader("CamelVelocityResourceUri").constant("path/to/my/template.vm").
+ to("velocity:dummy");
+</plain-text-body><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><plain-text-body>from("direct:in").
+ setHeader("CamelVelocityTemplate").constant("Hi this is a velocity template
that can do templating ${body}").
+ to("velocity:dummy");
+</plain-text-body><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><plain-text-body>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">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-private Exchange createLetter() {
- Exchange exchange =
context.getEndpoint("direct:a").createExchange();
- Message msg = exchange.getIn();
- msg.setHeader("firstName", "Claus");
- msg.setHeader("lastName", "Ibsen");
- msg.setHeader("item", "Camel in Action");
- msg.setBody("PS: Next beer is on me, James");
- return exchange;
-}
-
-@Test
-public void testVelocityLetter() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMessageCount(1);
- mock.message(0).body(String.class).contains("Thanks for the order of
Camel in Action");
-
- template.send("direct:a", createLetter());
-
- mock.assertIsSatisfied();
-}
-
-protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
-
from("direct:a").to("velocity:org/apache/camel/component/velocity/letter.vm").to("mock:result");
- }
- };
-}
-]]></script>
-</div></div><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>
+</plain-text-body><p>And the java
code:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterTest.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/xmlrpc.html
==============================================================================
--- websites/production/camel/content/xmlrpc.html (original)
+++ websites/production/camel/content/xmlrpc.html Fri Aug 25 09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: XmlRpc
@@ -86,16 +75,13 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="XmlRpc-XmlRpcComponent">XmlRpc
Component</h2><p><strong>Available as of Camel 2.11</strong></p><p>This
component provides a dataformat for xml, which allows serialization and
deserialization of request messages and response message using Apache XmlRpc's
binary dataformat. You can also invoke the XMLRPC Service through the
camel-xmlrpc producer.</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="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2 id="XmlRpc-XmlRpcComponent">XmlRpc
Component</h2><p><strong>Available as of Camel 2.11</strong></p><p>This
component provides a dataformat for xml, which allows serialization and
deserialization of request messages and response message using Apache XmlRpc's
binary dataformat. You can also invoke the XMLRPC Service through the
camel-xmlrpc producer.</p><p>Maven users will need to add the following
dependency to their <code>pom.xml</code> for this component:</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmlrpc</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div><h3 id="XmlRpc-XmlRpcOverview">XmlRpc Overview</h3><p>It's a <a
shape="rect" class="external-link" href="http://xmlrpc.scripting.com/spec"
rel="nofollow">spec</a> and a set of implementations that allow software
running on disparate operating systems, running in different environments to
make procedure calls over the Internet.</p><p>It's remote procedure calling
using HTTP as the transport and XML as the encoding. XML-RPC is designed to be
as simple as possible, while allowing complex data structures to be
transmitted, processed and returned.</p><p>An example of a typical XML-RPC
request would be:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<?xml version="1.0"?>
+</plain-text-body><h3 id="XmlRpc-XmlRpcOverview">XmlRpc Overview</h3><p>It's a
<a shape="rect" class="external-link" href="http://xmlrpc.scripting.com/spec"
rel="nofollow">spec</a> and a set of implementations that allow software
running on disparate operating systems, running in different environments to
make procedure calls over the Internet.</p><p>It's remote procedure calling
using HTTP as the transport and XML as the encoding. XML-RPC is designed to be
as simple as possible, while allowing complex data structures to be
transmitted, processed and returned.</p><p>An example of a typical XML-RPC
request would be:</p><plain-text-body><?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
@@ -104,9 +90,7 @@
</param>
</params>
</methodCall>
-]]></script>
-</div></div><p>An example of a typical XML-RPC response would be:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<?xml version="1.0"?>
+</plain-text-body><p>An example of a typical XML-RPC response would
be:</p><plain-text-body><?xml version="1.0"?>
<methodResponse>
<params>
<param>
@@ -114,9 +98,7 @@
</param>
</params>
</methodResponse>
-]]></script>
-</div></div><p>A typical XML-RPC fault would be:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<?xml version="1.0"?>
+</plain-text-body><p>A typical XML-RPC fault would
be:</p><plain-text-body><?xml version="1.0"?>
<methodResponse>
<fault>
<value>
@@ -133,72 +115,13 @@
</value>
</fault>
</methodResponse>
-]]></script>
-</div></div><h3 id="XmlRpc-URIformat">URI format</h3><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[xmlrpc://serverUri[?options]
-]]></script>
-</div></div><h3 id="XmlRpc-Options">Options</h3><div
class="confluenceTableSmall">
+</plain-text-body><h3 id="XmlRpc-URIformat">URI
format</h3><plain-text-body>xmlrpc://serverUri[?options]
+</plain-text-body><h3 id="XmlRpc-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body>
<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p> Property </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>basicEncoding</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Sets the encoding for basic authentication, null means
UTF-8 is chosen. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>basicUserName</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The user name for basic authentication.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>basicPassword</code> </p></td><td colspan="1" rowspan="1
" class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The password for basic authentication.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>clientConfigurer</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The reference id of the XmlRpcClient configurer which
implement the interface of XmlRpcClientConfigurer to setup the XmlRpcClient as
user wants. The value should be start with "#" such as
"#myConfigurer"</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>connectionTimeout</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>0</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Set the connection timeout in
milliseconds, 0 is to disable it</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>contentLengthOptional</co
de> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>false</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> whether a "Content-Length" header may be omitted. The
XML-RPC specification demands, that such a header be present.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>enabledForExceptions</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>false</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> whether the response should contain a
"faultCause" element in case of errors. The "faultCause" is an exception, which
the server has trapped and written into a byte stream as a serializable object.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>enabledForExtensions</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>false</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> whether extensions are enabled. By defaul
t, the client or server is strictly compliant to the XML-RPC specification and
extensions are disabled.</p></td></tr><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> Sets the requests encoding, null means
UTF-8 is chosen. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>gzipCompressing</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>false</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Whether gzip compression is
being used for transmitting the request. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>gzipRequesting</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>false</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Whether gzip
compression is being used for transm
itting the request. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>replyTimeout</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>0</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> Set the reply timeout in milliseconds, 0
is to disable it. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>userAgent</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>null</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The http user agent header to set when
doing xmlrpc requests </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>defaultMethodName</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>null</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Since <strong>Camel
2.14.0</strong>: The method name which would be used for the xmlrpc requests by
default, if the Message header CamelXmlRp
cMethodName is not set. </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="XmlRpc-MessageHeaders">Message Headers</h3><p>Camel XmlRpc uses these
headers.</p><div class="confluenceTableSmall">
+</rich-text-body><h3 id="XmlRpc-MessageHeaders">Message Headers</h3><p>Camel
XmlRpc uses these headers.</p><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body>
<div class="table-wrap"><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>CamelXmlRpcMethodName</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The XmlRpc method name which will be use for invoking
the XmlRpc server. </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="XmlRpc-UsingtheXmlRpcdataformat">Using the XmlRpc data
format</h3><p>As the XmlRpc message could be request or response, when you use
the XmlRpcDataFormat, you need to specify the dataformat is for request or
not.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
-
- <!-- we define the xml rpc data formats to be used -->
- <dataFormats>
- <xmlrpc id="xmlrpcRequest" request="true"/>
- <xmlrpc id="xmlrpcResponse" request="false"/>
- </dataFormats>
-
- <route>
- <from uri="direct:request"/>
- <marshal ref="xmlrpcRequest"/>
- <unmarshal>
- <xmlrpc request="true"/>
- </unmarshal>
- <to uri="mock:request" />
- </route>
-
- <route>
- <from uri="direct:response"/>
- <marshal>
- <xmlrpc request="false"/>
- </marshal>
- <unmarshal ref="xmlrpcResponse"/>
- <to uri="mock:response" />
- </route>
-</camelContext>
-]]></script>
-</div></div><h3 id="XmlRpc-InvokeXmlRpcServicefromClient">Invoke XmlRpc
Service from Client</h3><p>To invoke the XmlRpc service, you need to specify
the methodName on the message header and put the parameters into the message
body like below code, then you can get the result message as you want. If the
fault message is return, you should get an exception which cause if
XmlRpcException.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ String response =
template.requestBodyAndHeader(xmlRpcServiceAddress, new
Object[]{"me"}, XmlRpcConstants.METHOD_NAME, "hello",
String.class);
-]]></script>
-</div></div><h3 id="XmlRpc-HowtoconfiguretheXmlRpcClientwithJavacode">How to
configure the XmlRpcClient with Java code</h3><p>camel-xmlrpc provides a
pluggable strategy for configuring the XmlRpcClient used by the component, user
just to implement the <strong>XmlRpcClientConfigurer</strong> interface and can
configure the XmlRpcClient as he wants. The clientConfigure instance reference
can be set through the uri option clientConfigure.</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-
-public class MyClientConfigurer implements XmlRpcClientConfigurer {
-
- @Override
- public void configureXmlRpcClient(XmlRpcClient client) {
- // get the configure first
- XmlRpcClientConfigImpl clientConfig =
(XmlRpcClientConfigImpl)client.getClientConfig();
- // change the value of clientConfig
- clientConfig.setEnabledForExtensions(true);
- // set the option on the XmlRpcClient
- client.setMaxThreads(10);
- }
-
-}
-]]></script>
-</div></div></div>
+</rich-text-body><h3 id="XmlRpc-UsingtheXmlRpcdataformat">Using the XmlRpc
data format</h3><p>As the XmlRpc message could be request or response, when you
use the XmlRpcDataFormat, you need to specify the dataformat is for request or
not.</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-xmlrpc/src/test/resources/org/apache/camel/dataformat/xmlrpc/SpringXmlRpcDataFormatTest.xml}</plain-text-body><h3
id="XmlRpc-InvokeXmlRpcServicefromClient">Invoke XmlRpc Service from
Client</h3><p>To invoke the XmlRpc service, you need to specify the methodName
on the message header and put the parameters into the message body like below
code, then you can get the result message as you want. If the fault message is
return, you should get an exception which cause if
XmlRpcException.</p><plain-text-body> String response =
template.requestBodyAndHeader(xmlRpcServiceAddress, new Object[]{"me"},
XmlRpcConstants.METHOD_NAME, "hello", String.class);
+</plain-text-body><h3
id="XmlRpc-HowtoconfiguretheXmlRpcClientwithJavacode">How to configure the
XmlRpcClient with Java code</h3><p>camel-xmlrpc provides a pluggable strategy
for configuring the XmlRpcClient used by the component, user just to implement
the <strong>XmlRpcClientConfigurer</strong> interface and can configure the
XmlRpcClient as he wants. The clientConfigure instance reference can be set
through the uri option
clientConfigure.</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/MyClientConfigurer.java}</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/xquery.html
==============================================================================
--- websites/production/camel/content/xquery.html (original)
+++ websites/production/camel/content/xquery.html Fri Aug 25 09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: XQuery
@@ -86,78 +75,45 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="XQuery-XQuery">XQuery</h2><p>Camel supports <a shape="rect"
class="external-link" href="http://www.w3.org/TR/xquery/"
rel="nofollow">XQuery</a> to allow an <a shape="rect"
href="expression.html">Expression</a> or <a shape="rect"
href="predicate.html">Predicate</a> to be used in the <a shape="rect"
href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml
Configuration</a>. For example you could use XQuery to create an <a
shape="rect" href="predicate.html">Predicate</a> in a <a shape="rect"
href="message-filter.html">Message Filter</a> or as an <a shape="rect"
href="expression.html">Expression</a> for a <a shape="rect"
href="recipient-list.html">Recipient List</a>.</p><h3
id="XQuery-Options">Options</h3><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Def
ault Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>allowStAX</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.8.3/2.9:</strong> Whether to allow using StAX as the
<code>javax.xml.transform.Source</code>.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="XQuery-Examples">Examples</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("queue:foo").filter().
- xquery("//foo").
- to("queue:bar")
-]]></script>
-</div></div><p>You can also use functions inside your query, in which case you
need an explicit type conversion (or you will get a org.w3c.dom.DOMException:
HIERARCHY_REQUEST_ERR) by passing the Class as a second argument to the
<strong>xquery()</strong> method.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start").
- recipientList().xquery("concat('mock:foo.',
/person/@city)", String.class);
-]]></script>
-</div></div><h3 id="XQuery-Variables">Variables</h3><p>The IN message body
will be set as the <code>contextItem</code>. Besides this these Variables is
also added as parameters:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Variable</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>exchange</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Exchange</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The current Exchange</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>in.body</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The In message's body</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>out.body</p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p>Object</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The OUT message's body (if
any)</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>in.headers.*</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>You can access the value of exchange.in.headers with
key <strong>foo</strong> by using the variable which name is
in.headers.foo</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>out.headers.*</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>You can access the value of exchange.out.headers with
key <strong>foo</strong> by using the variable which name is out.headers.foo
variable</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>key name</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Object</p></td>
<td colspan="1" rowspan="1" class="confluenceTd"><p>Any exchange.properties
and exchange.in.headers and any additional parameters set using
<code>setParameters(Map)</code>. These parameters is added with they own key
name, for instance if there is an IN header with the key name
<strong>foo</strong> then its added as
<strong>foo</strong>.</p></td></tr></tbody></table></div><h3
id="XQuery-UsingXMLconfiguration">Using XML configuration</h3><p>If you prefer
to configure your routes in your <a shape="rect" href="spring.html">Spring</a>
XML file then you can use XPath expressions as follows</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<beans
xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:foo="http://example.com/person"
- xsi:schemaLocation="
+<div class="wiki-content maincontent"><h2
id="XQuery-XQuery">XQuery</h2><p>Camel supports <a shape="rect"
class="external-link" href="http://www.w3.org/TR/xquery/"
rel="nofollow">XQuery</a> to allow an <a shape="rect"
href="expression.html">Expression</a> or <a shape="rect"
href="predicate.html">Predicate</a> to be used in the <a shape="rect"
href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml
Configuration</a>. For example you could use XQuery to create an <a
shape="rect" href="predicate.html">Predicate</a> in a <a shape="rect"
href="message-filter.html">Message Filter</a> or as an <a shape="rect"
href="expression.html">Expression</a> for a <a shape="rect"
href="recipient-list.html">Recipient List</a>.</p><h3
id="XQuery-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1
" rowspan="1" class="confluenceTh"><p>Default Value</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>allowStAX</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8.3/2.9:</strong> Whether
to allow using StAX as the
<code>javax.xml.transform.Source</code>.</p></td></tr></tbody></table></div></rich-text-body><h3
id="XQuery-Examples">Examples</h3><plain-text-body>from("queue:foo").filter().
+ xquery("//foo").
+ to("queue:bar")
+</plain-text-body><p>You can also use functions inside your query, in which
case you need an explicit type conversion (or you will get a
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR) by passing the Class as a
second argument to the <strong>xquery()</strong>
method.</p><plain-text-body>from("direct:start").
+ recipientList().xquery("concat('mock:foo.', /person/@city)", String.class);
+</plain-text-body><h3 id="XQuery-Variables">Variables</h3><p>The IN message
body will be set as the <code>contextItem</code>. Besides this these Variables
is also added as parameters:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Variable</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>exchange</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Exchange</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The current Exchange</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>in.body</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The In message's body</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>out.body</p></td><td co
lspan="1" rowspan="1" class="confluenceTd"><p>Object</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The OUT message's body (if
any)</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>in.headers.*</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>You can access the value of exchange.in.headers with
key <strong>foo</strong> by using the variable which name is
in.headers.foo</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>out.headers.*</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Object</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>You can access the value of exchange.out.headers with
key <strong>foo</strong> by using the variable which name is out.headers.foo
variable</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>key name</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Object</p
></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Any
>exchange.properties and exchange.in.headers and any additional parameters set
>using <code>setParameters(Map)</code>. These parameters is added with they
>own key name, for instance if there is an IN header with the key name
><strong>foo</strong> then its added as
><strong>foo</strong>.</p></td></tr></tbody></table></div><h3
>id="XQuery-UsingXMLconfiguration">Using XML configuration</h3><p>If you
>prefer to configure your routes in your <a shape="rect"
>href="spring.html">Spring</a> XML file then you can use XPath expressions as
>follows</p><parameter
>ac:name="lang">xml</parameter><plain-text-body><beans
>xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:foo="http://example.com/person"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
+ <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="activemq:MyQueue"/>
+ <from uri="activemq:MyQueue"/>
<filter>
- <xquery>/foo:person[@name='James']</xquery>
- <to uri="mqseries:SomeOtherQueue"/>
+ <xquery>/foo:person[@name='James']</xquery>
+ <to uri="mqseries:SomeOtherQueue"/>
</filter>
</route>
</camelContext>
</beans>
-]]></script>
-</div></div><p>Notice how we can reuse the namespace prefixes,
<strong>foo</strong> in this case, in the XPath expression for easier namespace
based XQuery expressions!</p><p>When you use functions in your XQuery
expression you need an explicit type conversion which is done in the xml
configuration via the <strong>@type</strong> attribute:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <xquery
type="java.lang.String">concat('mock:foo.',
/person/@city)</xquery>
-]]></script>
-</div></div><h3 id="XQuery-UsingXQueryastransformation">Using XQuery as
transformation</h3><p>We can do a message translation using transform or
setBody in the route, as shown below:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start").
- transform().xquery("/people/person");]]></script>
-</div></div><p>Notice that xquery will use DOMResult by default, so if we want
to grab the value of the person node, using text() we need to tell xquery to
use String as result type, as shown:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start").
- transform().xquery("/people/person/text()",
String.class);]]></script>
-</div></div><p> </p><h3 id="XQuery-UsingXQueryasanendpoint">Using XQuery
as an endpoint</h3><p>Sometimes an XQuery expression can be quite large; it can
essentally be used for <a shape="rect" href="templating.html">Templating</a>.
So you may want to use an <a shape="rect" href="xquery-endpoint.html">XQuery
Endpoint</a> so you can route using XQuery templates.</p><p>The following
example shows how to take a message of an ActiveMQ queue (MyQueue) and
transform it using XQuery and send it to MQSeries.</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
+</plain-text-body><p>Notice how we can reuse the namespace prefixes,
<strong>foo</strong> in this case, in the XPath expression for easier namespace
based XQuery expressions!</p><p>When you use functions in your XQuery
expression you need an explicit type conversion which is done in the xml
configuration via the <strong>@type</strong> attribute:</p><parameter
ac:name="lang">xml</parameter><plain-text-body> <xquery
type="java.lang.String">concat('mock:foo.', /person/@city)</xquery>
+</plain-text-body><h3 id="XQuery-UsingXQueryastransformation">Using XQuery as
transformation</h3><p>We can do a message translation using transform or
setBody in the route, as shown below:</p><plain-text-body>from("direct:start").
+ transform().xquery("/people/person");</plain-text-body><p>Notice that
xquery will use DOMResult by default, so if we want to grab the value of the
person node, using text() we need to tell xquery to use String as result type,
as shown:</p><plain-text-body>from("direct:start").
+ transform().xquery("/people/person/text()",
String.class);</plain-text-body><p> </p><h3
id="XQuery-UsingXQueryasanendpoint">Using XQuery as an
endpoint</h3><p>Sometimes an XQuery expression can be quite large; it can
essentally be used for <a shape="rect" href="templating.html">Templating</a>.
So you may want to use an <a shape="rect" href="xquery-endpoint.html">XQuery
Endpoint</a> so you can route using XQuery templates.</p><p>The following
example shows how to take a message of an ActiveMQ queue (MyQueue) and
transform it using XQuery and send it to MQSeries.</p><plain-text-body>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
- <from uri="activemq:MyQueue"/>
- <to uri="xquery:com/acme/someTransform.xquery"/>
- <to uri="mqseries:SomeOtherQueue"/>
+ <from uri="activemq:MyQueue"/>
+ <to uri="xquery:com/acme/someTransform.xquery"/>
+ <to uri="mqseries:SomeOtherQueue"/>
</route>
</camelContext>
-]]></script>
-</div></div><h3 id="XQuery-Examples.1">Examples</h3><p>Here is a simple <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryFilterTest.java">example</a>
using an XQuery expression as a predicate in a <a shape="rect"
href="message-filter.html">Message Filter</a></p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start").filter().xquery("/person[@name='James']").to("mock:result");
-]]></script>
-</div></div><p>This <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryWithNamespacesFilterTest.java">example</a>
uses XQuery with namespaces as a predicate in a <a shape="rect"
href="message-filter.html">Message Filter</a></p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-Namespaces ns = new Namespaces("c",
"http://acme.com/cheese");
-
-from("direct:start").
- filter().xquery("/c:person[@name='James']", ns).
- to("mock:result");
-]]></script>
-</div></div><h3 id="XQuery-LearningXQuery">Learning XQuery</h3><p>XQuery is a
very powerful language for querying, searching, sorting and returning XML. For
help learning XQuery try these tutorials</p><ul><li>Mike Kay's <a shape="rect"
class="external-link" href="http://www.stylusstudio.com/xquery_primer.html"
rel="nofollow">XQuery Primer</a></li><li>the W3Schools <a shape="rect"
class="external-link" href="http://www.w3schools.com/xquery/default.asp"
rel="nofollow">XQuery Tutorial</a></li></ul><p>You might also find the <a
shape="rect" class="external-link" href="http://www.w3.org/TR/xpath-functions/"
rel="nofollow">XQuery function reference</a> useful</p><h3
id="XQuery-Loadingscriptfromexternalresource">Loading script from external
resource</h3><p><strong>Available as of Camel 2.11</strong></p><p>You can
externalize the script and have Camel load it from a resource such as
<code>"classpath:"</code>, <code>"file:"</code>, or <code>"http:"</code>.<br
clear="none"> This is done using
the following syntax: <code>"resource:scheme:location"</code>, eg to refer to
a file on the classpath you can do:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[.setHeader("myHeader").xquery("resource:classpath:myxquery.txt",
String.class)
-]]></script>
-</div></div><h3 id="XQuery-Dependencies">Dependencies</h3><p>To use XQuery in
your camel routes you need to add the a dependency on
<strong>camel-saxon</strong> which implements the XQuery language.</p><p>If you
use maven you could just add the following to your pom.xml, substituting the
version number for the latest & greatest release (see <a shape="rect"
href="download.html">the download page for the latest versions</a>).</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+</plain-text-body><h3 id="XQuery-Examples.1">Examples</h3><p>Here is a simple
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryFilterTest.java">example</a>
using an XQuery expression as a predicate in a <a shape="rect"
href="message-filter.html">Message
Filter</a></p><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryFilterTest.java}</plain-text-body><p>This
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryWithNamespacesFilterTest.java">example</a>
uses XQuery with namespaces as a predicate in a <a shape="rect"
href="message-filter.html">Message
Filter</a></p><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/bu
ilder/saxon/XQueryWithNamespacesFilterTest.java}</plain-text-body><h3
id="XQuery-LearningXQuery">Learning XQuery</h3><p>XQuery is a very powerful
language for querying, searching, sorting and returning XML. For help learning
XQuery try these tutorials</p><ul><li>Mike Kay's <a shape="rect"
class="external-link" href="http://www.stylusstudio.com/xquery_primer.html"
rel="nofollow">XQuery Primer</a></li><li>the W3Schools <a shape="rect"
class="external-link" href="http://www.w3schools.com/xquery/default.asp"
rel="nofollow">XQuery Tutorial</a></li></ul><p>You might also find the <a
shape="rect" class="external-link" href="http://www.w3.org/TR/xpath-functions/"
rel="nofollow">XQuery function reference</a> useful</p><h3
id="XQuery-Loadingscriptfromexternalresource">Loading script from external
resource</h3><p><strong>Available as of Camel 2.11</strong></p><p>You can
externalize the script and have Camel load it from a resource such as
<code>"classpath:"</code>, <code>"file:"</code>, or <co
de>"http:"</code>.<br clear="none"> This is done using the following syntax:
<code>"resource:scheme:location"</code>, eg to refer to a file on the classpath
you can
do:</p><plain-text-body>.setHeader("myHeader").xquery("resource:classpath:myxquery.txt",
String.class)
+</plain-text-body><h3 id="XQuery-Dependencies">Dependencies</h3><p>To use
XQuery in your camel routes you need to add the a dependency on
<strong>camel-saxon</strong> which implements the XQuery language.</p><p>If you
use maven you could just add the following to your pom.xml, substituting the
version number for the latest & greatest release (see <a shape="rect"
href="download.html">the download page for the latest
versions</a>).</p><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-saxon</artifactId>
<version>x.x.x</version>
</dependency>
-]]></script>
-</div></div></div>
+</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">