Modified: websites/production/camel/content/rss.html
==============================================================================
--- websites/production/camel/content/rss.html (original)
+++ websites/production/camel/content/rss.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: RSS
@@ -86,53 +75,14 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="RSS-RSSComponent">RSS
Component</h2><p>The <strong>rss:</strong> component is used for polling RSS
feeds. Camel will default poll the feed every 60th seconds.</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="RSS-RSSComponent">RSS
Component</h2><p>The <strong>rss:</strong> component is used for polling RSS
feeds. Camel will default poll the feed every 60th seconds.</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-rss</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div><p><strong>Note:</strong> The component currently only supports
polling (consuming) feeds.</p><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Camel-rss internally uses a <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/servicemix/smx4/bundles/trunk/rome-1.0/">patched
version</a> of <a shape="rect" class="external-link"
href="http://rometools.github.io/rome/" rel="nofollow">ROME</a> hosted on
ServiceMix to solve some OSGi <a shape="rect" class="external-link"
href="https://issues.apache.org/jira/browse/SMX4-510">class loading
issues</a>.</p></div></div><h3 id="RSS-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[rss:rssUri
-]]></script>
-</div></div><p>Where <code>rssUri</code> is the URI to the RSS feed to
poll.</p><p>You can append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="RSS-Options">Options</h3><div class="confluenceTableSmall"><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>splitEntries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If <code>true</code>, Camel
splits a feed into its individual entries and returns each entry, poll by poll.
For example, if a feed contains seven entries, Camel returns the first entry on
the first poll, the second entry on the
second poll, and so on. When no more entries are left in the feed, Camel
contacts the remote RSS URI to obtain a new feed. If <code>false</code>, Camel
obtains a fresh feed on every poll and returns all of the feed's
entries.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>filter</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Use in combination with the <code>splitEntries</code>
option in order to filter returned entries. By default, Camel applies the
<code>UpdateDateFilter</code> filter, which returns only new entries from the
feed, ensuring that the consumer endpoint never receives an entry more than
once. The filter orders the entries chronologically, with the newest returned
last.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throttleEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></
p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.5:</strong> Sets whether all entries identified in a single feed poll should
be delivered immediately. If true, only one entry is processed per
consumer.delay. Only applicable when splitEntries is set to
true.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>lastUpdate</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use in combination with the
<code>filter</code> option to block entries earlier than a specific date/time
(uses the <code>entry.updated</code> timestamp). The format is:
<code>yyyy-MM-ddTHH:MM:ss</code>. Example:
<code>2007-12-24T17:45:59</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>feedHeader</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Spe
cifies whether to add the ROME <code>SyndFeed</code> object as a
header.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sortEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If <code>splitEntries</code> is
<code>true</code>, this specifies whether to sort the entries by updated
date.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.delay</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>60000</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Delay in milliseconds between each
poll.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.initialDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before polling
starts.</p></td></tr><tr><td cols
pan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.userFixedDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Set to <code>true</code> to use
fixed delay between pools, otherwise fixed rate is used. See <a shape="rect"
class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>username</code></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong><span> For basic
authentication when polling from a HTTP feed</span></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><code>password</code></td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="con
fluenceTd"><strong>Camel 2.16:</strong><span> For basic authentication when
polling from a HTTP feed</span></td></tr></tbody></table></div></div>
-
-
-<h3 id="RSS-Exchangedatatypes">Exchange data types</h3><p>Camel initializes
the In body on the Exchange with a ROME <code>SyndFeed</code>. Depending on the
value of the <code>splitEntries</code> flag, Camel returns either a
<code>SyndFeed</code> with one <code>SyndEntry</code> or a
<code>java.util.List</code> of <code>SyndEntrys</code>.</p><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>Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Behavior</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>splitEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>A single entry from the current feed is set
in the exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><
p><code>splitEntries</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The entire list of entries from the current feed is set
in the exchange.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="RSS-MessageHeaders">Message Headers</h3><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>CamelRssFeed</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The entire
<code>SyncFeed</code> object.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="RSS-RSSDataformat">RSS Dataformat</h3><p>The RSS component ships with
an RSS dataformat that can be used to convert between String (as XML) and ROME
RSS model objects.</p><ul><li>marshal = from ROME <code>SyndFeed</code> to XML
<code>String</code></li><li>unmarshal = from XML <code>String</code> to ROME
<code>SyndFeed</code></li></ul><p>A route using this would look something 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[
-from("rss:file:src/test/data/rss20.xml?splitEntries=false&consumer.delay=1000").marshal().rss().to("mock:marshal");
-]]></script>
-</div></div>The purpose of this feature is to make it possible to use Camel's
lovely built-in expressions for manipulating RSS messages. As shown below, an
XPath expression can be used to filter the RSS message:<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[
-// only entries with Camel in the title will get through the filter
-from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100")
-
.marshal().rss().filter().xpath("//item/title[contains(.,'Camel')]").to("mock:result");
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Query parameters</p><span
class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>If the URL for the RSS feed uses
query parameters, this component will understand them as well, for example if
the feed uses <code>alt=rss</code>, then you can for example do<br
clear="none"> <code>from("rss:<a shape="rect" class="external-link"
href="http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&consumer.delay=1000"
rel="nofollow">http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&consumer.delay=1000</a>").to("bean:rss");</code></p></div></div><h3
id="RSS-Filteringentries">Filtering entries</h3><p>You can filter out entries
quite easily using XPath, as shown in the data format section above. You can
also exploit Camel's <a shape="rect" href="bean-integratio
n.html">Bean Integration</a> to implement your own conditions. For instance, a
filter equivalent to the XPath example above 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[
-// only entries with Camel in the title will get through the filter
-from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100").
- filter().method("myFilterBean",
"titleContainsCamel").to("mock:result");
-]]></script>
-</div></div>The custom bean for this would be:<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[
-public static class FilterBean {
- public boolean titleContainsCamel(@Body SyndFeed feed) {
- SyndEntry firstEntry = (SyndEntry) feed.getEntries().get(0);
- return firstEntry.getTitle().contains("Camel");
- }
-}
-]]></script>
-</div></div><h3 id="RSS-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><ul
class="alternate"><li><a shape="rect" href="atom.html">Atom</a></li></ul></div>
+</plain-text-body><p><strong>Note:</strong> The component currently only
supports polling (consuming) feeds.</p><rich-text-body><p>Camel-rss internally
uses a <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/servicemix/smx4/bundles/trunk/rome-1.0/">patched
version</a> of <a shape="rect" class="external-link"
href="http://rometools.github.io/rome/" rel="nofollow">ROME</a> hosted on
ServiceMix to solve some OSGi <a shape="rect" class="external-link"
href="https://issues.apache.org/jira/browse/SMX4-510">class loading
issues</a>.</p></rich-text-body><h3 id="RSS-URIformat">URI
format</h3><plain-text-body>rss:rssUri
+</plain-text-body><p>Where <code>rssUri</code> is the URI to the RSS feed to
poll.</p><p>You can append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="RSS-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>splitEntries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If <code>true</code>, Camel
splits a feed into its individual entries and returns each entry, poll by poll.
For example, if a feed contains seven entries, Camel returns the first e
ntry on the first poll, the second entry on the second poll, and so on. When
no more entries are left in the feed, Camel contacts the remote RSS URI to
obtain a new feed. If <code>false</code>, Camel obtains a fresh feed on every
poll and returns all of the feed's entries.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>filter</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use in combination with the
<code>splitEntries</code> option in order to filter returned entries. By
default, Camel applies the <code>UpdateDateFilter</code> filter, which returns
only new entries from the feed, ensuring that the consumer endpoint never
receives an entry more than once. The filter orders the entries
chronologically, with the newest returned last.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>throttleEntries</code></p></td><td colspan="1"
rowspan=
"1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> Sets whether
all entries identified in a single feed poll should be delivered immediately.
If true, only one entry is processed per consumer.delay. Only applicable when
splitEntries is set to true.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>lastUpdate</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use in combination with the
<code>filter</code> option to block entries earlier than a specific date/time
(uses the <code>entry.updated</code> timestamp). The format is:
<code>yyyy-MM-ddTHH:MM:ss</code>. Example:
<code>2007-12-24T17:45:59</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>feedHeader</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td cols
pan="1" rowspan="1" class="confluenceTd"><p>Specifies whether to add the ROME
<code>SyndFeed</code> object as a header.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>sortEntries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If <code>splitEntries</code> is
<code>true</code>, this specifies whether to sort the entries by updated
date.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.delay</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>60000</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Delay in milliseconds between each
poll.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.initialDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds b
efore polling starts.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.userFixedDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Set to <code>true</code> to use
fixed delay between pools, otherwise fixed rate is used. See <a shape="rect"
class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>username</code></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong><span> For basic
authentication when polling from a HTTP feed</span></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><code>password</code></td><td
colspan="1" rowspan="1" class="confluenceTd">&#
160;</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>Camel
2.16:</strong><span> For basic authentication when polling from a HTTP
feed</span></td></tr></tbody></table></div></rich-text-body><h3
id="RSS-Exchangedatatypes">Exchange data types</h3><p>Camel initializes the In
body on the Exchange with a ROME <code>SyndFeed</code>. Depending on the value
of the <code>splitEntries</code> flag, Camel returns either a
<code>SyndFeed</code> with one <code>SyndEntry</code> or a
<code>java.util.List</code> of <code>SyndEntrys</code>.</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>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Behavior</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>splitEntries</code></p></td><td colspan="1
" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A single entry from the current
feed is set in the exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>splitEntries</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The entire list of entries from the current
feed is set in the
exchange.</p></td></tr></tbody></table></div></rich-text-body><h3
id="RSS-MessageHeaders">Message Headers</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>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>CamelRssFeed</code></p></td><td
colspan="1" rowspan="1" class="con
fluenceTd"><p>The entire <code>SyncFeed</code>
object.</p></td></tr></tbody></table></div></rich-text-body><h3
id="RSS-RSSDataformat">RSS Dataformat</h3><p>The RSS component ships with an
RSS dataformat that can be used to convert between String (as XML) and ROME RSS
model objects.</p><ul><li>marshal = from ROME <code>SyndFeed</code> to XML
<code>String</code></li><li>unmarshal = from XML <code>String</code> to ROME
<code>SyndFeed</code></li></ul><p>A route using this would look something like
this:<plain-text-body>{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java}</plain-text-body>The
purpose of this feature is to make it possible to use Camel's lovely built-in
expressions for manipulating RSS messages. As shown below, an XPath expression
can be used to filter the RSS
message:<plain-text-body>{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/Rss
FilterWithXPathTest.java}</plain-text-body></p><parameter
ac:name="title">Query parameters</parameter><rich-text-body><p>If the URL for
the RSS feed uses query parameters, this component will understand them as
well, for example if the feed uses <code>alt=rss</code>, then you can for
example do<br clear="none"> <code>from("rss:<a shape="rect"
class="external-link"
href="http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&consumer.delay=1000"
rel="nofollow">http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&consumer.delay=1000</a>").to("bean:rss");</code></p></rich-text-body><h3
id="RSS-Filteringentries">Filtering entries</h3><p>You can filter out entries
quite easily using XPath, as shown in the data format section above. You can
also exploit Camel's <a shape="rect" href="bean-integration.html">Bean
Integration</a> to implement your own conditions. For instance, a filter
equivalent to the XPath example above would be:<plain-text-bod
y>{snippet:id=ex1|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssFilterTest.java}</plain-text-body>The
custom bean for this would
be:<plain-text-body>{snippet:id=ex2|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssFilterTest.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul class="alternate"><li><a shape="rect"
href="atom.html">Atom</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/servlet.html
==============================================================================
--- websites/production/camel/content/servlet.html (original)
+++ websites/production/camel/content/servlet.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: SERVLET
@@ -86,22 +75,14 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="SERVLET-ServletComponent">Servlet Component</h2><p>The
<strong>servlet:</strong> component provides HTTP based <a shape="rect"
href="endpoint.html">endpoints</a> for consuming HTTP requests that arrive at a
HTTP endpoint that is bound to a published Servlet.</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="SERVLET-ServletComponent">Servlet Component</h2><p>The
<strong>servlet:</strong> component provides HTTP based <a shape="rect"
href="endpoint.html">endpoints</a> for consuming HTTP requests that arrive at a
HTTP endpoint that is bound to a published Servlet.</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-servlet</artifactId>
<version>x.x.x</version>
<\!-\- use the same version as your Camel core version \-->
</dependency>
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Stream</p><span
class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Servlet is stream based, which
means the input it receives is submitted to Camel as a stream. That means you
will only be able to read the content of the stream <strong>once</strong>. If
you find a situation where the message body appears to be empty or you need to
access the data multiple times (eg: doing multicasting, or redelivery error
handling) you should use <a shape="rect" href="stream-caching.html">Stream
caching</a> or convert the message body to a <code>String</code> which is safe
to be read multiple times.</p></div></div><h3 id="SERVLET-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[servlet://relative_path[?options]
-]]></script>
-</div></div><p>You can append query options to the URI in the following
format, <code>?option=value&option=value&...</code></p><h3
id="SERVLET-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>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>httpBindingRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Reference to an
<code>org.apache.camel.component.http.HttpBinding</code> in the <a shape="rect"
href="registry.html">Registry</a>. A <code>HttpBinding</code> implementation
can be used to customize how to write a response.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd
"><code><span>httpBinding</span></code></td><td colspan="1" rowspan="1"
class="confluenceTd"><code>null</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong> <span>Reference to an
</span><code>org.apache.camel.component.http.HttpBinding</code><span> in the
</span><a shape="rect" href="registry.html">Registry</a><span>. A
</span><code>HttpBinding</code><span> implementation can be used to customize
how to write a response.</span></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>matchOnUriPrefix</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 or not the
<code>CamelServlet</code> should try to find a target consumer by matching the
URI prefix, if no exact match is found.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>servletName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><co
de>CamelServlet</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Specifies the servlet name that the servlet endpoint
will bind to. This name should match the name you define in
<code>web.xml</code> file.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="color:
rgb(0,0,0);">httpMethodRestrict</span></code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>null</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.11:</strong><span
style="color: rgb(0,0,0);"> </span><strong>Consumer only</strong><span
style="color: rgb(0,0,0);">: Used to only allow consuming if the HttpMethod
matches, such as GET/POST/PUT etc. </span><span style="color:
rgb(0,0,0);">From </span><strong>Camel 2.15 </strong><span style="color:
rgb(0,0,0);">onwards multiple methods can be specified separated by
comma.</span></td></tr></tbody></table></div></div>
-
-
-<h3 id="SERVLET-MessageHeaders">Message Headers</h3><p>Camel will apply the
same Message Headers as the <a shape="rect" href="http.html">HTTP</a>
component.</p><p>Camel will also populate <strong>all</strong>
<code>request.parameter</code> and <code>request.headers</code>. For example,
if a client request has the URL, <code><a shape="rect" class="external-link"
href="http://myserver/myserver?orderid=123"
rel="nofollow">http://myserver/myserver?orderid=123</a></code>, the exchange
will contain a header named <code>orderid</code> with the value 123.</p><h3
id="SERVLET-Usage">Usage</h3><p>You can consume only from endpoints generated
by the Servlet component. Therefore, it should be used only as input into your
Camel routes. To issue HTTP requests against other HTTP endpoints, use the <a
shape="rect" href="http.html">HTTP Component</a></p><h3
id="SERVLET-UsingServlet3.0AsyncMode">Using Servlet 3.0 Async
Mode</h3><p><strong>Available as of Camel 2.18</strong></p><p>You can configure
the
servlet with an init-param to turn on async mode when using a Servlet 3.x
container. There is a sample XML configuration below:</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[ <servlet>
+</plain-text-body><parameter
ac:name="title">Stream</parameter><rich-text-body><p>Servlet is stream based,
which means the input it receives is submitted to Camel as a stream. That means
you will only be able to read the content of the stream <strong>once</strong>.
If you find a situation where the message body appears to be empty or you need
to access the data multiple times (eg: doing multicasting, or redelivery error
handling) you should use <a shape="rect" href="stream-caching.html">Stream
caching</a> or convert the message body to a <code>String</code> which is safe
to be read multiple times.</p></rich-text-body><h3 id="SERVLET-URIformat">URI
format</h3><plain-text-body>servlet://relative_path[?options]
+</plain-text-body><p>You can append query options to the URI in the following
format, <code>?option=value&option=value&...</code></p><h3
id="SERVLET-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>httpBindingRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Reference to an
<code>org.apache.camel.component.http.HttpBinding</code> in the <a shape="rect"
href="registry.html">Registry</a>. A <code>HttpBinding</code> implementation
can be used to customize how to write a response.</p></td></tr><tr>
<td colspan="1" rowspan="1"
class="confluenceTd"><code><span>httpBinding</span></code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>null</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> <span>Reference
to an </span><code>org.apache.camel.component.http.HttpBinding</code><span> in
the </span><a shape="rect" href="registry.html">Registry</a><span>. A
</span><code>HttpBinding</code><span> implementation can be used to customize
how to write a response.</span></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>matchOnUriPrefix</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 or not the
<code>CamelServlet</code> should try to find a target consumer by matching the
URI prefix, if no exact match is found.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>servletName</code></p></td><td cols
pan="1" rowspan="1"
class="confluenceTd"><p><code>CamelServlet</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Specifies the servlet name that the servlet
endpoint will bind to. This name should match the name you define in
<code>web.xml</code> file.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="color:
rgb(0,0,0);">httpMethodRestrict</span></code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>null</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.11:</strong><span
style="color: rgb(0,0,0);"> </span><strong>Consumer only</strong><span
style="color: rgb(0,0,0);">: Used to only allow consuming if the HttpMethod
matches, such as GET/POST/PUT etc. </span><span style="color:
rgb(0,0,0);">From </span><strong>Camel 2.15 </strong><span style="color:
rgb(0,0,0);">onwards multiple methods can be specified separated by
comma.</span></td></tr></tbody></table></div></rich-text-bo
dy><h3 id="SERVLET-MessageHeaders">Message Headers</h3><p>Camel will apply the
same Message Headers as the <a shape="rect" href="http.html">HTTP</a>
component.</p><p>Camel will also populate <strong>all</strong>
<code>request.parameter</code> and <code>request.headers</code>. For example,
if a client request has the URL, <code><a shape="rect" class="external-link"
href="http://myserver/myserver?orderid=123"
rel="nofollow">http://myserver/myserver?orderid=123</a></code>, the exchange
will contain a header named <code>orderid</code> with the value 123.</p><h3
id="SERVLET-Usage">Usage</h3><p>You can consume only from endpoints generated
by the Servlet component. Therefore, it should be used only as input into your
Camel routes. To issue HTTP requests against other HTTP endpoints, use the <a
shape="rect" href="http.html">HTTP Component</a></p><h3
id="SERVLET-UsingServlet3.0AsyncMode">Using Servlet 3.0 Async
Mode</h3><p><strong>Available as of Camel 2.18</strong></p><p>You can configure
the servlet with an init-param to turn on async mode when using a Servlet 3.x
container. There is a sample XML configuration below:</p><parameter
ac:name="">xml</parameter><plain-text-body> <servlet>
<servlet-name>CamelServlet</servlet-name>
<display-name>Camel Http Transport Servlet</display-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
@@ -111,9 +92,7 @@
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
- </servlet>]]></script>
-</div></div><p> </p><h3
id="SERVLET-PuttingCamelJARsintheappserverbootclasspath">Putting Camel JARs in
the app server boot classpath</h3><p>If you put the Camel JARs such as
<code>camel-core</code>, <code>camel-servlet</code>, etc. in the boot classpath
of your application server (eg usually in its lib directory), then mind that
the servlet mapping list is now shared between multiple deployed Camel
application in the app server.</p><p>Mind that putting Camel JARs in the boot
classpath of the application server is generally not best practice!</p><p>So in
those situations you <strong>must</strong> define a custom and unique servlet
name in each of your Camel application, eg in the <code>web.xml</code>
define:</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[<servlet>
+ </servlet></plain-text-body><p> </p><h3
id="SERVLET-PuttingCamelJARsintheappserverbootclasspath">Putting Camel JARs in
the app server boot classpath</h3><p>If you put the Camel JARs such as
<code>camel-core</code>, <code>camel-servlet</code>, etc. in the boot classpath
of your application server (eg usually in its lib directory), then mind that
the servlet mapping list is now shared between multiple deployed Camel
application in the app server.</p><p>Mind that putting Camel JARs in the boot
classpath of the application server is generally not best practice!</p><p>So in
those situations you <strong>must</strong> define a custom and unique servlet
name in each of your Camel application, eg in the <code>web.xml</code>
define:</p><parameter ac:name="">xml</parameter><plain-text-body><servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
@@ -123,15 +102,11 @@
<servlet-name>MyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
-]]></script>
-</div></div><p>And in your Camel endpoints then include the servlet name as
well</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[<route>
- <from uri="servlet://foo?servletName=MyServlet"/>
+</plain-text-body><p>And in your Camel endpoints then include the servlet name
as well</p><parameter ac:name="">xml</parameter><plain-text-body><route>
+ <from uri="servlet://foo?servletName=MyServlet"/>
...
</route>
-]]></script>
-</div></div><p>From <strong>Camel 2.11</strong> onwards Camel will detect this
duplicate and fail to start the application. You can control to ignore this
duplicate by setting the servlet init-parameter ignoreDuplicateServletName to
true 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[ <servlet>
+</plain-text-body><p>From <strong>Camel 2.11</strong> onwards Camel will
detect this duplicate and fail to start the application. You can control to
ignore this duplicate by setting the servlet init-parameter
ignoreDuplicateServletName to true as follows:</p><parameter
ac:name="">xml</parameter><plain-text-body> <servlet>
<servlet-name>CamelServlet</servlet-name>
<display-name>Camel Http Transport Servlet</display-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
@@ -140,46 +115,7 @@
<param-value>true</param-value>
</init-param>
</servlet>
-]]></script>
-</div></div><p>But its <strong>strongly advised</strong> to use unique
servlet-name for each Camel application to avoid this duplication clash, as
well any unforeseen side-effects.</p><h3 id="SERVLET-Sample">Sample</h3><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From Camel 2.7 onwards it's easier
to use <a shape="rect" href="servlet.html">Servlet</a> in Spring web
applications. See <a shape="rect" href="servlet-tomcat-example.html">Servlet
Tomcat Example</a> for details.</p></div></div><p>In this sample, we define a
route that exposes a HTTP service at <code><a shape="rect"
class="external-link" href="http://localhost:8080/camel/services/hello"
rel="nofollow">http://localhost:8080/camel/services/hello</a></code>.<br
clear="none"> First, you need to publish the <a shape="rect"
class="external-link" hr
ef="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
through the normal Web Container, or OSGi Service.<br clear="none"> Use the
<code>Web.xml</code> file to publish the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
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[
-<web-app>
-
- <servlet>
- <servlet-name>CamelServlet</servlet-name>
- <display-name>Camel Http Transport Servlet</display-name>
-
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>CamelServlet</servlet-name>
- <url-pattern>/services/*</url-pattern>
- </servlet-mapping>
-
-</web-app>
-]]></script>
-</div></div>Then you can define your route as follows:<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("servlet:hello?matchOnUriPrefix=true").process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE,
String.class);
- String path = exchange.getIn().getHeader(Exchange.HTTP_URI,
String.class);
- path = path.substring(path.lastIndexOf("/"));
-
- assertEquals("Get a wrong content type", CONTENT_TYPE,
contentType);
- // assert camel http header
- String charsetEncoding =
exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
- assertEquals("Get a wrong charset name from the message
heaer", "UTF-8", charsetEncoding);
- // assert exchange charset
- assertEquals("Get a wrong charset naem from the exchange
property", "UTF-8", exchange.getProperty(Exchange.CHARSET_NAME));
- exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType +
"; charset=UTF-8");
- exchange.getOut().setHeader("PATH", path);
- exchange.getOut().setBody("<b>Hello World</b>");
- }
-});
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Specify the relative path
for camel-servlet endpoint</p><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Since we are binding the Http
transport with a published servlet, and we don't know the servlet's application
context path, the <code>camel-servlet</code> endpoint uses the relative path to
specify the endpoint's URL. A client can access the <code>camel-servlet</code>
endpoint through the servlet publish address:
<code>("http://localhost:8080/camel/services") +
RELATIVE_PATH("/hello")</code>.</p></div></div><h4
id="SERVLET-SamplewhenusingSpring3.x">Sample when using Spring 3.x</h4><p>See
<a shape="rect" href="servlet-tomcat-example.html">Servlet Tomcat
Example</a></p><h4 id="SERVLET-SamplewhenusingSpring2.x">Sample when using
Spring 2.x</h4><p>When using the Servlet component i
n a Camel/Spring application it's often required to load the Spring
ApplicationContext <em>after</em> the Servlet component has started. This can
be accomplished by using Spring's <code>ContextLoaderServlet</code> instead of
<code>ContextLoaderListener</code>. In that case you'll need to start
<code>ContextLoaderServlet</code> after <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
like this:</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[
+</plain-text-body><p>But its <strong>strongly advised</strong> to use unique
servlet-name for each Camel application to avoid this duplication clash, as
well any unforeseen side-effects.</p><h3
id="SERVLET-Sample">Sample</h3><rich-text-body><p>From Camel 2.7 onwards it's
easier to use <a shape="rect" href="servlet.html">Servlet</a> in Spring web
applications. See <a shape="rect" href="servlet-tomcat-example.html">Servlet
Tomcat Example</a> for details.</p></rich-text-body><p>In this sample, we
define a route that exposes a HTTP service at <code><a shape="rect"
class="external-link" href="http://localhost:8080/camel/services/hello"
rel="nofollow">http://localhost:8080/camel/services/hello</a></code>.<br
clear="none"> First, you need to publish the <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
through the norm
al Web Container, or OSGi Service.<br clear="none"> Use the
<code>Web.xml</code> file to publish the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
as
follows:<plain-text-body>{snippet:id=web|lang=xml|url=camel/trunk/components/camel-servlet/src/test/resources/org/apache/camel/component/servlet/web.xml}</plain-text-body>Then
you can define your route as
follows:<plain-text-body>{snippet:id=route|lang=java|url=camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/HttpClientRouteTest.java}</plain-text-body></p><parameter
ac:name="title">Specify the relative path for camel-servlet
endpoint</parameter><rich-text-body><p>Since we are binding the Http transport
with a published servlet, and we don't know the servlet's application context
path, the <code>camel-servlet</code> endpoint
uses the relative path to specify the endpoint's URL. A client can access the
<code>camel-servlet</code> endpoint through the servlet publish address:
<code>("http://localhost:8080/camel/services") +
RELATIVE_PATH("/hello")</code>.</p></rich-text-body><h4
id="SERVLET-SamplewhenusingSpring3.x">Sample when using Spring 3.x</h4><p>See
<a shape="rect" href="servlet-tomcat-example.html">Servlet Tomcat
Example</a></p><h4 id="SERVLET-SamplewhenusingSpring2.x">Sample when using
Spring 2.x</h4><p>When using the Servlet component in a Camel/Spring
application it's often required to load the Spring ApplicationContext
<em>after</em> the Servlet component has started. This can be accomplished by
using Spring's <code>ContextLoaderServlet</code> instead of
<code>ContextLoaderListener</code>. In that case you'll need to start
<code>ContextLoaderServlet</code> after <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apac
he/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
like this:</p><parameter ac:name="">xml</parameter><plain-text-body>
<web-app>
<servlet>
<servlet-name>CamelServlet</servlet-name>
@@ -196,9 +132,7 @@ from("servlet:hello?matchOnUriPrefi
<load-on-startup>2</load-on-startup>
</servlet>
<web-app>
-]]></script>
-</div></div><h4 id="SERVLET-SamplewhenusingOSGi">Sample when using
OSGi</h4><p>From <strong>Camel 2.6.0</strong>, you can publish the <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
as an OSGi service with help of SpringDM like this.</p><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>Then use
this service in your camel route like this:<div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>For
versions prior to Camel 2.6 you can use an <code>Activator</code> to publish
the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/C
amelHttpTransportServlet.java">CamelHttpTransportServlet</a> on the OSGi
platform<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3
id="SERVLET-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><ul
class="alternate"><li><a shape="rect"
href="servlet-tomcat-example.html">Servlet Tomcat Example</a></li><li><a
shape="rect" href="servlet-tomcat-no-spring-example.html">Servlet Tomcat No
Spring Example</a></li><li><a shape="rect" href="http.html">HTTP</a></li><li><a
shape="rect" href="jetty.html">Jetty</a></li></ul></div>
+</plain-text-body><h4 id="SERVLET-SamplewhenusingOSGi">Sample when using
OSGi</h4><p>From <strong>Camel 2.6.0</strong>, you can publish the <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
as an OSGi service with help of SpringDM like
this.<plain-text-body>{snippet:id=service|lang=xml|url=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml}</plain-text-body>Then
use this service in your camel route like
this:<plain-text-body>{snippet:id=camelContext|lang=xml|url=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml}</plain-text-body>For
versions prior to Camel 2.6 you can use an <code>Activator</code> to publish
the <a shape="rect" class="external-link" href="http://svn.a
pache.org/repos/asf/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java">CamelHttpTransportServlet</a>
on the OSGi
platform<plain-text-body>{snippet:id=activator|lang=java|url=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul class="alternate"><li><a shape="rect"
href="servlet-tomcat-example.html">Servlet Tomcat Example</a></li><li><a
shape="rect" href="servlet-tomcat-no-spring-example.html">Servlet Tomcat No
Spring Example</a></li><li><a shape="rect" href="http.html">HTTP</a></li><li><a
shape="rect" href="jetty.html">Jetty</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">