camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > AdviceWith
Date Thu, 28 Jan 2010 02:44:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/AdviceWith">AdviceWith</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="AdviceWith-AdviceWith"></a>AdviceWith</h2>
<p><b>Available as of Camel 2.1</b></p>

<p>AdviceWith is used for testing Camel routes where you can <em>advice</em>
an existing route before its being tested. What <tt>adviceWith</tt> allows is
to changes some factors on the route before the test is being run. </p>

<p>At current time you can <em>advice</em> an existing route by adding <a
href="/confluence/display/CAMEL/Intercept" title="Intercept">Intercept</a>, <a
href="/confluence/display/CAMEL/Exception+Clause" title="Exception Clause">Exception Clause</a>
etc. which then will apply for the route being advice.</p>

<p>For example in the route below we intercept sending a message to the <tt>mock:foo</tt>
endpoint and detour the message.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> void testAdvised()
<span class="code-keyword">throws</span> Exception {
    <span class="code-comment">// advice the first route using the inlined route builder
</span>    context.getRouteDefinitions().get(0).adviceWith(<span class="code-keyword">new</span>
RouteBuilder() {
        @Override
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span>
Exception {
            <span class="code-comment">// intercept sending to mock:foo and <span
class="code-keyword">do</span> something <span class="code-keyword">else</span>
</span>            interceptSendToEndpoint(<span class="code-quote">"mock:foo"</span>)
                    .skipSendToOriginalEndpoint()
                    .to(<span class="code-quote">"log:foo"</span>)
                    .to(<span class="code-quote">"mock:advised"</span>);
        }
    });

    getMockEndpoint(<span class="code-quote">"mock:foo"</span>).expectedMessageCount(0);
    getMockEndpoint(<span class="code-quote">"mock:advised"</span>).expectedMessageCount(1);
    getMockEndpoint(<span class="code-quote">"mock:result"</span>).expectedMessageCount(1);

    template.sendBody(<span class="code-quote">"direct:start"</span>, <span
class="code-quote">"Hello World"</span>);

    assertMockEndpointsSatisfied();
}
</pre>
</div></div>


<p>At current time you cannot alter the route by adding or changing exiting nodes in
the route path. In the future we may want to introduce a special <tt>AdviceRouteBuilder</tt>
which has special builder methods for altering the route etc.</p>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/AdviceWith">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=12321556&revisedVersion=2&originalVersion=1">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/AdviceWith?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message