camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Camel 2.x - Debugger API
Date Thu, 08 Jul 2010 12:35: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/Camel+2.x+-+Debugger+API">Camel
2.x - Debugger API</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="Camel2.x-DebuggerAPI-Camel2.xDebuggerAPI"></a>Camel
2.x - Debugger API</h2>
<p><b>Available as of Camel 2.4</b></p>

<p>There is a new <tt>org.apache.camel.spi.Debugger</tt> API which allows
3rd party to attach a debugger tooling to debug <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a>s in Camel routes.<br/>
There is a default implementation in <b>camel-core</b> as the <tt>org.apache.camel.impl.DefaultDebugger</tt>.
</p>

<h3><a name="Camel2.x-DebuggerAPI-Enabling"></a>Enabling</h3>
<p>You can enable the debugger from the <tt>CamelContext</tt> using the
<tt>setDebugger</tt>. We may add a nicer API for this in the future.</p>

<h3><a name="Camel2.x-DebuggerAPI-Breakpoint"></a>Breakpoint</h3>
<p>There is a <tt>org.apache.camel.spi.Breakpoint</tt> API in which the
3rd party tooling implement logic what should happen when the breakpoint is hit. </p>

<p>The breakpoint can be invoked in 2 kind of styles in Camel:</p>
<ul class="alternate" type="square">
	<li>processing based</li>
	<li>event based</li>
</ul>


<p>The processing is based on a <tt>before</tt> and <tt>after</tt>
callback when the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
is being routed and thus a <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a>
is invoked.</p>

<p>The event is based on the <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=EventNotifer&amp;linkCreation=true&amp;fromPageId=23332117"
class="createlink">EventNotifer</a> emitting events such as <tt>ExchangeCreatedEvent</tt>,
<tt>ExchangeFailureEvent</tt> etc. This allows you to have breakpoints when a
given Exchange has failed. Or when they are done, so you can inspect the result etc.</p>

<p>There is a <tt>org.apache.camel.impl.BreakpointSupport</tt> class which
can be used to extend, to avoid implementing all the methods from the interface.</p>

<h3><a name="Camel2.x-DebuggerAPI-Condition"></a>Condition</h3>
<p>There is a <tt>org.apache.camel.spi.Condition</tt> API in which the 3rd
party tooling can provide conditions when the breakpoints should apply. For example a conditional
breakpoint which only triggers if the message body is a certain message / type etc.</p>

<p>The condition can be invoked in 2 kind of styles in Camel:</p>
<ul class="alternate" type="square">
	<li>processing based</li>
	<li>event based</li>
</ul>


<p>Where there is a <tt>match</tt> method for each style.</p>

<p>There is a <tt>org.apache.camel.impl.ConditionSupport</tt> class which
can be used to extend, to avoid implementing all the methods from the interface.</p>

<h3><a name="Camel2.x-DebuggerAPI-Example"></a>Example</h3>

<p>For example we can have this breakpoint</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

        breakpoint = <span class="code-keyword">new</span> BreakpointSupport()
{
            <span class="code-keyword">public</span> void beforeProcess(Exchange
exchange, Processor processor, ProcessorDefinition definition) {
                <span class="code-object">String</span> body = exchange.getIn().getBody(<span
class="code-object">String</span>.class);
                logs.add(<span class="code-quote">"Breakpoint at "</span> + definition
+ <span class="code-quote">" with body: "</span> + body);
            }
        }
</pre>
</div></div>

<p>In which we want to trigger when the message contains Camel. So we can create this
<tt>Condition</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        camelCondition = <span class="code-keyword">new</span> ConditionSupport()
{
            <span class="code-keyword">public</span> <span class="code-object">boolean</span>
matchProcess(Exchange exchange, Processor processor, ProcessorDefinition definition) {
                <span class="code-keyword">return</span> body().contains(<span
class="code-quote">"Camel"</span>).matches(exchange);
            }
        };
</pre>
</div></div>

<p>And to use this we just tell the <tt>Debugger</tt> as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void testDebug() <span class="code-keyword">throws</span>
Exception {
        context.getDebugger().addBreakpoint(breakpoint, camelCondition);

        getMockEndpoint(<span class="code-quote">"mock:result"</span>).expectedBodiesReceived(<span
class="code-quote">"Hello World"</span>, <span class="code-quote">"Hello Camel"</span>);

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

        assertMockEndpointsSatisfied();

        assertEquals(2, logs.size());
        assertEquals(<span class="code-quote">"Breakpoint at To[log:foo] with body:
Hello Camel"</span>, logs.get(0));
        assertEquals(<span class="code-quote">"Breakpoint at To[mock:result] with body:
Hello Camel"</span>, logs.get(1));
    }
</pre>
</div></div>

<p>Which then will only invoke the breakpoint callback for the <tt>"Hello Camel"</tt>
message.</p>


<h3><a name="Camel2.x-DebuggerAPI-Singlestep"></a>Single step</h3>

<p>TODO: bla bla</p>

    </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/Camel+2.x+-+Debugger+API">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Camel+2.x+-+Debugger+API?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message