camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Debugger
Date Thu, 28 Oct 2010 12:30:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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/Debugger">Debugger</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (5)</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" > <br>We want to debug the following
route <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO:
e2 <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{snippet:id=e2|lang=java|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugTest.java}
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>Which can easily done by
overriding the {{debugBefore}} method as shown <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO:
e1 <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugTest.java}
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>Then from your Java editor
just add a breakpoint inside the {{debugBefore}} method. Then fire up the unit test and wait
for the Java editor to hit the breakpoint. Then you can inspect the [Exchange] during debugging
while it advances during routing. The {{ProcessorDefinition}} and the {{id}} and {{shortName}}
parameters is all information which tells you where in the route the breakpoint was hit. <br>
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip}
<br>There is also a {{debugAfter}} method which is invoked after the processor has been
invoked. This allows you to _see_ what happens to the [Exchange] right after it has invoked
a processor in the route. <br>{tip} <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Debugger-Debugger"></a>Debugger </h2>
<p><b>Available as of Camel 2.6</b></p>

<p>Camel <a href="/confluence/display/CAMEL/Debugger" title="Debugger">Debugger</a>
is much related to <a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a>,
in fact they are sisters. Debugger is a enhanced tracer with a debugger framework so that
tooling can be developed to easily monitor Camel routes, trace messages and set breakpoints
at points in a route etc.</p>

<h3><a name="Debugger-AbouttheDebugger"></a>About the Debugger</h3>

<p>The Debugger allows tooling or the likes to attach breakpoints which is being invoked
when <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>s
is being routed.</p>

<h3><a name="Debugger-Defaultimplementation"></a>Default implementation</h3>

<p>Camel provides a default implementation <tt>org.apache.camel.impl.DefaultDebugger</tt>
which you can set on the <tt>CamelContext</tt> using the <tt>setDebugger</tt>
method.<br/>
Likewise you can get hold of the <a href="/confluence/display/CAMEL/Debugger" title="Debugger">Debugger</a>
using the <tt>getDebugger</tt> method on <tt>CamelContext</tt>.</p>

<p>The <tt>org.apache.camel.spi.Debugger</tt> has methods to attach and
remove breakpoints. And to suspend/resume all breakpoints etc.<br/>
You can also attach a condition to the breakpoint so it only reacts if the condition matches.</p>

<h3><a name="Debugger-EasilydebuggingCamelroutesfrom%7B%7Bcameltest%7D%7D"></a>Easily
debugging Camel routes from <tt>camel-test</tt></h3>

<p>If you are developing unit tests using the <tt>camel-test</tt> component,
then the <a href="/confluence/display/CAMEL/Debugger" title="Debugger">Debugger</a>
comes out of the box.</p>

<h4><a name="Debugger-Example"></a>Example </h4>

<p>In this unit test</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class DebugTest <span class="code-keyword">extends</span>
CamelTestSupport
</pre>
</div></div>

<p>We want to debug the following route</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Override
<span class="code-keyword">protected</span> RouteBuilder createRouteBuilder()
<span class="code-keyword">throws</span> Exception {
    <span class="code-keyword">return</span> <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">// <span class="code-keyword">this</span>
is the route we want to debug
</span>            from(<span class="code-quote">"direct:start"</span>)
                .to(<span class="code-quote">"mock:a"</span>)
                .transform(body().prepend(<span class="code-quote">"Hello "</span>))
                .to(<span class="code-quote">"mock:b"</span>);
        }
    };
}
</pre>
</div></div>

<p>Which can easily done by overriding the <tt>debugBefore</tt> method as
shown</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Override
<span class="code-keyword">protected</span> void debugBefore(Exchange exchange,
Processor processor,
                           ProcessorDefinition definition, <span class="code-object">String</span>
id, <span class="code-object">String</span> shortName) {
    <span class="code-comment">// <span class="code-keyword">this</span>
method is invoked before we are about to enter the given processor
</span>    <span class="code-comment">// from your Java editor you can just add
a breakpoint in the code line below
</span>    log.info(<span class="code-quote">"Before "</span> + definition
+ <span class="code-quote">" with body "</span> + exchange.getIn().getBody());
}
</pre>
</div></div>

<p>Then from your Java editor just add a breakpoint inside the <tt>debugBefore</tt>
method. Then fire up the unit test and wait for the Java editor to hit the breakpoint. Then
you can inspect the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
during debugging while it advances during routing. The <tt>ProcessorDefinition</tt>
and the <tt>id</tt> and <tt>shortName</tt> parameters is all information
which tells you where in the route the breakpoint was hit.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>There is also a <tt>debugAfter</tt>
method which is invoked after the processor has been invoked. This allows you to <em>see</em>
what happens to the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
right after it has invoked a processor in the route.</td></tr></table></div>


<h3><a name="Debugger-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</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/Debugger">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=86210&revisedVersion=15&originalVersion=14">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Debugger?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message