0

I am using camel 2.14.0 and the new rest dsl feature. It seems exception clause is not working with rest dsl. Am I doing anything wrong? Here are my classes:

public MyRouteBuilder extends RouteBuilder {
    public void configure() throws Exception {
        restConfiguration.component("servlet").bindingMode(RestBindingMode.json);
        onException(RuntimeException.class).process(new MyProcessor()).stop();
        rest("/test")
            .get("/error")
                .route()
                    .bean(MyClassRaiseException.class, "test");
    }
}

public MyClassRaiseException {
    public void test() {
        throws new RuntimeException("TEST");
    }
}

public MyProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        System.out.println("This line of code is not executed");
    }
}

MyProcessor is not called. Helps are needed please!!

CL Chang
  • 148
  • 2
  • 8
  • please confirm us also, that test() is indeed called. – user2504380 Oct 08 '14 at 08:30
  • possible duplicate of [Apache Camel onException](http://stackoverflow.com/questions/14198043/apache-camel-onexception) – user2504380 Oct 08 '14 at 08:30
  • test() is indeed called, because I can see the error stack trace in my console. – CL Chang Oct 08 '14 at 14:38
  • This is not the same with [Apache Camel onException](http://stackoverflow.com/questions/14198043/apache-camel-onexception). Because I have no problem if I use java dsl instead of rest dsl. – CL Chang Oct 08 '14 at 14:44

1 Answers1

0

I may have a workaround for you. I had a similar problem with intercepting rest messages. The workaround involves creating an internal message that you can pick up exceptions from:

 public MyRouteBuilder extends RouteBuilder {
    public void configure() throws Exception {
        restConfiguration.component("servlet").bindingMode(RestBindingMode.json);
        onException(RuntimeException.class).process(new MyProcessor()).stop();
        rest("/test")
            .get("/error")
                .route().to("direct:errorTest");

        // Handles your internal message.
        from("direct:errorTest").bean(MyClassRaiseException.class, "test");
    }
}

There are two open issues for this problem. Please star the issues to get the developers attention:

https://issues.apache.org/jira/browse/CAMEL-7879

https://issues.apache.org/jira/browse/CAMEL-7820

jorgenfb
  • 2,215
  • 1
  • 21
  • 31