camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > ServletListener Component
Date Fri, 04 Jan 2013 10:35:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/ServletListener+Component">ServletListener
Component</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h4. Using a XML file <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">You
can also define Camel routes using XML DSL, though as we are not using Spring or Blueprint
the XML file can only contain Camel route(s).  <br>In the web.xml you refer to the XML
file which can be from &quot;classpath&quot;, &quot;file&quot; or a &quot;http&quot;
url, as shown below: <br>{code:xml} <br>  &lt;context-param&gt; <br>
   &lt;param-name&gt;routeBuilder-MyRoute&lt;/param-name&gt; <br>  
 &lt;param-value&gt;classpath:routes/myRoutes.xml&lt;/param-value&gt; <br>
 &lt;/context-param&gt; <br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">And
the XML file is: <br>{code:xml:title=routes/myRoutes.xml} <br>&lt;?xml version=&quot;1.0&quot;
encoding=&quot;UTF-8&quot;?&gt; <br>&lt;!-- the xmlns=&quot;http://camel.apache.org/schema/spring&quot;
is needed --&gt; <br>&lt;routes xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
 &lt;route id=&quot;foo&quot;&gt; <br>    &lt;from uri=&quot;direct:foo&quot;/&gt;
<br>    &lt;to uri=&quot;mock:foo&quot;/&gt; <br>  &lt;/route&gt;
<br> <br>  &lt;route id=&quot;bar&quot;&gt; <br>    &lt;from
uri=&quot;direct:bar&quot;/&gt; <br>    &lt;to uri=&quot;mock:bar&quot;/&gt;
<br>  &lt;/route&gt; <br> <br>&lt;/routes&gt; <br>{code}
<br> <br>Notice that in the XML file the root tag is &lt;routes&gt; which
must use the namespace &quot;http://camel.apache.org/schema/spring&quot;. This namespace
is having the spring in the name, but that is because of historical reasons, as Spring was
the first and only XML DSL back in the time. At runtime no Spring JARs is needed. Maybe in
Camel 3.0 the namespace can be renamed to a generic name. <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h4. Configuring propert placeholders
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="ServletListenerComponent-ServletListenerComponent"></a>ServletListener
Component</h2>
<p><b>Available as of Camel 2.11</b></p>

<p>This component is used for bootstrapping Camel applications in web applications.
For example beforehand people would have to find their own way of bootstrapping Camel, or
rely on 3rd party frameworks such as Spring to do it.</p>

<p>There may be situations where you want a pure Camel based solution, without the extra
overhead of Spring Framework.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Sidebar</b><br
/>This component works as a <tt>javax.servlet.ServletContextListener</tt>,
which works in any web container of today, as well any older containers.<br/>
There may be solutions around the corner which is based on Servlet 3.x and annotation driven
configuration, or using <a href="/confluence/display/CAMEL/CDI" title="CDI">CDI</a>
or other means.<br/>
This component is old school and based on the pure API from Servlet 2.x, which means it works
in any web container. Also the old ones, which was the goal.</td></tr></table></div>

<p>TODO: Maven dependency</p>

<h3><a name="ServletListenerComponent-Using"></a>Using</h3>

<p>To use this you need to configure the <tt>org.apache.camel.component.servletlistener.CamelServletContextListener</tt>
in the <tt>WEB-INF/web.xml</tt> file as shown below:<br/>
TODO: myweb.xml</p>

<h3><a name="ServletListenerComponent-Options"></a>Options</h3>

