You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by woggle23 <ma...@yahoo.co.uk> on 2011/06/24 11:36:10 UTC

intercept using adviceWith()

Morning All

I'm attempting to simulate errors in order to test my error handling. In my
test class I create the following interception in the createCamelContext
method:

context.addRoutes(new RouteSupport());

RouteDefinition route = context.getRouteDefinition("Route1");
		route.adviceWith(context, new RouteBuilder(){
		@Override
		public void configure() throws Exception{
		interceptSendToEndpoint("bean:sqlBuilder?method=makeEntryGeneric")				
.skipSendToOriginalEndpoint()
			.process(new SimulateDatabaseError());
		}
	});

Running a test which causes a message to route to
"bean:sqlBuilder?method=makeEntryGeneric" performs correctly; i.e. the
message is intercepted, an exception is thrown and handled as expected (the
test passes).

If I add a 2nd intercept to the above:

route = context.getRouteDefinition("DBContentsInterface");
		route.adviceWith(context, new RouteBuilder(){
		@Override
		public void configure() throws Exception{
			interceptSendToEndpoint("bean:sqlBuilder?method=getUpdatedTrackInfo")
				.skipSendToOriginalEndpoint()
				.process(new SimulateDatabaseError());
		}
	});

And run the same test, it fails. The exact same message is sent to
"bean:sqlBuilder?method=makeEntryGeneric", this time the message is
intercepted but the exception isn't handled. Any ideas why?

n.b. SimulateDatabaseError() is as follows:

private class SimulateDatabaseError implements Processor {
		public void process(Exchange exchange) throws Exception{
			System.out.println("Msg intercepted");
			throw new Exception(exchange.getIn().getBody().toString());
		}
	}

The OnException handler in RouteSupport is as follows:

onException(Exception.class)
			.handled(true)
			.bean(gduk.irad.DBErrorHandler.class, "errorMessage")
			.to("file:target/errors?fileName=Errors.log&fileExist=Append");

Many thanks in advance.

Matt

--
View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4520468.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 1, 2011 at 10:43 AM, Claus Ibsen <cl...@gmail.com> wrote:
> I dont have the time currently to look into this. Will likely get time
> later next week.
> The adviceWith has some limitations, and you may have hit such.
>

I have marked this conversation with a star in gmail, so I will get back to it.
Otherwise keep reminding me, later next week :)

PS: When we do some internal refactorings/optimization in the camel
routing engine. Then doing this adviceWith would become easier as the
engine supports this fully dynamically.


>
> On Fri, Jul 1, 2011 at 10:13 AM, woggle23 <ma...@yahoo.co.uk> wrote:
>> Hi Claus
>>
>> I tried moving the adviceWith() to the actual test method, still no joy I'm
>> afraid. It still works fine with a single interceptor, adding the 2nd still
>> causes problems though; the message is still intercepted but the error
>> handling doesn't work (as before).
>>
>> Did you try running this yourself? If so, what version of Camel were you
>> using? The above error description relates to version 2.7.0. Running with
>> version 2.8-SNAPSHOT yields the following stackdump:
>>
>> java.lang.NoSuchMethodError:
>> org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
>>        at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
>>        at
>> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:609)
>>        at
>> org.woggle23.DatabaseErrorTest.createCamelContext(DatabaseErrorTest.java:69)
>>        at org.apache.camel.test.CamelTestSupport.setUp(CamelTestSupport.java:115)
>>        at junit.framework.TestCase.runBare(TestCase.java:132)
>>        at org.apache.camel.test.TestSupport.runBare(TestSupport.java:65)
>>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>>        at junit.framework.TestResult.run(TestResult.java:113)
>>        at junit.framework.TestCase.run(TestCase.java:124)
>>        at junit.framework.TestSuite.runTest(TestSuite.java:232)
>>        at junit.framework.TestSuite.run(TestSuite.java:227)
>>        at
>> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
>>        at
>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>        at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>        at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>        at java.lang.reflect.Method.invoke(Method.java:597)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>>
>> Updated test case:
>> http://camel.465427.n5.nabble.com/file/n4541328/unittestissue.zip
>> unittestissue.zip
>>
>> Cheers
>>
>> Matt
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4541328.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
I dont have the time currently to look into this. Will likely get time
later next week.
The adviceWith has some limitations, and you may have hit such.


