You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2017/08/25 08:22:03 UTC
svn commit: r1017260 [18/40] - in /websites/production/camel/content: ./
cache/
Modified: websites/production/camel/content/error-handler.html
==============================================================================
--- websites/production/camel/content/error-handler.html (original)
+++ websites/production/camel/content/error-handler.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js' type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Error Handler
@@ -86,165 +75,47 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="ErrorHandler-ErrorHandler">Error Handler</h2><p>Camel supports pluggable <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/ErrorHandler.html">ErrorHandler</a> strategies to deal with errors processing an <a shape="rect" href="event-driven-consumer.html">Event Driven Consumer</a>. An alternative is to specify the error handling directly in the <a shape="rect" href="dsl.html">DSL</a> using the <a shape="rect" href="exception-clause.html">Exception Clause</a>.</p><p>For introduction and background material see <a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a>.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Exception Clause</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Using <a shape
="rect" href="error-handler.html">Error Handler</a> combined with <a shape="rect" href="exception-clause.html">Exception Clause</a> is a very powerful combination. We encourage end-users to use this combination in your error handling strategies. See samples and <a shape="rect" href="exception-clause.html">Exception Clause</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Using try ... catch ... finally</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Related to error handling is the <a shape="rect" href="try-catch-finally.html">Try Catch Finally</a> as DSL you can use directly in your route. Its basically a mimic of the regular try catch finally in the Java language but with more power.</p></div></div><p>The current implementations Camel provides out of the box are:</p><h4 id="ErrorHandler-Non-transacted:">Non-transacte
d<strong>:</strong></h4><ul><li><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> is the default error handler in Camel. This error handler does not support a dead letter queue, it will propagate exceptions back to the caller, as if there where no error handler at all. It has a limited set of features.</li><li><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> which supports attempting to redeliver the message exchange a number of times before sending it to a dead letter endpoint</li><li><strong><code>LoggingErrorHandler</code></strong> for just catching and logging exceptions</li><li><strong><code>NoErrorHandler</code></strong> for no error handling</li></ul><h4 id="ErrorHandler-Transacted:">Transacted:</h4><ul><li><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> is the default error handler in Camel for transacted routes. See the <a shape="rect" href="transactional-client.html">Transactional Client</a> EIP p
attern.</li></ul><p>These error handlers can be applied in the <a shape="rect" href="dsl.html">DSL</a> to an entire set of rules or a specific routing rule as we show in the next examples. Error handling rules are inherited on each routing rule within a single <a shape="rect" href="routebuilder.html">RouteBuilder</a></p><h3 id="ErrorHandler-ShortSummaryoftheProvidedErrorHandlers">Short Summary of the Provided Error Handlers</h3><h4 id="ErrorHandler-DefaultErrorHandler"><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a></h4><p>The <a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> is the default error handler in Camel. Unlike <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> it does not have any dead letter queue, and do <strong>not</strong> handle exceptions by default.</p><h4 id="ErrorHandler-DeadLetterChannel"><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></h4><p>The <a shape="rect" href="dead
-letter-channel.html">Dead Letter Channel</a> will redeliver at most 6 times using 1 second delay, and if the exchange failed it will be logged at <strong><code>ERROR</code></strong> level.</p><p>You can configure the default dead letter endpoint to use:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- // using dead letter channel with a seda queue for errors
- errorHandler(deadLetterChannel("seda:errors"));
-
- // here is our route
- from("seda:a").to("seda:b");
- }
-};
-]]></script>
-</div></div>or in Spring DSL:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
- <property name="deadLetterUri" value="log:dead"/>
+<div class="wiki-content maincontent"><h2 id="ErrorHandler-ErrorHandler">Error Handler</h2><p>Camel supports pluggable <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/ErrorHandler.html">ErrorHandler</a> strategies to deal with errors processing an <a shape="rect" href="event-driven-consumer.html">Event Driven Consumer</a>. An alternative is to specify the error handling directly in the <a shape="rect" href="dsl.html">DSL</a> using the <a shape="rect" href="exception-clause.html">Exception Clause</a>.</p><p>For introduction and background material see <a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a>.</p><parameter ac:name="title">Exception Clause</parameter><rich-text-body><p>Using <a shape="rect" href="error-handler.html">Error Handler</a> combined with <a shape="rect" href="exception-clause.html">Exception Clause</a> is a very powerful combination. We encourage end-users t
o use this combination in your error handling strategies. See samples and <a shape="rect" href="exception-clause.html">Exception Clause</a>.</p></rich-text-body><parameter ac:name="title">Using try ... catch ... finally</parameter><rich-text-body><p>Related to error handling is the <a shape="rect" href="try-catch-finally.html">Try Catch Finally</a> as DSL you can use directly in your route. Its basically a mimic of the regular try catch finally in the Java language but with more power.</p></rich-text-body><p>The current implementations Camel provides out of the box are:</p><h4 id="ErrorHandler-Non-transacted:">Non-transacted<strong>:</strong></h4><ul><li><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> is the default error handler in Camel. This error handler does not support a dead letter queue, it will propagate exceptions back to the caller, as if there where no error handler at all. It has a limited set of features.</li><li><a shape="rect" href="dead-lette
r-channel.html">Dead Letter Channel</a> which supports attempting to redeliver the message exchange a number of times before sending it to a dead letter endpoint</li><li><strong><code>LoggingErrorHandler</code></strong> for just catching and logging exceptions</li><li><strong><code>NoErrorHandler</code></strong> for no error handling</li></ul><h4 id="ErrorHandler-Transacted:">Transacted:</h4><ul><li><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> is the default error handler in Camel for transacted routes. See the <a shape="rect" href="transactional-client.html">Transactional Client</a> EIP pattern.</li></ul><p>These error handlers can be applied in the <a shape="rect" href="dsl.html">DSL</a> to an entire set of rules or a specific routing rule as we show in the next examples. Error handling rules are inherited on each routing rule within a single <a shape="rect" href="routebuilder.html">RouteBuilder</a></p><h3 id="ErrorHandler-ShortSummaryoftheProvid
edErrorHandlers">Short Summary of the Provided Error Handlers</h3><h4 id="ErrorHandler-DefaultErrorHandler"><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a></h4><p>The <a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> is the default error handler in Camel. Unlike <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> it does not have any dead letter queue, and do <strong>not</strong> handle exceptions by default.</p><h4 id="ErrorHandler-DeadLetterChannel"><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></h4><p>The <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> will redeliver at most 6 times using 1 second delay, and if the exchange failed it will be logged at <strong><code>ERROR</code></strong> level.</p><p>You can configure the default dead letter endpoint to use:<plain-text-body>{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder
/ErrorHandlerTest.java}</plain-text-body>or in Spring DSL:</p><parameter ac:name="language">xml</parameter><plain-text-body><bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+ <property name="deadLetterUri" value="log:dead"/>
</bean>
-<camelContext errorHandlerRef="deadLetterErrorHandler" xmlns="http://camel.apache.org/schema/spring">
+<camelContext errorHandlerRef="deadLetterErrorHandler" xmlns="http://camel.apache.org/schema/spring">
<!-- ... -->
</camelContext>
-]]></script>
-</div></div><p>or also from <strong>Camel 2.3.0:<br clear="none"></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead">
+</plain-text-body><p>or also from <strong>Camel 2.3.0:<br clear="none"></strong></p><parameter ac:name="language">xml</parameter><plain-text-body><camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead">
-<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
+<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
...
</camel:camelContext>
-]]></script>
-</div></div><h4 id="ErrorHandler-TheLoggingErrorHandler">The <code>LoggingErrorHandler</code></h4><p>The logging error handler will log (by default at <strong><code>ERROR</code></strong> level) whenever an uncaught exception is thrown. The logging category, logger and level may all be defined in the builder.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.INFO));
-]]></script>
-</div></div><p>or in Spring DSL:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="loggingErrorHandler" class="org.apache.camel.builder.LoggingErrorHandler">
- <property name="logName" value="mylogger.name"/>
- <property name="level" value="DEBUG"/>
+</plain-text-body><h4 id="ErrorHandler-TheLoggingErrorHandler">The <code>LoggingErrorHandler</code></h4><p>The logging error handler will log (by default at <strong><code>ERROR</code></strong> level) whenever an uncaught exception is thrown. The logging category, logger and level may all be defined in the builder.</p><parameter ac:name="language">java</parameter><plain-text-body>errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.INFO));
+</plain-text-body><p>or in Spring DSL:</p><parameter ac:name="language">xml</parameter><plain-text-body><bean id="loggingErrorHandler" class="org.apache.camel.builder.LoggingErrorHandler">
+ <property name="logName" value="mylogger.name"/>
+ <property name="level" value="DEBUG"/>
</bean>
-<camelContext errorHandlerRef="loggingErrorHandler" xmlns="http://camel.apache.org/schema/spring">
+<camelContext errorHandlerRef="loggingErrorHandler" xmlns="http://camel.apache.org/schema/spring">
...
</camelContext>
-]]></script>
-</div></div><p>or also from <strong>Camel 2.3.0</strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camel:errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" logName="mylogger.name" level="DEBUG"/>
+</plain-text-body><p>or also from <strong>Camel 2.3.0</strong>:</p><parameter ac:name="language">xml</parameter><plain-text-body><camel:errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" logName="mylogger.name" level="DEBUG"/>
-<camel:camelContext errorHandlerRef="loggingErrorHandler">
+<camel:camelContext errorHandlerRef="loggingErrorHandler">
...
</camel:camelContext>
-]]></script>
-</div></div><p>This would create an error handler which logs exceptions using the category <strong><code>mylogger.name</code></strong> and uses the level <strong><code>INFO</code></strong> for all log messages created.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("seda:a")
- .errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.DEBUG))
- .to("seda:b");
-]]></script>
-</div></div><p>Loggers may also be defined for specific routes.</p><h4 id="ErrorHandler-TheNoErrorHandler">The <code>NoErrorHandler</code></h4><p>The no error handler is to be used for disabling error handling.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[errorHandler(noErrorHandler());
-]]></script>
-</div></div><p>or in Spring DSL:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+</plain-text-body><p>This would create an error handler which logs exceptions using the category <strong><code>mylogger.name</code></strong> and uses the level <strong><code>INFO</code></strong> for all log messages created.</p><parameter ac:name="language">java</parameter><plain-text-body>from("seda:a")
+ .errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.DEBUG))
+ .to("seda:b");
+</plain-text-body><p>Loggers may also be defined for specific routes.</p><h4 id="ErrorHandler-TheNoErrorHandler">The <code>NoErrorHandler</code></h4><p>The no error handler is to be used for disabling error handling.</p><parameter ac:name="language">java</parameter><plain-text-body>errorHandler(noErrorHandler());
+</plain-text-body><p>or in Spring DSL:</p><parameter ac:name="language">xml</parameter><plain-text-body><bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
-<camelContext errorHandlerRef="noErrorHandler" xmlns="http://camel.apache.org/schema/spring">
+<camelContext errorHandlerRef="noErrorHandler" xmlns="http://camel.apache.org/schema/spring">
...
</camelContext>
-]]></script>
-</div></div><p>or also from <strong>Camel 2.3.0</strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camel:errorHandler id="noErrorHandler" type="NoErrorHandler"/>
+</plain-text-body><p>or also from <strong>Camel 2.3.0</strong>:</p><parameter ac:name="language">xml</parameter><plain-text-body><camel:errorHandler id="noErrorHandler" type="NoErrorHandler"/>
-<camel:camelContext errorHandlerRef="noErrorHandler">
+<camel:camelContext errorHandlerRef="noErrorHandler">
...
</camel:camelContext>
-]]></script>
-</div></div><h4 id="ErrorHandler-TransactionErrorHandler"><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a></h4><p>The <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> is the default error handler in Camel for transacted routes.</p><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you have marked a route as transacted using the <strong><code>transacted</code></strong> DSL then Camel will automatic use a <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>. It will try to lookup the global/per route configured error handler and use it if its a <strong><code>TransactionErrorHandlerBuilder</code></strong> instance. If not Camel will automatic create a temporary <a shape="rect" href="transactionerrorhandler.html">TransactionE
rrorHandler</a> that overrules the default error handler. This is convention over configuration.</p></div></div><h3 id="ErrorHandler-FeaturesSupportbyVariouss">Features Support by Various <a shape="rect" href="error-handler.html">Error Handler</a>s</h3><p>Here is a breakdown of which features is supported by the <a shape="rect" href="error-handler.html">Error Handler</a>(s):</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Feature</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Supported By The Following <a shape="rect" href="error-handler.html">Error Handler</a></p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><em><code>all scopes</code></em></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-
letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onException</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onWhen</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>continued</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.htm
l">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>handled</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Custom <code>ExceptionPolicy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useOriginalBody</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>retryWhile</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onRedelivery</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html
">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>RedeliveryPolicy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>asyncDelayedRedelivery</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>redeliverWhileStopping</code></p></td><td c
olspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><em><code>dead letter queue</code></em></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onPrepareFailure</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a><span>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></span></p></td></tr></tbody></table></div><p>See <a shape="rect" href="exception-clause.html">Exception Clause</a> documentation for documentation of some of the features ab
ove.</p><h3 id="ErrorHandler-Scopes">Scopes</h3><p>The error handler is scoped as either</p><ul class="alternate"><li>global</li><li>per route</li></ul><p>The following example shows how you can register a global error handler (in this case using the logging handler)</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- // use logging error handler
- errorHandler(loggingErrorHandler("com.mycompany.foo"));
-
- // here is our regular route
- from("seda:a").to("seda:b");
- }
-};
-]]></script>
-</div></div>The following example shows how you can register a route specific error handler; the customized logging handler is only registered for the route from <a shape="rect" href="endpoint.html">Endpoint</a> <strong><code>seda:a</code></strong><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- // this route is using a nested logging error handler
- from("seda:a")
- // here we configure the logging error handler
- .errorHandler(loggingErrorHandler("com.mycompany.foo"))
- // and we continue with the routing here
- .to("seda:b");
-
- // this route will use the default error handler (DeadLetterChannel)
- from("seda:b").to("seda:c");
- }
-};
-]]></script>
-</div></div><h3 id="ErrorHandler-SpringBasedConfiguration">Spring Based Configuration</h3><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Java DSL vs. Spring DSL</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The error handler is configured a bit differently in Java DSL and Spring DSL. Spring DSL relies more on standard Spring bean configuration whereas Java DSL uses fluent builders.</p></div></div><p>The error handler can be configured as a spring bean and scoped in:</p><ul class="alternate"><li>global (the camelContext tag)</li><li>per route (the route tag)</li><li>or per policy (the policy/transacted tag)</li></ul><p>The error handler is configured with the <strong><code>errorHandlerRef</code></strong> attribute.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Error Handler Hierarc
hy</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The error handlers is inherited, so if you only have set a global error handler then its use everywhere. But you can override this in a route and use another error handler.</p></div></div><h4 id="ErrorHandler-SpringBasedConfigurationSample">Spring Based Configuration Sample</h4><p>In this sample we configure a <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> on the route that should redeliver at most 3 times and use a little delay before retrying.<br clear="none"> First, we configure the reference to <strong><code>myDeadLetterErrorHandler</code></strong> using the <strong><code>errorHandlerRef</code></strong> attribute on the <code>route</code> tag.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <template id="myTemplate"/>
-<!-- set the errorHandlerRef to our DeadLetterChannel, this applies for this route only -->
- <route errorHandlerRef="myDeadLetterErrorHandler">
- <from uri="direct:in"/>
- <process ref="myFailureProcessor"/>
- <to uri="mock:result"/>
- </route>
- </camelContext>
-]]></script>
-</div></div>Then we configure <strong><code>myDeadLetterErrorHandler</code></strong> that is our <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a>. This configuration is standard Spring using the bean element.<br clear="none">Finally, we have another spring bean for the redelivery policy where we can configure the options for how many times to redeliver, delays etc.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
- <!-- here we configure our DeadLetterChannel -->
-<bean id="myDeadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
- <!-- exchanges is routed to mock:dead in cased redelivery failed -->
- <property name="deadLetterUri" value="mock:dead"/>
- <!-- reference the redelivery policy to use -->
- <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig"/>
- </bean>
-
- <!-- here we set the redelivery settings -->
-<bean id="myRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
- <!-- try redelivery at most 3 times, after that the exchange is dead and its routed to the mock:dead endpoint -->
- <property name="maximumRedeliveries" value="3"/>
- <!-- delay 250ms before redelivery -->
- <property name="redeliveryDelay" value="250"/>
- </bean>
-]]></script>
-</div></div>From <strong>Camel 2.3.0</strong>, camel provides a customer bean configuration for the Error Handler, you can find the examples here.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" logName="foo" level="INFO" xmlns="http://camel.apache.org/schema/spring"/>
-
-<!-- If don't specify type attribute, the type value will be set to DefaultErrorHandler -->
-<errorHandler id="errorHandler" xmlns="http://camel.apache.org/schema/spring"/>
-
-<!-- You can define the redeliveryPolicy inside of the errorHandler -->
-<camel:errorHandler id="defaultErrorHandler" type="DefaultErrorHandler">
- <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0" logStackTrace="false"/>
-</camel:errorHandler>
-
-<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead">
- <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000" logHandled="true" asyncDelayedRedelivery="true"/>
-</camel:errorHandler>
-
-<bean id="myErrorProcessor" class="org.apache.camel.spring.handler.MyErrorProcessor"/>
-
-<!-- TX error handler can be configured using a template -->
-<camel:errorHandler id="transactionErrorHandler" type="TransactionErrorHandler"
- transactionTemplateRef="PROPAGATION_REQUIRED" onRedeliveryRef="myErrorProcessor"/>
-
-<!-- or using a transaction manager -->
-<camel:errorHandler id="txEH" type="TransactionErrorHandler" transactionManagerRef="txManager"/>
-
-<!-- You can also define the errorHandler inside the camelContext -->
-<camelContext errorHandlerRef="noErrorHandler" xmlns="http://camel.apache.org/schema/spring">
- <errorHandler id="noErrorHandler" type="NoErrorHandler"/>
-</camelContext>
-]]></script>
-</div></div><h3 id="ErrorHandler-UsingtheTransactionalErrorHandler">Using the <code>TransactionalErrorHandler</code></h3><p>The <strong><code>TransactionalErrorHandler</code></strong> is based on spring transaction. This requires the usage of the camel-spring component. See <a shape="rect" href="transactional-client.html">Transactional Client</a> that has many samples for how to use and transactional behavior and configuration with this error handler.</p><h3 id="ErrorHandler-Seealso">See also</h3><ul class="alternate"><li><a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a> for introduction and background material on error handling in Camel</li><li><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> for the dead letter error handler</li><li><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> for the default error handler in Camel</li><li><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHa
ndler</a> for the default error handler for transacted routes</li><li><a shape="rect" href="transactional-client.html">Transactional Client</a> for transactional behavior</li><li><a shape="rect" href="exception-clause.html">Exception Clause</a> as it supports <strong>handling</strong> thrown exceptions</li><li><a shape="rect" href="try-catch-finally.html">Try Catch Finally</a> for try ... catch ... finally as DSL you can use in the routing</li></ul></div>
+</plain-text-body><h4 id="ErrorHandler-TransactionErrorHandler"><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a></h4><p>The <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> is the default error handler in Camel for transacted routes.</p><parameter ac:name="">[TransactionErrorHandler] is default for transacted routes</parameter><rich-text-body><p>If you have marked a route as transacted using the <strong><code>transacted</code></strong> DSL then Camel will automatic use a <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>. It will try to lookup the global/per route configured error handler and use it if its a <strong><code>TransactionErrorHandlerBuilder</code></strong> instance. If not Camel will automatic create a temporary <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> that overrules the default error handler. This is convention over configuration.</p></rich-t
ext-body><h3 id="ErrorHandler-FeaturesSupportbyVariouss">Features Support by Various <a shape="rect" href="error-handler.html">Error Handler</a>s</h3><p>Here is a breakdown of which features is supported by the <a shape="rect" href="error-handler.html">Error Handler</a>(s):</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Feature</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Supported By The Following <a shape="rect" href="error-handler.html">Error Handler</a></p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><em><code>all scopes</code></em></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="conflu
enceTd"><p><code>onException</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onWhen</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>continued</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler
</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>handled</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Custom <code>ExceptionPolicy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>useOriginalBody</code></p></td><td colspan="1" rowspan="1" class="conflu
enceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>retryWhile</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onRedelivery</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a><
/p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>RedeliveryPolicy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>asyncDelayedRedelivery</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>redeliverWhileStopping</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultE
rrorHandler</a>, <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><em><code>dead letter queue</code></em></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>onPrepareFailure</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a><span>, <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></span></p></td></tr></tbody></table></div><p>See <a shape="rect" href="exception-clause.html">Exception Clause</a> documentation for documentation of some of the features above.</p><h3 id="ErrorHandler-Scopes">Scopes</h3><p>The error handler is scoped as either</p><ul class="
alternate"><li>global</li><li>per route</li></ul><p>The following example shows how you can register a global error handler (in this case using the logging handler)<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}</plain-text-body>The following example shows how you can register a route specific error handler; the customized logging handler is only registered for the route from <a shape="rect" href="endpoint.html">Endpoint</a> <strong><code>seda:a</code></strong><plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}</plain-text-body></p><h3 id="ErrorHandler-SpringBasedConfiguration">Spring Based Configuration</h3><parameter ac:name="title">Java DSL vs. Spring DSL</parameter><rich-text-body><p>The error handler is configured a bit differently in Java DSL and Spring DSL. Spring DSL relies more on standard Spring bean configur
ation whereas Java DSL uses fluent builders.</p></rich-text-body><p>The error handler can be configured as a spring bean and scoped in:</p><ul class="alternate"><li>global (the camelContext tag)</li><li>per route (the route tag)</li><li>or per policy (the policy/transacted tag)</li></ul><p>The error handler is configured with the <strong><code>errorHandlerRef</code></strong> attribute.</p><parameter ac:name="title">Error Handler Hierarchy</parameter><rich-text-body><p>The error handlers is inherited, so if you only have set a global error handler then its use everywhere. But you can override this in a route and use another error handler.</p></rich-text-body><h4 id="ErrorHandler-SpringBasedConfigurationSample">Spring Based Configuration Sample</h4><p>In this sample we configure a <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> on the route that should redeliver at most 3 times and use a little delay before retrying.<br clear="none"> First, we configure the ref
erence to <strong><code>myDeadLetterErrorHandler</code></strong> using the <strong><code>errorHandlerRef</code></strong> attribute on the <code>route</code> tag.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest-context.xml}</plain-text-body>Then we configure <strong><code>myDeadLetterErrorHandler</code></strong> that is our <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a>. This configuration is standard Spring using the bean element.<br clear="none">Finally, we have another spring bean for the redelivery policy where we can configure the options for how many times to redeliver, delays etc.<plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest-context.xml}</plain-text-body>From <strong>Camel 2.3.0</strong>, camel provides
a customer bean configuration for the Error Handler, you can find the examples here.<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml}</plain-text-body></p><h3 id="ErrorHandler-UsingtheTransactionalErrorHandler">Using the <code>TransactionalErrorHandler</code></h3><p>The <strong><code>TransactionalErrorHandler</code></strong> is based on spring transaction. This requires the usage of the camel-spring component. See <a shape="rect" href="transactional-client.html">Transactional Client</a> that has many samples for how to use and transactional behavior and configuration with this error handler.</p><h3 id="ErrorHandler-Seealso">See also</h3><ul class="alternate"><li><a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a> for introduction and background material on error handling in Camel</li><li><a shape="rect" href="dead-letter-chann
el.html">Dead Letter Channel</a> for the dead letter error handler</li><li><a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a> for the default error handler in Camel</li><li><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> for the default error handler for transacted routes</li><li><a shape="rect" href="transactional-client.html">Transactional Client</a> for transactional behavior</li><li><a shape="rect" href="exception-clause.html">Exception Clause</a> as it supports <strong>handling</strong> thrown exceptions</li><li><a shape="rect" href="try-catch-finally.html">Try Catch Finally</a> for try ... catch ... finally as DSL you can use in the routing</li></ul></div>
</td>
<td valign="top">
<div class="navigation">