<p>The <tt>org.apache.camel.component.servletlistener.CamelServletContextListener</tt>
supports the following options which can be configured as context-param in the web.xml file.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> propertyPlaceholder.XXX </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To configure <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=property+placeholders&amp;linkCreation=true&amp;fromPageId=30747188"
class="createlink">Using PropertyPlaceholder</a> in Camel. You should prefix the
option with "propertyPlaceholder.", for example to configure the location, use propertyPlaceholder.location
as name. You can configure all the options from the <a href="/confluence/display/CAMEL/Properties"
title="Properties">Properties</a> component. </td>
</tr>
<tr>
<td class='confluenceTd'> jmx.XXX </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To configure <a href="/confluence/display/CAMEL/Camel+JMX"
title="Camel JMX">JMX</a>. You should prefix the option with "jmx.", for example
to disable JMX, use jmx.disabled as name. You can configure all the options from <tt>org.apache.camel.spi.ManagementAgent</tt>.
As well the options mentioned on the <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel
JMX">JMX</a> page. </td>
</tr>
<tr>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To configure the name of the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> streamCache </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to enable <a href="/confluence/display/CAMEL/Stream+caching"
title="Stream caching">Stream caching</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> trace </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to enable <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Tracing&amp;linkCreation=true&amp;fromPageId=30747188"
class="createlink">Tracing</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> delayer </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> To set a delay value for <a href="/confluence/display/CAMEL/Delay+Interceptor"
title="Delay Interceptor">Delay Interceptor</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> handleFault </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to enable handle fault. </td>
</tr>
<tr>
<td class='confluenceTd'> errorHandlerRef </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Refers to a context scoped <a href="/confluence/display/CAMEL/Error+Handler"
title="Error Handler">Error Handler</a> to be used. </td>
</tr>
<tr>
<td class='confluenceTd'> autoStartup </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to start all routes when starting Camel. </td>
</tr>
<tr>
<td class='confluenceTd'> useMDCLogging </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to use <a href="/confluence/display/CAMEL/MDC+logging"
title="MDC logging">MDC logging</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> useBreadcrumb </td>
<td class='confluenceTd'> <tt>Boolean</tt> </td>
<td class='confluenceTd'> Whether to use <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Breadcrumb&amp;linkCreation=true&amp;fromPageId=30747188"
class="createlink">Breadcrumb</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> managementNamePattern </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To set a custom naming pattern for JMX MBeans. </td>
</tr>
<tr>
<td class='confluenceTd'> threadNamePattern </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To set a custom naming pattern for threads. </td>
</tr>
<tr>
<td class='confluenceTd'> properties.XXX </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To set custom properties on <tt>CamelContext.getProperties</tt>.
This is seldom in use. </td>
</tr>
<tr>
<td class='confluenceTd'> routebuilder.XXX </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To configure routes to be used. See below for more details.
</td>
</tr>
<tr>
<td class='confluenceTd'> CamelContextLifecycle </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Refers to a FQN classname of a implementation of <tt>org.apache.camel.component.servletlistener.CamelContextLifecycle</tt>.
Which allows to execute custom code before and after <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> has been started or stopped. See below for
further details. </td>
</tr>
<tr>
<td class='confluenceTd'> XXX </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To set any option on <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a>. </td>
</tr>
</tbody></table>
</div>

<p>TODO: Div small table</p>

<h3><a name="ServletListenerComponent-Examples"></a>Examples</h3>

<p>See <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Servlet+Tomcat+No+Spring+Example&amp;linkCreation=true&amp;fromPageId=30747188"
class="createlink">Servlet Tomcat No Spring Example</a>. </p>

<h3><a name="ServletListenerComponent-Configuringroutes"></a>Configuring
routes</h3>

<p>You need to configure which routes to use in the web.xml file. You can do this in
a number of ways, though all the parameters must be prefixed with "routeBuilder".</p>

<h4><a name="ServletListenerComponent-UsingaRouteBuilderclass"></a>Using
a RouteBuilder class</h4>

<p>By default Camel will assume the param-value is a FQN classname for a Camel <a
href="/confluence/display/CAMEL/RouteBuilder" title="RouteBuilder">RouteBuilder</a>
class, as shown below:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>routeBuilder-MyRoute<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag">&lt;param-value&gt;</span>org.apache.camel.component.servletlistener.MyRoute<span
class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>

<p>You can specify multiple classes in the same param-value as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>routeBuilder-routes<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- we can define
multiple values separated by comma --&gt;</span></span>
    <span class="code-tag">&lt;param-value&gt;</span>
      org.apache.camel.component.servletlistener.MyRoute,
      org.apache.camel.component.servletlistener.routes.BarRouteBuilder
    <span class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>

<p>The name of the parameter does not have a meaning at runtime. It just need to be
unique and start with "routeBuilder". In the example above we have "routeBuilder-routes".
But you could just as well have named it "routeBuilder.foo".</p>

<h4><a name="ServletListenerComponent-Usingpackagescanning"></a>Using package
scanning</h4>

