You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by semiosis <ca...@louiszuckerman.com> on 2012/12/18 18:54:54 UTC

global onException only works for first to() route item but nothing after that

Hi all,

First thank you for camel, it has been a huge help streamlining our
workflows.  I'm having trouble with a global exception handler and would
appreciate any help or ideas you have.

I have a global onException set up before my route, like this...

		onException(Exception.class).handled(false).to("bean:exceptionHandler")
				.logStackTrace(true);

Then I have a route which goes from an aws-sqs consumer to a chain of beans,
like this...

		from(sqsUri + sqsAuth)
				.unmarshal(json)
				.to("bean:checkin")
				.choice()
				.when(body().contains(
						ProcessA.class.getSimpleName()))
				.pipeline("bean:stepA1",
						"bean:stepA2",
						"bean:stepA3")
				.when(body().contains(
						ProcessB.class.getSimpleName()))
				.pipeline("bean:stepB1",
						"bean:stepB2",
						"bean:stepB3")
				.when(body().contains(Checkin.DUPLICATE))
				.to("bean:duplicateHandler").otherwise()
				.to("bean:exceptionHandler");

If an exception is thrown in "bean:checkin" my exceptionHandler is invoked
and everything is good.  The problem is that if an exception is thrown in
any bean after "bean:checkin" it is silently ignored, not handled by the
global onException.

I've tried everything I can think of to reduce the complexity here.  Even a
simple two-step route behaves the same...

		from(sqsUri + sqsAuth)
				.unmarshal(json)
				.to("bean:checkin")
				.to("bean:duplicateHandler");

If an exception is thrown in "bean:duplicateHandler" it's silently ignored,
so it's not an issue with the choice() or pipeline()s.

It seems that if an exception is thrown anywhere after the first to() then
my global onException is not invoked.

I've spent two days working on this and I'm out of ideas.  What am I doing
wrong?  Please help.

Thank you very much,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Willem jiang <wi...@gmail.com>.
I just added an unit test[1] according to your description, I cannot reproduce the error
Please check it out and do some modify to see if you can reproduce the error.

[1]http://svn.apache.org/viewvc?rev=1423761&view=rev  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Wednesday, December 19, 2012 at 1:54 AM, semiosis wrote:

> Hi all,
>  
> First thank you for camel, it has been a huge help streamlining our
> workflows. I'm having trouble with a global exception handler and would
> appreciate any help or ideas you have.
>  
> I have a global onException set up before my route, like this...
>  
> onException(Exception.class).handled(false).to("bean:exceptionHandler")
> .logStackTrace(true);
>  
> Then I have a route which goes from an aws-sqs consumer to a chain of beans,
> like this...
>  
> from(sqsUri + sqsAuth)
> .unmarshal(json)
> .to("bean:checkin")
> .choice()
> .when(body().contains(
> ProcessA.class.getSimpleName()))
> .pipeline("bean:stepA1",
> "bean:stepA2",
> "bean:stepA3")
> .when(body().contains(
> ProcessB.class.getSimpleName()))
> .pipeline("bean:stepB1",
> "bean:stepB2",
> "bean:stepB3")
> .when(body().contains(Checkin.DUPLICATE))
> .to("bean:duplicateHandler").otherwise()
> .to("bean:exceptionHandler");
>  
> If an exception is thrown in "bean:checkin" my exceptionHandler is invoked
> and everything is good. The problem is that if an exception is thrown in
> any bean after "bean:checkin" it is silently ignored, not handled by the
> global onException.
>  
> I've tried everything I can think of to reduce the complexity here. Even a
> simple two-step route behaves the same...
>  
> from(sqsUri + sqsAuth)
> .unmarshal(json)
> .to("bean:checkin")
> .to("bean:duplicateHandler");
>  
> If an exception is thrown in "bean:duplicateHandler" it's silently ignored,
> so it's not an issue with the choice() or pipeline()s.
>  
> It seems that if an exception is thrown anywhere after the first to() then
> my global onException is not invoked.
>  
> I've spent two days working on this and I'm out of ideas. What am I doing
> wrong? Please help.
>  
> Thank you very much,
>  
> -louis
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Claus,

