camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Tracer
Date Wed, 15 Jul 2009 08:56: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/Tracer">Tracer</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="Tracer-TracerInterceptor"></a>Tracer Interceptor</h2>

<p>Camel supports a tracer interceptor that is used for logging the route executions at <tt>INFO</tt> level.</p>

<p>The Tracer is an InterceptStrategy which can be applied to a DefaultCamelContext or SpringCamelContext to ensure that there is a TracerInterceptor created for every node in the DSL.</p>

<p>You can enable or disable the Tracer's logging dynamically, by calling the tracer's <tt>setEnabled</tt> method.</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><p>The <tt>org.apache.camel.processor.interceptor.TraceFormatter</tt> has been rename to <tt>org.apache.camel.processor.interceptor.DefaultTraceFormatter</tt> in Camel 2.0.</p>

<p>Users of Camel 1.x should use <tt>TraceFormatter</tt> whereas 2.x users should use <tt>DefaultTraceFormatter</tt>.</p></td></tr></table></div>

<h3><a name="Tracer-Options"></a>Options</h3>
<p>Trace has been improved in <b>Camel 1.5</b> to be more configurable with these options:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> formatter </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Sets the Trace Formatter to use. Will default use <tt>org.apache.camel.processor.interceptor.DefaultTraceFormatter</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> enabled </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Flag to enable or disable this tracer </td>
</tr>
<tr>
<td class='confluenceTd'> logLevel </td>
<td class='confluenceTd'> <tt>INFO</tt> </td>
<td class='confluenceTd'> The logging level to use: FATAL, ERROR, WARN, INFO, DEBUG, TRACE </td>
</tr>
<tr>
<td class='confluenceTd'> logName </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The log name to use. Will default use <tt>org.apache.camel.processor.interceptor.TraceInterceptor</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> traceFilter </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> An exchange <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> to filter the tracing. </td>
</tr>
<tr>
<td class='confluenceTd'> traceInterceptors </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Flag to enable or disable tracing of interceptors </td>
</tr>
<tr>
<td class='confluenceTd'> traceExceptions </td>
<td class='confluenceTd'> true</td>
<td class='confluenceTd'> Flag to enable or disable tracing of thrown exception during processing of the exchange </td>
</tr>
<tr>
<td class='confluenceTd'> logStackTrace </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> When tracing exception you can control whether the stack trace should be logged also. If <b>not</b> then only the exception class and message is logged. </td>
</tr>
<tr>
<td class='confluenceTd'> destinationUri </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Optional destination uri to route <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventExchange.html" rel="nofollow">TraceEventExchange</a> containing <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html" rel="nofollow">TraceEventMessage</a> with details about the trace. Can be used for custom processing to store traces in database using <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a>. </td>
</tr>
</tbody></table>

<h3><a name="Tracer-Formatting"></a>Formatting</h3>
<p>The tracer formats the execution of exchanges to log lines. They are logged at INFO level in the log category: <tt>org.apache.camel.processor.interceptor.TraceInterceptor</tt>.<br/>
The tracer uses by default <tt>TraceFormatter</tt> to format the log line.</p>