<p>You can also tell Camel to use package scanning, which mean it will look in the given
package for all classes of <a href="/confluence/display/CAMEL/RouteBuilder" title="RouteBuilder">RouteBuilder</a>
types and automatic adding them as Camel routes. To do that you need to prefix the value with
"packagescan:" as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>routeBuilder-MyRoute<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- define the routes
using package scanning by prefixing with packagescan: --&gt;</span></span>
    <span class="code-tag">&lt;param-value&gt;</span>packagescan:org.apache.camel.component.servletlistener.routes<span
class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>

<h4><a name="ServletListenerComponent-UsingaXMLfile"></a>Using a XML file</h4>

<p>You can also define Camel routes using XML DSL, though as we are not using Spring
or Blueprint the XML file can only contain Camel route(s). <br/>
In the web.xml you refer to the XML file which can be from "classpath", "file" or a "http"
url, as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>routeBuilder-MyRoute<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag">&lt;param-value&gt;</span>classpath:routes/myRoutes.xml<span
class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>

<p>And the XML file is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;!-- the xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>
is needed --&gt;
</span>&lt;routes xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>
  &lt;route id=<span class="code-quote">"foo"</span>&gt;
    &lt;from uri=<span class="code-quote">"direct:foo"</span>/&gt;
    &lt;to uri=<span class="code-quote">"mock:foo"</span>/&gt;
  &lt;/route&gt;

  &lt;route id=<span class="code-quote">"bar"</span>&gt;
    &lt;from uri=<span class="code-quote">"direct:bar"</span>/&gt;
    &lt;to uri=<span class="code-quote">"mock:bar"</span>/&gt;
  &lt;/route&gt;

&lt;/routes&gt;
</pre>
</div></div>

<p>Notice that in the XML file the root tag is &lt;routes&gt; which must use
the namespace "http://camel.apache.org/schema/spring". This namespace is having the spring
in the name, but that is because of historical reasons, as Spring was the first and only XML
DSL back in the time. At runtime no Spring JARs is needed. Maybe in Camel 3.0 the namespace
can be renamed to a generic name.</p>


<h4><a name="ServletListenerComponent-Configuringpropertplaceholders"></a>Configuring
propert placeholders</h4>

<p>Here is a snippet of a web.xml configuration for setting up property placeholders
to load <tt>myproperties.properties</tt> from the classpath</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag"><span class="code-comment">&lt;!-- setup property
placeholder to load properties from classpath --&gt;</span></span>
  <span class="code-tag"><span class="code-comment">&lt;!-- we do this by
setting the param-name with propertyPlaceholder. as prefix and then any options such as location,
cache etc --&gt;</span></span>
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>propertyPlaceholder.location<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag">&lt;param-value&gt;</span>classpath:myproperties.properties<span
class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
  <span class="code-tag"><span class="code-comment">&lt;!-- for example to
disable cache on properties component, you do --&gt;</span></span>
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>propertyPlaceholder.cache<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag">&lt;param-value&gt;</span>false<span class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>

<h4><a name="ServletListenerComponent-ConfiguringJMX"></a>Configuring JMX</h4>

<p>Here is a snippet of a web.xml configuration for configuring JMX, such as disabling
JMX.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag"><span class="code-comment">&lt;!-- configure JMX
by using names that is prefixed with jmx. --&gt;</span></span>
  <span class="code-tag"><span class="code-comment">&lt;!-- in this example
we disable JMX --&gt;</span></span>
  <span class="code-tag">&lt;context-param&gt;</span>
    <span class="code-tag">&lt;param-name&gt;</span>jmx.disabled<span
class="code-tag">&lt;/param-name&gt;</span>
    <span class="code-tag">&lt;param-value&gt;</span>true<span class="code-tag">&lt;/param-value&gt;</span>
  <span class="code-tag">&lt;/context-param&gt;</span>
</pre>
</div></div>




<h3><a name="ServletListenerComponent-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/SERVLET" title="SERVLET">SERVLET</a></li>
	<li><a href="/confluence/display/CAMEL/Servlet+Tomcat+Example" title="Servlet Tomcat
Example">Servlet Tomcat Example</a></li>
	<li><a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Servlet+Tomcat+No+Spring+Example&amp;linkCreation=true&amp;fromPageId=30747188"
class="createlink">Servlet Tomcat No Spring Example</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ServletListener+Component">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30747188&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ServletListener+Component?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message