Yes I read those docs, although with just a few lines here & there out of
context, and no complete example, it was not very helpful.

Is adding getContext().setTracing(true) to my configure() method enough?  Do
I also need to set any properties or options?  Construct a Tracer object? 
It's not clear to me which of all those options are required to just get
basic tracing turned on.

Another thing I should have mentioned, I am extending SpringRouteBuilder and
overriding its configure() method to build my route.

Thanks,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724385.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Dec 18, 2012 at 10:17 PM, semiosis <ca...@louiszuckerman.com> wrote:
> Please forgive my ignorance, but I must be missing something here...
>
>     context.setTracing(true);
>
> i don't have a context object, but i can call getContext() from within
> configure(), which compiles, but then I don't get any additional logging.
>
> And what log should I check?  I have log4j set up with a console appender,
> and I can see my own log statement's output, but none from camel, with or
> without the getContext().setTracing(true).
>
> I tried this in the test class you provided and tracing behaves the same in
> your test class and my production code -- which is to say, tracing doesn't
> give me anything in the logs.
>
> Thanks as always,
>

Did you read the docs at?
http://camel.apache.org/tracer

> -louis
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724320.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
I added a link to [1] on the Camel tracer page.

[1] http://camel.apache.org/camel-jar-dependencies.html

Best,
Christian

On Fri, Dec 21, 2012 at 12:58 AM, semiosis <ca...@louiszuckerman.com> wrote:

> Hi Christian,
>
> And yet, with all that, it was totally not obvious why tracing was
> mysteriously failing.
>
> Thanks again for your help.
>
> For what it's worth, I think it would be really helpful to have a quick
> note
> about the following error on the tracing page to highlight the significance
> of the SLF4j dependency.
>
> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
> details.
>
> This costs nothing and would be a big benefit to others who may encounter
> this issue in the future.
>
> All the best,
>
> -louis
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724475.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Christian,

And yet, with all that, it was totally not obvious why tracing was
mysteriously failing.

Thanks again for your help.

For what it's worth, I think it would be really helpful to have a quick note
about the following error on the tracing page to highlight the significance
of the SLF4j dependency.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.

This costs nothing and would be a big benefit to others who may encounter
this issue in the future.

All the best,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724475.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
Read the doc: http://camel.apache.org/camel-jar-dependencies.html

And Maven also tells you the dependencies:

Christian-Muellers-MacBook-Pro:camel-core cmueller$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]

[INFO]
------------------------------------------------------------------------
[INFO] Building Camel :: Core 2.9.1
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ camel-core ---
[INFO] org.apache.camel:camel-core:bundle:2.9.1
[INFO] +-
com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- org.osgi:org.osgi.core:jar:4.2.0:provided
[INFO] +- junit:junit:jar:4.8.1:test
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:test
[INFO] |  \- log4j:log4j:jar:1.2.16:test
[INFO] +- org.easymock:easymock:jar:3.0:test
[INFO] |  +- cglib:cglib-nodep:jar:2.2:test
[INFO] |  \- org.objenesis:objenesis:jar:1.2:test
[INFO] \- xml-resolver:xml-resolver:jar:1.2:test
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 4.377s
[INFO] Finished at: Thu Dec 20 23:53:20 CET 2012
[INFO] Final Memory: 7M/81M
[INFO]
------------------------------------------------------------------------


Best,
Christian

On Wed, Dec 19, 2012 at 10:25 PM, semiosis <ca...@louiszuckerman.com> wrote:

> Hi Christian,
>
> Thank you very much for providing a comprehensive example of tracing.  As
> it
> turns out there was an error message produced at the top of the output from
> my tests which I had not understood the significance of...
>
> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
> details.
>
> When your known-good example produced this error as well I figured it must
> somehow be related to the lack of tracing output.  The problem is that
> tracing depends on the presence of SLF4j, which I did not have in my
> project.
>
> I added this to my pom.xml and now tracing works:
>
>                 <dependency>
>                         <groupId>org.slf4j</groupId>
>                         <artifactId>slf4j-log4j12</artifactId>
>                         <version>1.7.2</version>
>                 </dependency>
>
> Please consider adding a note about this to the tracer documentation.  (Or
> if it's there already, maybe it could be highlighted, because I didn't see
> it.)
>
> Thanks again for all the help.  I will go back to pursuing the bug in my
> application, now with the benefit of the tracer logs.
>
> Best regards,
>
> -louis
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724402.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Christian,

Thank you very much for providing a comprehensive example of tracing.  As it
turns out there was an error message produced at the top of the output from
my tests which I had not understood the significance of...

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.

When your known-good example produced this error as well I figured it must
somehow be related to the lack of tracing output.  The problem is that
tracing depends on the presence of SLF4j, which I did not have in my
project.

I added this to my pom.xml and now tracing works:

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.2</version>
		</dependency>

Please consider adding a note about this to the tracer documentation.  (Or
if it's there already, maybe it could be highlighted, because I didn't see
it.)

Thanks again for all the help.  I will go back to pursuing the bug in my
application, now with the benefit of the tracer logs.

Best regards,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724402.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
I updated this example for you (you don't have to use inner classes, but
it's easier to share...):

import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class CamelGlobalOnExceptionTest extends CamelTestSupport {

    @Test
    public void test() throws Exception {
        MockEndpoint mockErrorHandler = ((MockEndpoint)
context.getEndpoint("mock:errorHandler"));
        mockErrorHandler.expectedMessageCount(1);

        MockEndpoint mockEnd = ((MockEndpoint)
context.getEndpoint("mock:end"));
        mockEnd.setSleepForEmptyTest(2000);
        mockEnd.expectedMessageCount(0);

        try {
            template.sendBody("direct:start", "Camel");
            fail("CamelExecutionException expected");
        } catch (CamelExecutionException e) {
            // expected
        }

        mockErrorHandler.assertIsSatisfied();
    }

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry registry = super.createRegistry();

        registry.bind("bean1", new MyBean(false));
        registry.bind("bean2", new MyBean(true));

        return registry;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new MyRouteBuilder();
    }

    public static class MyRouteBuilder extends RouteBuilder {
        public void configure() throws Exception {
            getContext().setTracing(true);

            onException(Exception.class)
                .handled(false)
                .to("mock:errorHandler")
                .logStackTrace(true);

            from("direct:start")
                .to("bean:bean1")
                .to("bean:bean2")
                .to("mock:end");
        }
    }

    public static class MyBean {

        private boolean shouldThrowAnException;

        public MyBean(boolean shouldThrowAnException) {
            this.shouldThrowAnException = shouldThrowAnException;
        }

        public void process(Exchange exchange) throws Exception {
            if (shouldThrowAnException) {
                throw new Exception("exception forced for unit test");
            }
        }
    }
}

and  use the following log4j.properties file:

log4j.rootLogger=INFO, file, out

# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1}
- %m%n

# File appender
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1}
- %m%n
log4j.appender.file.file=target/test.log
log4j.appender.file.append=true

and got the following log entries:

2012-12-19 22:05:39,311 [main           ] INFO
Tracer                         -
ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-2 >>>
(route1) from(direct://start) --> bean://bean1 <<< Pattern:InOnly,
Headers:{breadcrumbId=ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-1},
BodyType:String, Body:Camel
2012-12-19 22:05:39,332 [main           ] INFO
LazyLoadingTypeConverter       - Loaded additional 0 type converters (total
169 type converters) in 0.001 seconds
2012-12-19 22:05:39,336 [main           ] INFO
Tracer                         -
ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-2 >>>
(route1) bean://bean1 --> bean://bean2 <<< Pattern:InOnly,
Headers:{breadcrumbId=ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-1},
BodyType:String, Body:Camel
2012-12-19 22:05:39,338 [main           ] INFO
Tracer                         -
ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-2 >>>
(route1) bean://bean2 --> OnException[Exception] <<< Pattern:InOnly,
Headers:{breadcrumbId=ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-1,
CamelRedeliveryCounter=0, CamelRedelivered=false}, BodyType:String,
Body:Camel
2012-12-19 22:05:39,338 [main           ] INFO
Tracer                         -
ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-2 >>>
OnException[Exception] --> mock://errorHandler <<< Pattern:InOnly,
Headers:{breadcrumbId=ID-Christian-Muellers-MacBook-Pro-local-55586-1355951138794-0-1,
CamelRedeliveryCounter=0, CamelRedelivered=false}, BodyType:String,
Body:Camel

This should also work for you...

Best,
Christian

On Wed, Dec 19, 2012 at 7:05 PM, semiosis <ca...@louiszuckerman.com> wrote:

> Hi Christian,
>
> I am using the Java DSL, overriding the configure() method in a subclass of
> SpringRouteBuilder.  I added this line to my configure() method, also to
> the
> configure() method in the test case you sent me...
>
>    getContext().setTracing(true)
>
> and added some explicit log4j info messages to the code to verify logging
> is
> working.  All i see are my own messages, nothing from camel.
>
> To recap, my problem is that I am having trouble with exception handling
> after the first bean in my route.  I want to trace execution so that I can
> figure out where that exception is going when it is silently dropped.  But
> I
> can't get tracing to work even in the simple test case.
>
> Thanks again for all the help,
>
> -louis
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724392.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Christian,

I am using the Java DSL, overriding the configure() method in a subclass of
SpringRouteBuilder.  I added this line to my configure() method, also to the
configure() method in the test case you sent me...

   getContext().setTracing(true)

and added some explicit log4j info messages to the code to verify logging is
working.  All i see are my own messages, nothing from camel.

To recap, my problem is that I am having trouble with exception handling
after the first bean in my route.  I want to trace execution so that I can
figure out where that exception is going when it is silently dropped.  But I
can't get tracing to work even in the simple test case.

Thanks again for all the help,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724392.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
How do you define your camel routes? If you use the XML DSL, there is a
trace attribute in the camelContext element which you have to set to true.
If you use the java DSL, there is a setTracing() method on the Camel
context which you have to set to true. I didn't understand what you issue
is?
As Claus already mentioned, everything is described at [1].

If you are a beginner, I recommend to buy a copy of this book [2].

[1] http://camel.apache.org/tracer
[2] http://www.manning.com/ibsen/

Best,
Christian

On Tue, Dec 18, 2012 at 10:17 PM, semiosis <ca...@louiszuckerman.com> wrote:

> Please forgive my ignorance, but I must be missing something here...
>
>     context.setTracing(true);
>
> i don't have a context object, but i can call getContext() from within
> configure(), which compiles, but then I don't get any additional logging.
>
> And what log should I check?  I have log4j set up with a console appender,
> and I can see my own log statement's output, but none from camel, with or
> without the getContext().setTracing(true).
>
> I tried this in the test class you provided and tracing behaves the same in
> your test class and my production code -- which is to say, tracing doesn't
> give me anything in the logs.
>
> Thanks as always,
>
> -louis
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724320.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Willem,

Thanks for the tip.  Here is my log4j.properties, which sends my explicit
log statements to the console, but nothing else...

log4j.rootLogger=DEBUG, Console

log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.Console.ImmediateFlush=true


Thanks again,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724386.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Willem jiang <wi...@gmail.com>.
Hi,

You should be able to find some log which is start with Tracer like below, if you setup the log4j.properties rightly.

INFO Tracer xxx  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Wednesday, December 19, 2012 at 5:17 AM, semiosis wrote:

> Please forgive my ignorance, but I must be missing something here...
>  
> context.setTracing(true);
>  
> i don't have a context object, but i can call getContext() from within
> configure(), which compiles, but then I don't get any additional logging.
>  
> And what log should I check? I have log4j set up with a console appender,
> and I can see my own log statement's output, but none from camel, with or
> without the getContext().setTracing(true).
>  
> I tried this in the test class you provided and tracing behaves the same in
> your test class and my production code -- which is to say, tracing doesn't
> give me anything in the logs.
>  
> Thanks as always,
>  
> -louis
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724320.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Please forgive my ignorance, but I must be missing something here...

    context.setTracing(true);

i don't have a context object, but i can call getContext() from within
configure(), which compiles, but then I don't get any additional logging.

And what log should I check?  I have log4j set up with a console appender,
and I can see my own log statement's output, but none from camel, with or
without the getContext().setTracing(true).

I tried this in the test class you provided and tracing behaves the same in
your test class and my production code -- which is to say, tracing doesn't
give me anything in the logs.

Thanks as always,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724320.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
That's simple:

You have simply to enable the tracing:
context.setTracing(true);


    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                context.setTracing(true);

                onException(Exception.class)
                    .handled(false)
                    .to("mock:errorHandler")
                    .logStackTrace(true);

                from("direct:start")
                    .to("bean:bean1")
                    .to("bean:bean2")
                    .to("mock:end");
            }
        };
    }

