camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > AdviceWith
Date Thu, 28 Jan 2010 02:44:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">AdviceWith</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Claus
     <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() {
        <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>)
                    .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>);


<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 id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View Online</a>
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message