I have a simple route with a producer in the middle which throws an exception
(java.lang.IllegalArgumentException) as follows:

from("direct:start").process(exceptionThrower).to("mock:result");

As expected, the default error handler (Dead Letter Channel) is triggered
which attempts to redeliver the message a few times. Since all the
redelivery attempt fails, I do not expect the message to end up in my
mock:result endpoint. But I see that the message is finally being delivered
to the mock:result endpoint.

If I add my own exception handler as follows:

exception(IllegalArgumentException.class).to("mock:exception");

then I see the message is delivered to both my mock:exception and mock:resut
endpoints

Am I missing something fundamental here?

Here is the Test case:
================

import junit.framework.TestCase;

import org.apache.camel.CamelContext;
import org.apache.camel.CamelTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.util.jndi.JndiContext;

public class ExceptionTest extends TestCase  {
        private CamelContext camelContext;
        private CamelTemplate<Exchange> template;

        public ExceptionTest(String name) {
                super(name);
        }

        protected void setUp() throws Exception {
                super.setUp();
                JndiContext context = new JndiContext();
                camelContext = new DefaultCamelContext(context);
                template = new CamelTemplate<Exchange>(camelContext);
                camelContext.start();
        }

        public void testException() throws Exception {
                final Processor  exceptionThrower = new Processor() {
                        public void process(Exchange exchange) throws Exception 
 {
                                exchange.getIn().setBody("<exception/>");
                                throw new IllegalArgumentException("Exception 
thrown intentionally.");
                        }
                };
                RouteBuilder builder = new RouteBuilder() {
                        public void configure() {
//                              
exception(IllegalArgumentException.class).to("mock:exception");
                                
from("direct:start").process(exceptionThrower).to("mock:result");
                        }
                };
                camelContext.addRoutes(builder);

                template.sendBody("direct:start", "<body/>");

                MockEndpoint resultEndpoint = 
camelContext.getEndpoint("mock:result",
MockEndpoint.class);
                MockEndpoint exceptionEndpoint =
camelContext.getEndpoint("mock:exception", MockEndpoint.class);

                resultEndpoint.expectedMessageCount(0);         
//              exceptionEndpoint.expectedMessageCount(1);
                MockEndpoint.assertIsSatisfied(resultEndpoint, 
exceptionEndpoint);
        }

        protected void tearDown() throws Exception {
                super.tearDown();
                camelContext.stop();
        }
}

-- 
View this message in context: 
http://www.nabble.com/Dead-Letter-Channel-delivers-message-when-it-shouldn%27t--tf4390150s22882.html#a12517101
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to