... and check the log...

Best,
Christian

On Tue, Dec 18, 2012 at 8:31 PM, semiosis <ca...@louiszuckerman.com> wrote:

> ve any other thoughts on how to further




--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Hi Christian,

Thanks for sending that test case.  I tried it and it works as you would
expect.  It also works when pulling from SQS.  I could not reproduce my
problem in the test case.  This is helpful because I now have some
confidence in my camel route configuration, and can start to look for other
issues which could be causing this.

Do you have any other thoughts on how to further diagnose this problem?

I would like to use tracing to find out what happens after the exception is
thrown in my problematic code, but I wasn't able to get tracing to work at
all after messing with it for an hour or two last night.

Thanks again,

-louis



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724306.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: global onException only works for first to() route item but nothing after that

Posted by Christian Müller <ch...@gmail.com>.
It works in general:

import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class CamelGlobalOnExceptionTest extends CamelTestSupport {

    @Test
    public void test() throws Exception {
        MockEndpoint mockErrorHandler = ((MockEndpoint)
context.getEndpoint("mock:errorHandler"));
        mockErrorHandler.expectedMessageCount(1);

        MockEndpoint mockEnd = ((MockEndpoint)
context.getEndpoint("mock:end"));
        mockEnd.setSleepForEmptyTest(2000);
        mockEnd.expectedMessageCount(0);

        try {
            template.sendBody("direct:start", "Camel");
            fail("CamelExecutionException expected");
        } catch (CamelExecutionException e) {
            // expected
        }

        mockErrorHandler.assertIsSatisfied();
    }

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry registry = super.createRegistry();

        registry.bind("bean1", new MyBean(false));
        registry.bind("bean2", new MyBean(true));

        return registry;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                onException(Exception.class)
                    .handled(false)
                    .to("mock:errorHandler")
                    .logStackTrace(true);

                from("direct:start")
                    .to("bean:bean1")
                    .to("bean:bean2")
                    .to("mock:end");
            }
        };
    }

    public static class MyBean {

        private boolean shouldThrowAnException;

        public MyBean(boolean shouldThrowAnException) {
            this.shouldThrowAnException = shouldThrowAnException;
        }

        public void process(Exchange exchange) throws Exception {
            if (shouldThrowAnException) {
                throw new Exception("exception forced for unit test");
            }
        }
    }
}

Can you try this example with the aws-component?

Best,
Christian

On Tue, Dec 18, 2012 at 6:57 PM, semiosis <ca...@louiszuckerman.com> wrote:

> Using camel version 2.9.1 on OpenJDK 6 by the way.  Thanks again!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724298.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: global onException only works for first to() route item but nothing after that

Posted by semiosis <ca...@louiszuckerman.com>.
Using camel version 2.9.1 on OpenJDK 6 by the way.  Thanks again!



--
View this message in context: http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724298.html
Sent from the Camel - Users mailing list archive at Nabble.com.