You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jothi <co...@gmail.com> on 2013/05/15 18:34:19 UTC

Exception Handling Scenario - Suggestions Needed

Camel Users:

I have the following route:

from("activemq:{{in.queue}}")
    .process(new MyInputProcessor())
    .beanRef("myBeanProcessor")
    .process(new MyOutputProcessor()")
    .to("activemq:{{out.queue}}");
  
In my beanRef, I change the body of the Exchange to a different type after
processing the incoming message from the Exchange (from the activemq queue).
In my route I have the following defined for the exception handling:

        onException(Exception.class).maximumRedeliveries(0)
                .useOriginalMessage()
                .process(exceptionHandler)
                .convertBodyTo(String.class)
                .wireTap("activemq:alert");

My requirement is that if in my myBeanProcessor, any Exception occurs, I
need to handle it differently in the sense that I cannot use the
.useOriginalMessage(), but rather, I need to get the actual body in the
exchange after the MyInputProcessor() has run (which I already know), and
then do some processing, and then I need to send it to the exceptionHandler.
But this time when I send it to the exceptionHandler, I need to get the
original message that I got from the "activemq:{{in.queue}}".

Here is what I have so far:

		onException(Exception.class).maximumRedeliveries(0).useOriginalMessage()
// When I use this, simple("${body} is com.test.generated.MyType") is
evaluated to false
            .choice()
            .when(simple("${body} is com.test.generated.MyType"))
                .log(LoggingLevel.INFO, getClass().getName(),
"ExceptionHandling: Routing to direct:sendErrorResponse
route").to("direct:sendErrorResponse")
            .otherwise()
                .log(LoggingLevel.INFO, getClass().getName(),
"ExceptionHandling: Routing to direct:handleExceptionHandler") route")
				.to("direct:handleExceptionHandler").routeId("exceptionHandler");

        // If an exception occurs during the creation of TradeBuilder xml
        from("direct:sendErrorResponse")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    MyType myType = exchange.getIn().getBody(MyType.class);
                    // Get and set values into another object
					MyResponseType resp = new MyResponseType();
					resp.setField1(myType.getField1());
					resp.setField2(...);
					resp.setField3(...);
                    exchange.getIn().setBody(resp);
                }
            })
            .marshal(jaxb).
            .to("activemq:{{out.queue}}")
            // Send it also to the exceptionHandler appender
            .to("direct:handleExceptionHandler").routeId("responseHandler");

        from("direct:handleExceptionHandler") // I always want to use the
original message that I get from the in.queue in my route above
            .process(new ExceptionHandler())
            .convertBodyTo(String.class)
            .wireTap("activemq:alert");

Any suggestions?



--
View this message in context: http://camel.465427.n5.nabble.com/Exception-Handling-Scenario-Suggestions-Needed-tp5732623.html
Sent from the Camel - Users mailing list archive at Nabble.com.