<p>TraceFormatter has the following options:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> breadCrumbLength </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> <b>Camel 1.5.1:</b> Fixed length of the bread crumb. 0 = no fixed length. Setting a value to e.g. 80 allows the tracer logs to be aligned for easier reading. </td>
</tr>
<tr>
<td class='confluenceTd'> nodeLength </td>
<td class='confluenceTd'> 0 </td>
<td class='confluenceTd'> <b>Camel 1.5.1:</b> Fixed length of the node. 0 = no fixed length. Setting a value to e.g. 40 allows the tracer logs to be aligned for easier reading.</td>
</tr>
<tr>
<td class='confluenceTd'> showBreadCrumb </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Outputs the unique unit of work for the exchange. To be used for correlation so you can identify the same exchange. </td>
</tr>
<tr>
<td class='confluenceTd'> showNode </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> In <b>Camel 1.x</b> its the destination node. In <b>Camel 2.0</b> its both the previous and destination node, so you can see from -&gt; to. </td>
</tr>
<tr>
<td class='confluenceTd'> showExchangeId </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> To output the unique exchange id. Currently the breadcrumb is sufficient. </td>
</tr>
<tr>
<td class='confluenceTd'> showShortExchangeId </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 1.5.1:</b> To output the unique exchange id in short form, without the hostname. </td>
</tr>
<tr>
<td class='confluenceTd'> showProperties </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Output the exchange properties </td>
</tr>
<tr>
<td class='confluenceTd'> showHeaders </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Output the in message headers </td>
</tr>
<tr>
<td class='confluenceTd'> showBodyType </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Output the in body Java type </td>
</tr>
<tr>
<td class='confluenceTd'> showBody </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Output the in body </td>
</tr>
<tr>
<td class='confluenceTd'> showOutHeaders </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Output the out (if any) message headers </td>
</tr>
<tr>
<td class='confluenceTd'> showOutBodyType </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Output the out (if any) body Java type </td>
</tr>
<tr>
<td class='confluenceTd'> showOutBody </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Output the out (if any) body </td>
</tr>
<tr>
<td class='confluenceTd'> showExchangePattern </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 1.5:</b> Output the exchange pattern </td>
</tr>
<tr>
<td class='confluenceTd'> showException </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 1.5:</b> Output the exception if the exchange has failed </td>
</tr>
<tr>
<td class='confluenceTd'> maxChars </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Is used to limit the number of chars logged per line. </td>
</tr>
</tbody></table>

<p>Example:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">ID-claus-acer/4412-1222625653890/2-0 -&gt; to(mock:a)                , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p><tt>ID-claus-acer/3690-1214458315718/2-0</tt> is the breadcrumb with the unique correlation id.<br/>
<tt>node3</tt> is the id of the node in the route path. Is always shown.<br/>
<tt>To[mock:a]</tt> is the destination node.<br/>
<tt>InOnly</tt> is the exchange pattern. Is always shown.<br/>
Then the rest is properties, headers and the body.</p>

<h4><a name="Tracer-Showingfromandto"></a>Showing from and to</h4>
<p>In <b>Camel 2.0</b> the trace log will output both the from and to so you can see where the Exchange came from, such as:</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">&gt;&gt;&gt; direct:start --&gt; process(MyProcessor)
&gt;&gt;&gt; process(MyProcessor) --&gt; to(mock:a)
&gt;&gt;&gt; to(mock:a) --&gt; to(mock:b)</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-Enabling"></a>Enabling</h3>

<p>To enable tracer from the main run</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">java org.apache.camel.spring.Main -t</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>

<p>or </p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">java org.apache.camel.spring.Main -trace</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>and the tracer will be active.</p>

