camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Loading routes from XML files
Date Sun, 10 Nov 2013 10:07:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/Loading+routes+from+XML+files">Loading
routes from XML files</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</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" >This cookbook shows how to load and
add routes from XML files into an existing [CamelContext]. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{info}
<br>When adding routes as shown on this page, the routes is isolated and cannot re-use
any existing {{onException}}, {{intercept}} etc. <br>{info} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >You can define Camel routes in XML
files using the {{&lt;routes&gt;}} tag with the namespace {{&quot;http://camel.apache.org/schema/spring&quot;}}.
<br>Suppose we have the bar route as shown below in the {{barRoute.xml}} XML file. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="LoadingroutesfromXMLfiles-LoadingroutesfromXMLfiles"></a>Loading
routes from XML files</h2>
<p><b>Available as of Camel 2.6</b></p>

<p>This cookbook shows how to load and add routes from XML files into an existing <a
href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td>When adding routes
as shown on this page, the routes is isolated and cannot re-use any existing <tt>onException</tt>,
<tt>intercept</tt> etc.</td></tr></table></div>

<p>You can define Camel routes in XML files using the <tt>&lt;routes&gt;</tt>
tag with the namespace <tt>"http://camel.apache.org/schema/spring"</tt>.<br/>
Suppose we have the bar route as shown below in the <tt>barRoute.xml</tt> XML
file.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>barRoute.xml</b></div><div class="codeContent
panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: xml; gutter: false"><![CDATA[
&lt;routes xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;!-- here we define the bar route --&gt;
    &lt;route id="bar"&gt;
        &lt;from uri="direct:bar"/&gt;
        &lt;to uri="mock:bar"/&gt;
    &lt;/route&gt;

    &lt;!-- we could add more routes if we like,
         but in this example we stick to one route only --&gt;
&lt;/routes&gt;
]]></script>
</div></div>

<p>We can then load this route and add to the existing <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> using the following lines of code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Java code</b></div><div class="codeContent
panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
// load route from XML and add them to the existing camel context
InputStream is = getClass().getResourceAsStream("barRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
]]></script>
</div></div>

<p>If you are using older versions of Camel, you can do this as well but it requires
a bit more work. See this <a href="http://svn.apache.org/viewvc?view=revision&amp;revision=1040085"
class="external-link" rel="nofollow">commit log</a>.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Loading+routes+from+XML+files">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24188162&revisedVersion=3&originalVersion=2">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message