【问题标题】:Can exception clause works with rest dsl in camel 2.14.0?异常条款可以与骆驼 2.14.0 中的 rest dsl 一起使用吗?
【发布时间】:2014-10-08 07:57:10
【问题描述】:

我正在使用 camel 2.14.0 和新的 rest dsl 功能。似乎例外条款不适用于rest 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 未被调用。求帮助!!

【问题讨论】:

  • 也请确认一下,确实调用了 test()。
  • Apache Camel onException的可能重复
  • test() 确实被调用了,因为我可以在控制台中看到错误堆栈跟踪。
  • 这与Apache Camel onException不同。因为如果我使用java dsl而不是rest dsl我没有问题。

标签: java rest apache-camel


【解决方案1】:

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

 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 2020-05-13
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多