On Fri, Jul 1, 2011 at 10:13 AM, woggle23 <ma...@yahoo.co.uk> wrote:
> Hi Claus
>
> I tried moving the adviceWith() to the actual test method, still no joy I'm
> afraid. It still works fine with a single interceptor, adding the 2nd still
> causes problems though; the message is still intercepted but the error
> handling doesn't work (as before).
>
> Did you try running this yourself? If so, what version of Camel were you
> using? The above error description relates to version 2.7.0. Running with
> version 2.8-SNAPSHOT yields the following stackdump:
>
> java.lang.NoSuchMethodError:
> org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
>        at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
>        at
> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:609)
>        at
> org.woggle23.DatabaseErrorTest.createCamelContext(DatabaseErrorTest.java:69)
>        at org.apache.camel.test.CamelTestSupport.setUp(CamelTestSupport.java:115)
>        at junit.framework.TestCase.runBare(TestCase.java:132)
>        at org.apache.camel.test.TestSupport.runBare(TestSupport.java:65)
>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>        at junit.framework.TestResult.run(TestResult.java:113)
>        at junit.framework.TestCase.run(TestCase.java:124)
>        at junit.framework.TestSuite.runTest(TestSuite.java:232)
>        at junit.framework.TestSuite.run(TestSuite.java:227)
>        at
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
>        at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:597)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>
> Updated test case:
> http://camel.465427.n5.nabble.com/file/n4541328/unittestissue.zip
> unittestissue.zip
>
> Cheers
>
> Matt
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4541328.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
The JIRA is
https://issues.apache.org/jira/browse/CAMEL-4184

And I am currently testing a possible fix. Keep an eye on the JIRA
ticket for updates.
And when/if a commit with a fix is committed then please give a test
on your system with the latest source code.

On Thu, Jul 7, 2011 at 12:27 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I have reproduced the issue. The problem is when you use context
> scoped onException.
> If you define the onException on each route, then it works.
>
> I will log a JIRA and see what can be done.
>
>
>
> On Fri, Jul 1, 2011 at 10:13 AM, woggle23 <ma...@yahoo.co.uk> wrote:
>> Hi Claus
>>
>> I tried moving the adviceWith() to the actual test method, still no joy I'm
>> afraid. It still works fine with a single interceptor, adding the 2nd still
>> causes problems though; the message is still intercepted but the error
>> handling doesn't work (as before).
>>
>> Did you try running this yourself? If so, what version of Camel were you
>> using? The above error description relates to version 2.7.0. Running with
>> version 2.8-SNAPSHOT yields the following stackdump:
>>
>> java.lang.NoSuchMethodError:
>> org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
>>        at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
>>        at
>> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:609)
>>        at
>> org.woggle23.DatabaseErrorTest.createCamelContext(DatabaseErrorTest.java:69)
>>        at org.apache.camel.test.CamelTestSupport.setUp(CamelTestSupport.java:115)
>>        at junit.framework.TestCase.runBare(TestCase.java:132)
>>        at org.apache.camel.test.TestSupport.runBare(TestSupport.java:65)
>>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>>        at junit.framework.TestResult.run(TestResult.java:113)
>>        at junit.framework.TestCase.run(TestCase.java:124)
>>        at junit.framework.TestSuite.runTest(TestSuite.java:232)
>>        at junit.framework.TestSuite.run(TestSuite.java:227)
>>        at
>> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
>>        at
>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>        at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>        at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>        at java.lang.reflect.Method.invoke(Method.java:597)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>>
>> Updated test case:
>> http://camel.465427.n5.nabble.com/file/n4541328/unittestissue.zip
>> unittestissue.zip
>>
>> Cheers
>>
>> Matt
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4541328.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have reproduced the issue. The problem is when you use context
scoped onException.
If you define the onException on each route, then it works.