<h3><a name="Tracer-EnablingfromJavaDSL"></a>Enabling from Java DSL</h3>
<p>The tracer can be enabled by adding it to the interceptor chain to the camel context. This is demonstrated in the unit test below.<br/>
<b>Notice:</b> We could have changed the properties on the Tracer object before adding it, if we e.g. don't like the default settings.</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public void testSendingSomeMessages() throws Exception {
    template.sendBodyAndHeader("direct:start", "Hello London", "to", "James");
    template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus");
}

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // add tracer as an interceptor so it will log the exchange executions at runtime
            // this can aid us to understand/see how the exchanges is routed etc.
            getContext().addInterceptStrategy(new Tracer());

            from("direct:start").
                    process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            // do nothing
                        }

                        @Override
                        public String toString() {
                            return "MyProcessor";
                        }
                    }).
                    to("mock:a").
                    to("mock:b");
        }
    };
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>In <b>Camel 2.0</b> this is a bit easier as you just do:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">context.setTracing(true);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Running the test we get the trace information logged at INFO level (<b>Camel 1.x</b> output):</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-0 -&gt; process(MyProcessor)      , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London 
INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-0 -&gt; to(mock:a)                , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London 
INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-0 -&gt; to(mock:b)                , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London 
...
INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-1 -&gt; process(MyProcessor)      , Pattern:InOnly , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling 
INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-1 -&gt; to(mock:a)                , Pattern:InOnly , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling 
INFO  TraceInterceptor     - ID-claus-acer/4412-1222625653890/2-1 -&gt; to(mock:b)                , Pattern:InOnly , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And the same output with <b>Camel 2.0</b>:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 &gt;&gt;&gt; from(direct:start) --&gt; MyProcessor     , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 &gt;&gt;&gt; MyProcessor --&gt; mock:a                 , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 &gt;&gt;&gt; mock:a --&gt; mock:b                      , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
...
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 &gt;&gt;&gt; from(direct:start) --&gt; MyProcessor     , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 &gt;&gt;&gt; MyProcessor --&gt; mock:a                 , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 &gt;&gt;&gt; mock:a --&gt; mock:b                      , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-ConfiguringfromJavaDSL"></a>Configuring from Java DSL</h3>
<p>The tracer options can be configured from the Java DSL like this:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public void configure() throws Exception {
        // add tracer as an interceptor so it will log the exchange executions at runtime
        // this can aid us to understand/see how the exchanges is routed etc.
        Tracer tracer = new Tracer();
        tracer.getFormatter().setShowBreadCrumb(false);
        tracer.getFormatter().setShowNode(false);
        ...
        getContext().addInterceptStrategy(tracer);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="Tracer-Usingpredicatestofilterexchanges"></a>Using predicates to filter exchanges</h4>
<p><b>Available as of Camel 1.5</b><br/>
In the code below we want the tracer only to trace if the body contains the text <tt>London</tt>. As this is just an example can of course set any <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a> that matches your criteria:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">Tracer tracer = new Tracer();
    // set the level to FATAL so we can easily spot it
    tracer.setLogLevel(LoggingLevel.FATAL);
    // and only trace if the body contains London as text
    tracer.setTraceFilter(body().contains(constant("London")));
    // do not show exchange pattern
    tracer.getFormatter().setShowExchangePattern(false);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-EnablingfromSpringXML"></a>Enabling from Spring XML</h3>

<p>There is now a <b>trace</b> attribute you can specify on the *&lt;camelContext/&gt; for example</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">&lt;camelContext trace="true" xmlns="http://activemq.apache.org/camel/schema/spring"&gt;
    ...
  &lt;/camelContext&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can see this in action with the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTraceTest.java" rel="nofollow">SpringTraceTest</a> and its <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTraceTest-context.xml" rel="nofollow">spring.xml file</a></p>

<p>Another option is to just include a spring XML which defines the Tracer bean such as the <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/spring/trace.xml" rel="nofollow">one that is automatically included if you run the Main with -t above</a>.</p>

<h3><a name="Tracer-ConfigurationfromSpring"></a>Configuration from Spring</h3>
<p>In Camel 1.5 you can configure the tracer as a Spring bean. Just add a bean with the bean class <tt>org.apache.camel.processor.interceptor.Tracer</tt> and Camel will use it as the Tracer.</p>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;!-- we can configure the tracer by defining the tracer bean and set the properties as we like --&gt;
&lt;!-- the id name can be anything its the class that must be org.apache.camel.processor.interceptor.Tracer --&gt;
&lt;bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer"&gt;
    &lt;property name="traceExceptions" value="false"/&gt;
    &lt;property name="traceInterceptors" value="true"/&gt;
    &lt;property name="logLevel" value="FATAL"/&gt;
    &lt;property name="logName" value="com.mycompany.messages"/&gt;
&lt;/bean&gt;

&lt;camelContext id="camel" trace="true" xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;route&gt;
        &lt;from uri="direct:start"/&gt;
        &lt;to uri="mock:result"/&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-FormattingfromSpring"></a>Formatting from Spring</h3>
<p>In Camel 1.5 you can configure the formatting of tracer as a Spring bean. Just add a bean with the id <b>traceFormatter</b> and Camel will lookup this id and use the formatter, as the example below illustrates:</p>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;bean id="traceFormatter" class="org.apache.camel.processor.interceptor.DefaultTraceFormatter"&gt;
    &lt;property name="showBody" value="true"/&gt;
    &lt;property name="showBodyType" value="false"/&gt;
    &lt;property name="showBreadCrumb" value="false"/&gt;
    &lt;property name="maxChars" value="100"/&gt;
&lt;/bean&gt;

&lt;camelContext id="camel" trace="true" xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;route&gt;
        &lt;from uri="direct:start"/&gt;
        &lt;to uri="mock:result"/&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-Enabletracingofoutmessages"></a>Enable tracing of out messages</h3>
<p><b>Available as of Camel 2.0</b></p>

<p>You can now trace messages coming out of processing steps. To enable this, configure the tracer as follows</p>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">Tracer tracer = new Tracer();
tracer.setTraceOutExchanges(true);

// we configure the default trace formatter where we can
// specify which fields we want in the output
DefaultTraceFormatter formatter = new DefaultTraceFormatter();
formatter.setShowOutBody(true);
formatter.setShowOutBodyType(true);

// set to use our formatter
tracer.setFormatter(formatter);

getContext().addInterceptStrategy(tracer);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>

<p>or</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer"&gt;
  &lt;property name="traceOutExchanges" value="true" /&gt;
&lt;/bean&gt;

&lt;bean id="traceFormatter" class="org.apache.camel.processor.interceptor.DefaultTraceFormatter"&gt;
  &lt;property name="showOutBody" value="true" /&gt;
  &lt;property name="showOutBodyType" value="true" /&gt;
&lt;/bean&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Running with these options, you'll get output similar to:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">INFO  TraceInterceptor - ID-mojo/59899-1225474989226/2-0 -&gt; transform(body) , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London
INFO  TraceInterceptor - transform(body) -&gt; ID-mojo/59899-1225474989226/2-0 , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London , OutBodyType:String , OutBody:Hello London</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-UsingCustomFormatter"></a>Using Custom Formatter</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>You can now implement your own <tt>org.apache.camel.processor.interceptor.TraceFormatter</tt> to be used for logging trace messages to the log. </p>

<p>The sample below shows how to configure a Tracer from Java DSL using custom formatter:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// we create a tracer where we want to use our own formatter instead of the default one
Tracer tracer = new Tracer();

// use our own formatter instead of the default one
MyTraceFormatter formatter = new MyTraceFormatter();
tracer.setFormatter(formatter);

// and we must remeber to add the tracer to Camel
getContext().addInterceptStrategy(tracer);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And here we have our custom logger that implements the <tt>TraceFormatter</tt> interface where we can construct the log message how we like:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// here we have out own formatter where we can create the output we want for trace logs
// as this is a test we just create a simple string with * around the body
class MyTraceFormatter implements TraceFormatter {

    public Object format(TraceInterceptor interceptor, ProcessorDefinition node, Exchange exchange) {
        return "***" + exchange.getIn().getBody(String.class) + "***";
    }
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-UsingDestinationforcustomprocessingandrouting"></a>Using Destination for custom processing and routing</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>Tracer now supports custom processing of trace events. This can be used to route a trace event to a <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> endpoint for persistence in a database.</p>

<p>This works by Camel creates a new <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventExchange.html" rel="nofollow">TraceEventExchange</a> containing:</p>
<ul class="alternate" type="square">
	<li>snapshot of the original traced Exchange as a immutable <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html" rel="nofollow">TraceEventMessage</a> containing String values of the fields, when the interception occurred. This ensures the fields contains the exact data at the given time of interception.</li>
	<li>the original Exchange can be accessed using <tt>getTracedExchange()</tt></li>
</ul>


<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><p>Beware to access the original Exchange to avoid causing any side effects or alter its state. Prefer to access the information from <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html" rel="nofollow">TraceEventMessage</a></p></td></tr></table></div>

<p>Camel routes the TraceEventExchange synchronously from the point of interception. When its completed Camel will continue routing the original Exchange.</p>

<p>The sample below demonstrates this feature, where we route traced Exchanges to the ((direct:traced)) route:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// we create a tracer where we want to send TraveEvents to an endpoint
// "direct:traced" where we can do some custom processing such as storing
// it in a file or a database
Tracer tracer = new Tracer();
tracer.setDestinationUri("direct:traced");
// we disable regular trace logging in the log file. You can omit this and
// have both.
tracer.setLogLevel(LoggingLevel.OFF);
// and we must remeber to add the tracer to Camel
getContext().addInterceptStrategy(tracer);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Then we can configure a route for the traced messages:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("direct:traced").process(new MyTraceMessageProcessor()).to("file://myapp/logs/trace);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And our processor where we can process the TraceEventMessage. Here we want to create a CSV format of the trace event to be stored as a file. We do this by constructing the CSV String and the replace the IN body with our String instead of the <tt>TraceEventMessage</tt>.</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">class MyTraceMessageProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        // here we can transform the message how we like want it
        TraceEventMessage msg = exchange.getIn().getBody(DefaultTraceEventMessage.class);

        // we want to store it as a CSV with from;to;exchangeId;body
        String s = msg.getFromEndpointUri() + ";" + msg.getToNode() + ";" + msg.getExchangeId() + ";" + msg.getBody();

        // so we replace the IN body with our CSV string
        exchange.getIn().setBody(s);
    }
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-UsingJPAasdatastorefortracemessages"></a>Using <a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a> as datastore for trace messages</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>See <a href="/confluence/display/CAMEL/Tracer+Example" title="Tracer Example">Tracer Example</a> for complete documentation and how to use this feature.</p>

<h3><a name="Tracer-Tracedroutepathduringruntime"></a>Traced route path during runtime</h3>
<p><b>Available as of Camel 2.0</b></p>

<p><a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a> also traces the actual route path taken during runtime. Camel will store the route path taken on the UnitOfWork when <a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a> is enabled. </p>

<p>The example below demonstrates how we can use that for error handling where we can determine at which node in the route graph the error triggered.<br/>
First we define our route:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:error").redeliverDelay(0).maximumRedeliveries(3));

            // must enable tracer to trace the route path taken during runtime
            context.setTracing(true);

            // let our my error processor handle all exceptions
            onException(Exception.class).handled(true).process(new MyErrorProcessor());

            // our route where an exception can be thrown from either foo or bar bean
            // so we have enable tracing so we can check it at runtime to get the actual
            // node path taken
            from("direct:start").to("bean:foo").to("bean:bar");
        }
    };
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And then our custom error processor where we can handle the exception and figure out at which node the exception occurred.</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">private class MyErrorProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        // cast to TraceableUnitOfWork so we can work on the intercepted node path
        TraceableUnitOfWork tuow = (TraceableUnitOfWork) exchange.getUnitOfWork();

        // get the list of intercepted nodes
        List&lt;RouteNode&gt; list = tuow.getNodes();
        // get the 3rd last as its the bean
        Processor last = list.get(list.size() - 3).getProcessor();

        // set error message
        exchange.getFault().setBody("Failed at: " + last.toString());
    }

    public String toString() {
        return "MyErrorProcessor";
    }
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="Tracer-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Tracer+Example" title="Tracer Example">Tracer Example</a></li>
	<li><a href="/confluence/display/CAMEL/Debugger" title="Debugger">Debugger</a></li>
	<li><a href="/confluence/display/CAMEL/Delay+Interceptor" title="Delay Interceptor">Delay Interceptor</a></li>
</ul>

     </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/Tracer">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=89192&revisedVersion=34&originalVersion=33">View Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Tracer?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message