I try to translate the syntax of Java DSL into Spring DSL. <route> <from uri="direct:startWithError"/> <doTry> <split> <tokenize token="@"/> <bean ref="error"/> <to uri="mock:result"/> </split> <doCatch> <exception>java.lang.Exception</exception> <handled> <constant>false</constant> </handled> <to uri="log:org.apache.camel.processor?level=INFO&multiline=true&showException=true&showCaughtException=true&showStackTrace=false"/> <to uri="mock:error"/> </doCatch> </doTry> </route>
The following syntax which is accepted is not the correct one because the mock:error endpoint does not receive anything when excecuting the test case !! Regards, Charles Moulliard Senior Enterprise Architect Apache Camel Committer ***************************** blog : http://cmoulliard.blogspot.com On Fri, Aug 14, 2009 at 3:12 PM, Charles Moulliard <cmoulli...@gmail.com>wrote: > Thx. > > With the following syntax, it works : > > public void testSplitWithError() throws Exception { > MockEndpoint error = getMockEndpoint("mock:error"); > error.expectedBodiesReceived("James"); > error.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull(); > > MockEndpoint result = getMockEndpoint("mock:result"); > result.expectedBodiesReceived("Hello Claus", "Hello Willem"); > > try { > template.sendBody("direct:startWithError", "cl...@james > @Willem"); > fail("Exception has been throwed"); > } catch (CamelExecutionException ex) { > // Nothing to do > } > > assertMockEndpointsSatisfied(); > } > > Regards, > > Charles Moulliard > Senior Enterprise Architect > Apache Camel Committer > > ***************************** > blog : http://cmoulliard.blogspot.com > > > On Fri, Aug 14, 2009 at 2:52 PM, Claus Ibsen <claus.ib...@gmail.com>wrote: > >> You need try .. catch around the template when you send a message as >> you do NOT handle the exception and thus the client get this exception >> back. >> >> >> On Fri, Aug 14, 2009 at 2:43 PM, Charles Moulliard<cmoulli...@gmail.com> >> wrote: >> > I have adapted the test case as you propose but it fails. >> > >> > org.apache.camel.CamelExecutionException: Exception occured during >> execution >> > on the exchange: Exchange[Message: Hello Willem] >> > at >> > >> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1027) >> > at >> > >> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:479) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:427) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:112) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:117) >> > at >> > >> org.apache.camel.processor.SplitterTryCatchErrorTest.testSplitWithError(SplitterTryCatchErrorTest.java:38) >> > 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 junit.framework.TestCase.runTest(TestCase.java:164) >> > at junit.framework.TestCase.runBare(TestCase.java:130) >> > at junit.framework.TestResult$1.protect(TestResult.java:106) >> > at junit.framework.TestResult.runProtected(TestResult.java:124) >> > at junit.framework.TestResult.run(TestResult.java:109) >> > at junit.framework.TestCase.run(TestCase.java:120) >> > at junit.framework.TestSuite.runTest(TestSuite.java:230) >> > at junit.framework.TestSuite.run(TestSuite.java:225) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) >> > at >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) >> > Caused by: java.lang.Exception: This is a dummy error James! >> > at >> > >> org.apache.camel.processor.SplitterTryCatchErrorTest$GenerateError.dummyException(SplitterTryCatchErrorTest.java:73) >> > 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.camel.component.bean.MethodInfo.invoke(MethodInfo.java:193) >> > at >> > >> org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:115) >> > at >> > >> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:122) >> > at >> > >> org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:95) >> > at >> > >> org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:65) >> > at >> > >> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:81) >> > at >> > >> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:78) >> > at >> > org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:141) >> > at >> > org.apache.camel.processor.SendProcessor.process(SendProcessor.java:78) >> > at >> > >> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:148) >> > at org.apache.camel.processor.Pipeline.process(Pipeline.java:74) >> > at >> org.apache.camel.processor.TryProcessor.process(TryProcessor.java:63) >> > at >> > >> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:61) >> > at >> > >> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:61) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.processExchange(RedeliveryErrorHandler.java:186) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:155) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:88) >> > at >> > >> org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:49) >> > at >> > >> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:148) >> > at >> > >> org.apache.camel.processor.MulticastProcessor.doProcessSequntiel(MulticastProcessor.java:189) >> > at >> > >> org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:126) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.processExchange(RedeliveryErrorHandler.java:186) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:155) >> > at >> > >> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:88) >> > at >> > >> org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:49) >> > at >> > >> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:148) >> > at >> > >> org.apache.camel.processor.UnitOfWorkProcessor.processNext(UnitOfWorkProcessor.java:54) >> > at >> > >> org.apache.camel.processor.DelegateProcessor.process(DelegateProcessor.java:48) >> > at >> > >> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:45) >> > at >> > >> org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:170) >> > at >> > >> org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:155) >> > at >> > org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:141) >> > at >> > org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:155) >> > at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:93) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:97) >> > at >> > >> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:110) >> > ... 20 more >> > >> > >> > >> > CODE ******************************************************** >> > >> > import org.apache.camel.ContextTestSupport; >> > import org.apache.camel.Exchange; >> > import org.apache.camel.builder.RouteBuilder; >> > import org.apache.camel.component.mock.MockEndpoint; >> > import org.apache.camel.impl.JndiRegistry; >> > >> > /** >> > * @version $Revision: 736555 $ >> > */ >> > public class SplitterTryCatchErrorTest extends ContextTestSupport { >> > >> > public void testSplitWithError() throws Exception { >> > MockEndpoint error = getMockEndpoint("mock:error"); >> > error.expectedBodiesReceived("James"); >> > >> error.message(0).property(Exchange.EXCEPTION_CAUGHT).contains("This >> > is a dummy error James!"); >> > >> > MockEndpoint result = getMockEndpoint("mock:result"); >> > result.expectedBodiesReceived("Hello Claus", "Hello Willem"); >> > >> > template.sendBody("direct:startWithError", "cl...@james >> @Willem"); >> > >> > assertMockEndpointsSatisfied(); >> > } >> > >> > protected JndiRegistry createRegistry() throws Exception { >> > JndiRegistry jndi = super.createRegistry(); >> > jndi.bind("error", new GenerateError()); >> > return jndi; >> > } >> > >> > protected RouteBuilder createRouteBuilder() { >> > return new RouteBuilder() { >> > public void configure() { >> > from("direct:startWithError") >> > .split(body().tokenize("@")) >> > .doTry() >> > // GENERATE A DUMMY ERROR >> > .to("bean:error") >> > .to("mock:result") >> > .doCatch(java.lang.Exception.class).handled(false) >> > >> > >> .to("log:org.apache.camel.processor?level=INFO&multiline=true&showException=true&showCaughtException=true&showStackTrace=false") >> > .to("mock:error") >> > .end(); >> > } >> > }; >> > } >> > >> > public static final class GenerateError { >> > public GenerateError() { >> > // Helper Class >> > } >> > >> > public String dummyException(String payload) throws Exception { >> > if (payload.equals("James")) { >> > throw new Exception("This is a dummy error James!"); >> > } >> > return "Hello " + payload; >> > } >> > >> > } >> > >> > >> > } >> > >> > ******************************************** >> > >> > Here is the trace of the log >> > >> > 2009-08-14 14:34:57,726 [main ] INFO >> > DefaultCamelContext - JMX enabled. Using >> > InstrumentationLifecycleStrategy. >> > 2009-08-14 14:34:57,882 [main ] DEBUG >> > SplitterTryCatchErrorTest - Using created route builder: Routes: [] >> > 2009-08-14 14:34:57,882 [main ] DEBUG >> > DefaultCamelContext - Adding routes from builder: Routes: [] >> > 2009-08-14 14:34:58,132 [main ] INFO >> > DefaultCamelContext - Apache Camel (CamelContext:camel-1) is >> > starting >> > 2009-08-14 14:34:58,132 [main ] DEBUG >> > DefaultProducerServicePool - Starting service pool: >> > org.apache.camel.impl.defaultproducerservicep...@b02efa >> > 2009-08-14 14:34:58,601 [main ] DEBUG >> > DefaultComponentResolver - Found component: direct via type: >> > org.apache.camel.component.direct.DirectComponent via: >> > META-INF/services/org/apache/camel/component/direct >> > 2009-08-14 14:34:58,601 [main ] DEBUG >> > DefaultComponent - Creating endpoint >> > uri=[direct://startWithError], path=[startWithError], parameters=[{}] >> > 2009-08-14 14:34:58,616 [main ] DEBUG >> > DefaultCamelContext - direct://startWithError converted to >> > endpoint: Endpoint[direct://startWithError] by component: >> > org.apache.camel.component.direct.directcompon...@1e0f2f6 >> > 2009-08-14 14:34:58,695 [main ] DEBUG >> > DefaultComponentResolver - Found component: bean via type: >> > org.apache.camel.component.bean.BeanComponent via: >> > META-INF/services/org/apache/camel/component/bean >> > 2009-08-14 14:34:58,710 [main ] DEBUG >> > DefaultComponent - Creating endpoint uri=[bean://error], >> > path=[error], parameters=[{}] >> > 2009-08-14 14:34:58,726 [main ] DEBUG >> > DefaultCamelContext - bean://error converted to endpoint: >> > Endpoint[bean://error] by component: >> > org.apache.camel.component.bean.beancompon...@1c0f2e5 >> > 2009-08-14 14:34:58,773 [main ] DEBUG >> > DefaultComponentResolver - Found component: mock via type: >> > org.apache.camel.component.mock.MockComponent via: >> > META-INF/services/org/apache/camel/component/mock >> > 2009-08-14 14:34:58,773 [main ] DEBUG >> > DefaultComponent - Creating endpoint uri=[mock://result], >> > path=[result], parameters=[{}] >> > 2009-08-14 14:34:58,788 [main ] DEBUG >> > DefaultCamelContext - mock://result converted to endpoint: >> > Endpoint[mock://result] by component: >> > org.apache.camel.component.mock.mockcompon...@1977b9b >> > 2009-08-14 14:34:58,835 [main ] DEBUG >> > DefaultComponentResolver - Found component: log via type: >> > org.apache.camel.component.log.LogComponent via: >> > META-INF/services/org/apache/camel/component/log >> > 2009-08-14 14:34:58,851 [main ] DEBUG >> > DefaultComponent - Creating endpoint >> > >> uri=[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false], >> > path=[org.apache.camel.processor], parameters=[{level=INFO, >> multiline=true, >> > showCaughtException=true, showException=true, showStackTrace=false}] >> > 2009-08-14 14:34:58,882 [main ] DEBUG >> > DefaultCamelContext - >> > >> log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false >> > converted to endpoint: >> > >> Endpoint[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false] >> > by component: org.apache.camel.component.log.logcompon...@1a7ddcf >> > 2009-08-14 14:34:58,882 [main ] DEBUG >> > DefaultComponent - Creating endpoint uri=[mock://error], >> > path=[error], parameters=[{}] >> > 2009-08-14 14:34:58,882 [main ] DEBUG >> > DefaultCamelContext - mock://error converted to endpoint: >> > Endpoint[mock://error] by component: >> > org.apache.camel.component.mock.mockcompon...@1977b9b >> > 2009-08-14 14:34:58,976 [main ] DEBUG >> > DefaultCamelContext - Starting routes >> > 2009-08-14 14:34:59,116 [main ] DEBUG >> > DirectConsumer - Starting consumer: >> > Consumer[direct://startWithError] >> > 2009-08-14 14:34:59,116 [main ] DEBUG >> > DefaultCamelContext - Route 0: >> > EventDrivenConsumerRoute[Endpoint[direct://startWithError] -> >> > UnitOfWork(Channel[Splitter[on: tokenize(body, @) to: Channel[Try >> > {Pipeline[Channel[sendTo(Endpoint[bean://error])], >> > Channel[sendTo(Endpoint[mock://result])]]} [Catch[[class >> > java.lang.Exception] -> >> > >> Pipeline[Channel[sendTo(Endpoint[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false])], >> > Channel[sendTo(Endpoint[mock://error])]]]]] aggregate: >> > useLatestAggregationStrategy]])] >> > 2009-08-14 14:34:59,116 [main ] DEBUG >> > DefaultCamelContext - Started routes >> > 2009-08-14 14:34:59,116 [main ] INFO >> > DefaultCamelContext - Apache Camel (CamelContext:camel-1) >> > started >> > 2009-08-14 14:34:59,163 [main ] DEBUG >> > DirectProducer - Starting producer: >> > Producer[direct://startWithError] >> > 2009-08-14 14:34:59,179 [main ] DEBUG >> > ProducerCache - Adding to producer cache with key: >> > Endpoint[direct://startWithError] for producer: >> > Producer[direct://startWithError] >> > 2009-08-14 14:34:59,304 [main ] DEBUG >> > ProducerCache - >>>> Endpoint[direct://startWithError] >> > Exchange[Message: cl...@james@Willem] >> > 2009-08-14 14:34:59,413 [main ] DEBUG >> > ProcessorEndpoint$1 - Starting producer: >> Producer[bean://error] >> > 2009-08-14 14:34:59,413 [main ] DEBUG >> > ProducerCache - Adding to producer cache with key: >> > Endpoint[bean://error] for producer: Producer[bean://error] >> > 2009-08-14 14:35:00,726 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.component.file.GenericFileConverter >> > 2009-08-14 14:35:00,757 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.InstanceMethodWithExchangeTestConverter >> > 2009-08-14 14:35:00,757 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.StaticMethodWithExchangeTestConverter >> > 2009-08-14 14:35:00,757 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.CamelConverter >> > 2009-08-14 14:35:00,757 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.CollectionConverter >> > 2009-08-14 14:35:00,757 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.IOConverter >> > 2009-08-14 14:35:00,773 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.jaxp.DomConverter >> > 2009-08-14 14:35:00,773 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.jaxp.StaxConverter >> > 2009-08-14 14:35:00,788 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.jaxp.StreamSourceConverter >> > 2009-08-14 14:35:00,788 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.jaxp.XmlConverter >> > 2009-08-14 14:35:00,788 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.NIOConverter >> > 2009-08-14 14:35:00,788 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.ObjectConverter >> > 2009-08-14 14:35:00,804 [main ] DEBUG >> > AnnotationTypeConverterLoader - Loading converter class: >> > org.apache.camel.converter.stream.StreamCacheConverter >> > 2009-08-14 14:35:00,804 [main ] DEBUG >> > BeanProcessor - Setting bean invocation result on the >> IN >> > message: Hello Claus >> > 2009-08-14 14:35:00,804 [main ] DEBUG >> > BeanProcessor - Setting bean invocation result on the >> IN >> > message: Hello Claus >> > 2009-08-14 14:35:00,804 [main ] DEBUG >> > MockEndpoint$1 - Starting producer: >> Producer[mock://result] >> > 2009-08-14 14:35:00,804 [main ] DEBUG >> > ProducerCache - Adding to producer cache with key: >> > Endpoint[mock://result] for producer: Producer[mock://result] >> > 2009-08-14 14:35:00,820 [main ] DEBUG >> > MockEndpoint - mock://result >>>> 1 : >> Exchange[Message: >> > Hello Claus] with body: Hello Claus >> > 2009-08-14 14:35:00,820 [main ] DEBUG >> > Pipeline - Message exchange has failed so breaking >> out >> > of pipeline: Exchange[Message: James] Exception: java.lang.Exception: >> This >> > is a dummy error James! >> > 2009-08-14 14:35:00,820 [main ] DEBUG >> > ProcessorEndpoint$1 - Starting producer: >> > >> Producer[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false] >> > 2009-08-14 14:35:00,820 [main ] DEBUG >> > ProducerCache - Adding to producer cache with key: >> > >> Endpoint[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false] >> > for producer: >> > >> Producer[log://org.apache.camel.processor?level=INFO&multiline=true&showCaughtException=true&showException=true&showStackTrace=false] >> > 2009-08-14 14:35:00,835 [main ] INFO >> > processor - Exchange[ >> > , BodyType:String >> > , Body:James >> > , CaughtExceptionType:java.lang.Exception, CaughtExceptionMessage:This >> is a >> > dummy error James!] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > MockEndpoint$1 - Starting producer: >> Producer[mock://error] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > ProducerCache - Adding to producer cache with key: >> > Endpoint[mock://error] for producer: Producer[mock://error] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > MockEndpoint - mock://error >>>> 1 : Exchange[Message: >> > James] with body: James >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > TryProcessor - The exception is handled: false for the >> > exception: java.lang.Exception caused by: This is a dummy error James! >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DefaultErrorHandler - Failed delivery for exchangeId: >> > ID-dell-charles-2915-1250253299195-0-2. On delivery attempt: 0 caught: >> > java.lang.Exception: This is a dummy error James! >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DefaultErrorHandler - This exchange is not handled so its >> marked >> > as failed: Exchange[Message: James] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > BeanProcessor - Setting bean invocation result on the >> IN >> > message: Hello Willem >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > BeanProcessor - Setting bean invocation result on the >> IN >> > message: Hello Willem >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > MockEndpoint - mock://result >>>> 2 : >> Exchange[Message: >> > Hello Willem] with body: Hello Willem >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > MulticastProcessor - Done sequientel processing 3 exchanges >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DefaultErrorHandler - Failed delivery for exchangeId: >> > ID-dell-charles-2915-1250253299195-0-4. On delivery attempt: 0 caught: >> > java.lang.Exception: This is a dummy error James! >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DefaultErrorHandler - This exchange is not handled so its >> marked >> > as failed: Exchange[Message: Hello Willem] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > SplitterTryCatchErrorTest - tearDown test: testSplitWithError >> > 2009-08-14 14:35:00,835 [main ] INFO >> > DefaultCamelContext - Apache Camel (CamelContext:camel-1) is >> > stopping >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DirectConsumer - Stopping consumer: >> > Consumer[direct://startWithError] >> > 2009-08-14 14:35:00,835 [main ] DEBUG >> > DefaultProducerServicePool - Stopping service pool: >> > org.apache.camel.impl.defaultproducerservicep...@b02efa >> > 2009-08-14 14:35:00,835 [main ] INFO >> > DefaultCamelContext - Apache Camel (CamelContext:camel-1) >> > stopped >> > >> > Regards, >> > >> > Charles Moulliard >> > Senior Enterprise Architect >> > Apache Camel Committer >> > >> > ***************************** >> > blog : http://cmoulliard.blogspot.com >> > >> > >> > On Fri, Aug 14, 2009 at 10:50 AM, Claus Ibsen <claus.ib...@gmail.com> >> wrote: >> > >> >> Hi >> >> >> >> But Camel is smart and flexible so it allows you to lower the handled >> >> flag on doCatch (noticed handled(false)) so you can do like this, in >> >> which the client will get the exception back in his face. And the >> >> mock:error can see the caused exception from a property on the >> >> exchange >> >> >> >> MockEndpoint error = getMockEndpoint("mock:error"); >> >> error.expectedBodiesReceived("James"); >> >> >> error.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull(); >> >> >> >> >> >> from("direct:start") >> >> .split(body().tokenize("@")) >> >> .doTry() >> >> .to("bean:error") >> >> .to("mock:result") >> >> .doCatch(Exception.class).handled(false) >> >> .to("mock:error") >> >> .end(); >> >> >> >> >> >> On Fri, Aug 14, 2009 at 10:44 AM, Claus Ibsen<claus.ib...@gmail.com> >> >> wrote: >> >> > Hi >> >> > >> >> > Works fine I will commit an unit test later when Hadrian is done with >> >> > the build of Camel 2.0 release. >> >> > >> >> > 2 messages goes to mock:result >> >> > 1 message go to mock:error >> >> > >> >> > All as expected. >> >> > >> >> > Since you use doTry .. doCatch the client will not receive any >> >> > exception as he will not do that either when you do >> >> > >> >> > try { >> >> > >> >> > } catch (Exception e) { >> >> > .. do something >> >> > } >> >> > >> >> > Since you do NOT rethrow the exception in the catch block. Catching >> an >> >> > exception is like handling it = NO MORE AN EXCEPTION >> >> > >> >> > >> >> > >> >> > >> >> > On Wed, Aug 12, 2009 at 2:53 PM, Charles Moulliard< >> cmoulli...@gmail.com> >> >> wrote: >> >> >> Hi, >> >> >> >> >> >> I'm back again with try/catch and split. I have created the >> following >> >> unit >> >> >> test who seems to work but I don't understand why the try/catch >> block of >> >> the >> >> >> test does not receive the error ? >> >> >> >> >> >> Code >> >> >> >> >> >> package org.apache.camel.processor; >> >> >> >> >> >> import org.apache.camel.ContextTestSupport; >> >> >> // import org.apache.camel.RuntimeCamelException; >> >> >> import org.apache.camel.builder.RouteBuilder; >> >> >> import org.apache.camel.component.mock.MockEndpoint; >> >> >> import org.apache.camel.impl.JndiRegistry; >> >> >> >> >> >> public class SplitterTryCatchErrorTest extends ContextTestSupport { >> >> >> >> >> >> public void testSplitWithError() throws Exception { >> >> >> MockEndpoint resultEndpoint = getMockEndpoint("mock:error"); >> >> >> resultEndpoint.expectedBodiesReceived("James"); >> >> >> >> >> >> try { >> >> >> template.sendBody("direct:startWithError", "cl...@james >> >> >> @Willem"); >> >> >> //fail("Should have thrown an exception"); >> >> >> } catch (Exception e) { >> >> >> assertTrue(e.getCause().getMessage().startsWith("This is >> a >> >> dummy >> >> >> error James!")); >> >> >> } >> >> >> >> >> >> assertMockEndpointsSatisfied(); >> >> >> } >> >> >> >> >> >> >> >> >> protected JndiRegistry createRegistry() throws Exception { >> >> >> JndiRegistry jndi = super.createRegistry(); >> >> >> jndi.bind("error", new GenerateError()); >> >> >> return jndi; >> >> >> } >> >> >> >> >> >> protected RouteBuilder createRouteBuilder() { >> >> >> return new RouteBuilder() { >> >> >> public void configure() { >> >> >> from("direct:startWithError") >> >> >> .split(body().tokenize("@")) >> >> >> .doTry() >> >> >> // GENERATE A DUMMY ERROR >> >> >> .to("bean:error") >> >> >> .to("mock:result") >> >> >> .doCatch(java.lang.Exception.class) >> >> >> .to("mock:error") >> >> >> .end(); >> >> >> >> >> >> } >> >> >> >> >> >> public static final class GenerateError { >> >> >> public GenerateError() { >> >> >> // Helper Class >> >> >> } >> >> >> >> >> >> public String dummyException(String payload) throws Exception >> { >> >> >> if (payload.equals("James")) { >> >> >> throw new Exception("This is a dummy error James!"); >> >> >> } >> >> >> return "Hello " + payload; >> >> >> } >> >> >> >> >> >> } >> >> >> >> >> >> >> >> >> } >> >> >> >> >> >> What I observe in the log is that the split of the body is done and >> each >> >> >> message is processed individually : one for Claus, one for Willem. >> For >> >> >> James, a dummy exception is throwed. >> >> >> >> >> >> 2009-08-12 14:41:06,701 [main ] DEBUG >> >> >> ProducerCache - >>>> >> Endpoint[direct://startWithError] >> >> >> Exchange[Message: cl...@james@Willem] >> >> >> 2009-08-12 14:41:06,811 [main ] DEBUG >> >> >> ProcessorEndpoint$1 - Starting producer: >> >> Producer[bean://error] >> >> >> 2009-08-12 14:41:06,811 [main ] DEBUG >> >> >> ProducerCache - Adding to producer cache with key: >> >> >> Endpoint[bean://error] for producer: Producer[bean://error] >> >> >> 2009-08-12 14:41:09,233 [main ] DEBUG >> >> >> BeanProcessor - Setting bean invocation result on >> the >> >> IN >> >> >> message: Hello Claus >> >> >> 2009-08-12 14:41:09,233 [main ] DEBUG >> >> >> BeanProcessor - Setting bean invocation result on >> the >> >> IN >> >> >> message: Hello Claus >> >> >> 2009-08-12 14:41:09,248 [main ] DEBUG >> >> >> MockEndpoint$1 - Starting producer: >> >> Producer[mock://result] >> >> >> 2009-08-12 14:41:09,248 [main ] DEBUG >> >> >> ProducerCache - Adding to producer cache with key: >> >> >> Endpoint[mock://result] for producer: Producer[mock://result] >> >> >> 2009-08-12 14:41:09,248 [main ] DEBUG >> >> >> MockEndpoint - mock://result >>>> 1 : >> >> Exchange[Message: >> >> >> Hello Claus] with body: Hello Claus >> >> >> 2009-08-12 14:41:09,248 [main ] DEBUG >> >> >> Pipeline - Message exchange has failed so >> breaking >> >> out >> >> >> of pipeline: Exchange[Message: James] Exception: >> java.lang.Exception: >> >> This >> >> >> is a dummy error James! >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> MockEndpoint$1 - Starting producer: >> >> Producer[mock://error] >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> ProducerCache - Adding to producer cache with key: >> >> >> Endpoint[mock://error] for producer: Producer[mock://error] >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> MockEndpoint - mock://error >>>> 1 : >> Exchange[Message: >> >> >> James] with body: James >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> TryProcessor - The exception is handled: true for >> the >> >> >> exception: java.lang.Exception caused by: This is a dummy error >> James! >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> BeanProcessor - Setting bean invocation result on >> the >> >> IN >> >> >> message: Hello Willem >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> BeanProcessor - Setting bean invocation result on >> the >> >> IN >> >> >> message: Hello Willem >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> MockEndpoint - mock://result >>>> 2 : >> >> Exchange[Message: >> >> >> Hello Willem] with body: Hello Willem >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> MulticastProcessor - Done sequientel processing 3 >> exchanges >> >> >> 2009-08-12 14:41:09,264 [main ] INFO >> >> >> MockEndpoint - Asserting: Endpoint[mock://result] >> is >> >> >> satisfied >> >> >> 2009-08-12 14:41:09,264 [main ] INFO >> >> >> MockEndpoint - Asserting: Endpoint[mock://error] >> is >> >> >> satisfied >> >> >> 2009-08-12 14:41:09,264 [main ] DEBUG >> >> >> SplitterTryCatchErrorTest - tearDown test: testSplitWithError >> >> >> >> >> >> The test succeeds but the exception is not catched in the try/catch >> >> block of >> >> >> testSplitWithError. What is wrong ? >> >> >> >> >> >> Regards, >> >> >> >> >> >> Charles >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > Claus Ibsen >> >> > Apache Camel Committer >> >> > >> >> > Open Source Integration: http://fusesource.com >> >> > Blog: http://davsclaus.blogspot.com/ >> >> > Twitter: http://twitter.com/davsclaus >> >> > >> >> >> >> >> >> >> >> -- >> >> Claus Ibsen >> >> Apache Camel Committer >> >> >> >> Open Source Integration: http://fusesource.com >> >> Blog: http://davsclaus.blogspot.com/ >> >> Twitter: http://twitter.com/davsclaus >> >> >> > >> >> >> >> -- >> Claus Ibsen >> Apache Camel Committer >> >> Open Source Integration: http://fusesource.com >> Blog: http://davsclaus.blogspot.com/ >> Twitter: http://twitter.com/davsclaus >> > >