I will log a JIRA and see what can be done.



On Fri, Jul 1, 2011 at 10:13 AM, woggle23 <ma...@yahoo.co.uk> wrote:
> Hi Claus
>
> I tried moving the adviceWith() to the actual test method, still no joy I'm
> afraid. It still works fine with a single interceptor, adding the 2nd still
> causes problems though; the message is still intercepted but the error
> handling doesn't work (as before).
>
> Did you try running this yourself? If so, what version of Camel were you
> using? The above error description relates to version 2.7.0. Running with
> version 2.8-SNAPSHOT yields the following stackdump:
>
> java.lang.NoSuchMethodError:
> org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
>        at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
>        at
> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:609)
>        at
> org.woggle23.DatabaseErrorTest.createCamelContext(DatabaseErrorTest.java:69)
>        at org.apache.camel.test.CamelTestSupport.setUp(CamelTestSupport.java:115)
>        at junit.framework.TestCase.runBare(TestCase.java:132)
>        at org.apache.camel.test.TestSupport.runBare(TestSupport.java:65)
>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>        at junit.framework.TestResult.run(TestResult.java:113)
>        at junit.framework.TestCase.run(TestCase.java:124)
>        at junit.framework.TestSuite.runTest(TestSuite.java:232)
>        at junit.framework.TestSuite.run(TestSuite.java:227)
>        at
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
>        at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:597)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>
> Updated test case:
> http://camel.465427.n5.nabble.com/file/n4541328/unittestissue.zip
> unittestissue.zip
>
> Cheers
>
> Matt
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4541328.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by woggle23 <ma...@yahoo.co.uk>.
Hi Claus

I tried moving the adviceWith() to the actual test method, still no joy I'm
afraid. It still works fine with a single interceptor, adding the 2nd still
causes problems though; the message is still intercepted but the error
handling doesn't work (as before).

Did you try running this yourself? If so, what version of Camel were you
using? The above error description relates to version 2.7.0. Running with
version 2.8-SNAPSHOT yields the following stackdump:

java.lang.NoSuchMethodError:
org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
	at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
	at
org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:609)
	at
org.woggle23.DatabaseErrorTest.createCamelContext(DatabaseErrorTest.java:69)
	at org.apache.camel.test.CamelTestSupport.setUp(CamelTestSupport.java:115)
	at junit.framework.TestCase.runBare(TestCase.java:132)
	at org.apache.camel.test.TestSupport.runBare(TestSupport.java:65)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
	at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

Updated test case:
http://camel.465427.n5.nabble.com/file/n4541328/unittestissue.zip
unittestissue.zip 

Cheers

Matt

--
View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4541328.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
You should do the advice stuff in the test method, not in the createCamelContext

On Mon, Jun 27, 2011 at 6:30 PM, woggle23 <ma...@yahoo.co.uk> wrote:
> I tried running it against 2.8-SNAPSHOT, the results were worse - the test
> didn't even pass with a single intercept.
>
> The attached zip is the test I was trying to perform (DatabaseErrorTest), a
> single intercept is currently in use (intercepting the "MsgInterface"
> route), adding the "DBcontentsInterface" intercept causes the test to fail
> when running against 2.7.
>
> The test sends an xml message to an http endpoint. The route converts it to
> a string then sends it to a bean endpoint - which is intercepted. The
> SimulateDatabaseError() processor, which the interceptor diverts the message
> to, throws an exception, which should be handled by the onException() dsl in
> RouteSupport.java.
>
> http://camel.465427.n5.nabble.com/file/n4528996/unittestissue.zip
> unittestissue.zip
>
> Cheers
>
> Matt
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4528996.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by woggle23 <ma...@yahoo.co.uk>.
I tried running it against 2.8-SNAPSHOT, the results were worse - the test
didn't even pass with a single intercept.

