Use the defaultErrorHandler if you want handle the exception (not
rethrowing the exception).

Using the following test, the exception is logged at level WARN (using
Camel 2.11-SNAPSHOT):

package org.apache.camel.builder;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.LoggingLevel;

public class LoggingErrorHandlerTest extends ContextTestSupport {

    public void testLoggingErrorHandler() throws Exception {
        getMockEndpoint("mock:end").expectedMessageCount(1);

        template.sendBody("direct:start", "foo");

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() {
                from("direct:start")

.errorHandler(loggingErrorHandler("com.mycompany.foo").level(LoggingLevel.WARN))
                    .to("mock:end")
                    .throwException(new Exception("forced exception for
test"));
            }
        };
    }
}

Log:
2013-03-20 23:48:21,404 [main           ] WARN
foo                            - Failed delivery for (MessageId:
ID-Christians-MacBook-Pro-local-53438-1363819701117-0-1 on ExchangeId:
ID-Christians-MacBook-Pro-local-53438-1363819701117-0-2). Exhausted after
delivery attempt: 1 caught: java.lang.Exception: forced exception for test
java.lang.Exception: forced exception for test
    at
org.apache.camel.builder.LoggingErrorHandlerTest$1.configure(LoggingErrorHandlerTest.java:39)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/test-classes/:]
    at
org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/classes/:]
    at
org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/classes/:]
    at
org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/classes/:]
    at
org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:648)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/classes/:]
    at
org.apache.camel.ContextTestSupport.setUp(ContextTestSupport.java:115)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/test-classes/:]
    at junit.framework.TestCase.runBare(TestCase.java:139)[junit-4.11.jar:]
    at
org.apache.camel.TestSupport.runBare(TestSupport.java:58)[file:/Users/cmueller/workspaceCamel/camel/camel-core/target/test-classes/:]
    at
junit.framework.TestResult$1.protect(TestResult.java:122)[junit-4.11.jar:]
    at
junit.framework.TestResult.runProtected(TestResult.java:142)[junit-4.11.jar:]
    at junit.framework.TestResult.run(TestResult.java:125)[junit-4.11.jar:]
    at junit.framework.TestCase.run(TestCase.java:129)[junit-4.11.jar:]
    at
junit.framework.TestSuite.runTest(TestSuite.java:255)[junit-4.11.jar:]
    at junit.framework.TestSuite.run(TestSuite.java:250)[junit-4.11.jar:]
    at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)[junit-4.11.jar:]
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/350/1/.cp/:]
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/349/1/.cp/:]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/349/1/.cp/:]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/349/1/.cp/:]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/349/1/.cp/:]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)[file:/Applications/eclipse-4.2.2/configuration/org.eclipse.osgi/bundles/349/1/.cp/:]

Best,
Christian

On Thu, Mar 14, 2013 at 12:54 PM, dancerjohn <winddancerj...@gmail.com>wrote:

> So, I have a camel context that has a DeadLetterChannel with no
> redeliveries
> at the context level. Within the context I have a route:
>
> from("direct:input")
>      .routeId("enrichHeader")
>      .setHeader("myHeader").constant("someValue)
>      .to("direct:output");
>
> I have a unit test in which I interceptSendToEndpoint("direct:output") and
> cause an exception to be thrown.
>
> Then in the unit test I do producerTemplate.sendBody(theBody).
>
> Now, as configured above on exception the message gets sent to the dead
> letter channel. All's well. However, if I configure a loggingErrorHandler I
> get odd behavior. So if I update the above route as follows:
>
> from("direct:input")
>      .routeId("enrichHeader")
>
>      .errorHandler(
>         loggingErrorHandler("com.myco.myproject")
>              .level(LoggingLevel.WARN))
>
>      .setHeader("myHeader").constant("someValue)
>      .to("direct:output");
>
> When I run the test now I get two unexpected behaviors. First, the
> exception
> is still logged at level ERROR instead of the configured WARN. Second, the
> exception is propagated back to the producerTemplate.sendBody(theBody)
> invokation.
>
> On the one hand, the logging at ERROR is obviously odd. The other part that
> seems odd is that the handler is propagating the exception. I would have
> thought it would have marked it as handled and be done with it.
>
> Is this expected behavior? Seems like documentation for the
> LoggingErrorHandler is lacking.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Unexpected-behavior-of-LoggingErrorHandler-in-Camel-tp5729173.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Reply via email to