2014-10-08 62 views
0

我使用駱駝2.14.0和新的休息dsl功能。看起來異常從句不適用於其他dsl。我做錯了什麼?這裏是我的課程:異常子句可以在駝峯2.14.0中使用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未被調用。請幫助!

+0

請確認我們也該測試()確實調用。 – user2504380 2014-10-08 08:30:34

+0

可能重複的[Apache Camel onException](http://stackoverflow.com/questions/14198043/apache-camel-onexception) – user2504380 2014-10-08 08:30:46

+0

test()確實被調用,因爲我可以在控制檯中看到錯誤堆棧跟蹤。 – 2014-10-08 14:38:54

回答

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

相關問題