The attached zip is the test I was trying to perform (DatabaseErrorTest), a
single intercept is currently in use (intercepting the "MsgInterface"
route), adding the "DBcontentsInterface" intercept causes the test to fail
when running against 2.7.

The test sends an xml message to an http endpoint. The route converts it to
a string then sends it to a bean endpoint - which is intercepted. The
SimulateDatabaseError() processor, which the interceptor diverts the message
to, throws an exception, which should be handled by the onException() dsl in
RouteSupport.java.

http://camel.465427.n5.nabble.com/file/n4528996/unittestissue.zip
unittestissue.zip 

Cheers

Matt

--
View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4528996.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
Can you try with 2.8-SNAPSHOT as we fixed some issues with adviceWith
and error handlers and whatnot.

If its still a problem then attach some junit test with all source so
its easier for us to look into.

On Mon, Jun 27, 2011 at 11:57 AM, woggle23 <ma...@yahoo.co.uk> wrote:
>>> What version of Camel are you using?
>
> Version 2.7
>
> Cheers
>
> Matt
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4527689.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: intercept using adviceWith()

Posted by woggle23 <ma...@yahoo.co.uk>.
>> What version of Camel are you using? 

Version 2.7

Cheers

Matt

--
View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4527689.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: intercept using adviceWith()

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

What version of Camel are you using?


On Fri, Jun 24, 2011 at 11:36 AM, woggle23 <ma...@yahoo.co.uk> wrote:
> Morning All
>
> I'm attempting to simulate errors in order to test my error handling. In my
> test class I create the following interception in the createCamelContext
> method:
>
> context.addRoutes(new RouteSupport());
>
> RouteDefinition route = context.getRouteDefinition("Route1");
>                route.adviceWith(context, new RouteBuilder(){
>                @Override
>                public void configure() throws Exception{
>                interceptSendToEndpoint("bean:sqlBuilder?method=makeEntryGeneric")
> .skipSendToOriginalEndpoint()
>                        .process(new SimulateDatabaseError());
>                }
>        });
>
> Running a test which causes a message to route to
> "bean:sqlBuilder?method=makeEntryGeneric" performs correctly; i.e. the
> message is intercepted, an exception is thrown and handled as expected (the
> test passes).
>
> If I add a 2nd intercept to the above:
>
> route = context.getRouteDefinition("DBContentsInterface");
>                route.adviceWith(context, new RouteBuilder(){
>                @Override
>                public void configure() throws Exception{
>                        interceptSendToEndpoint("bean:sqlBuilder?method=getUpdatedTrackInfo")
>                                .skipSendToOriginalEndpoint()
>                                .process(new SimulateDatabaseError());
>                }
>        });
>
> And run the same test, it fails. The exact same message is sent to
> "bean:sqlBuilder?method=makeEntryGeneric", this time the message is
> intercepted but the exception isn't handled. Any ideas why?
>
> n.b. SimulateDatabaseError() is as follows:
>
> private class SimulateDatabaseError implements Processor {
>                public void process(Exchange exchange) throws Exception{
>                        System.out.println("Msg intercepted");
>                        throw new Exception(exchange.getIn().getBody().toString());
>                }
>        }
>
> The OnException handler in RouteSupport is as follows:
>
> onException(Exception.class)
>                        .handled(true)
>                        .bean(gduk.irad.DBErrorHandler.class, "errorMessage")
>                        .to("file:target/errors?fileName=Errors.log&fileExist=Append");
>
> Many thanks in advance.
>
> Matt
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/intercept-using-adviceWith-tp4520468p4520468.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/