异常子句可以在camel 2.14.0中使用rest dsl吗?

时间:2014-10-08 07:57:11

标签: java rest apache-camel

我正在使用camel 2.14.0和新的rest dsl功能。似乎异常条款不适用于休息dsl。我做错了吗?这是我的课程:

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。请帮忙!!

1 个答案:

答案 0 :(得分:0)

我可能有一个解决方法。拦截休息消息时遇到了类似的问题。解决方法涉及创建内部消息,您可以从以下内容中获取异常:

 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");
    }
}

此问题有两个未解决的问题。请解决问题,以引起开发人员的注意:

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

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