camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <cmoulli...@gmail.com>
Subject Re: Try/catch with split
Date Fri, 14 Aug 2009 08:48:22 GMT
Many thank.

I will test now the Spring DSL version as this is with Spring DSL that I
have the issue in my camel route project.

Regards,

Charles


On Fri, Aug 14, 2009 at 10:44 AM, Claus Ibsen <claus.ibsen@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<cmoulliard@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", "Claus@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: Claus@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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message