Camel Route onExcpetion / errorHandle没有捕获Salesforce Compotent异常

时间:2017-01-11 21:45:56

标签: groovy apache-camel

首次使用Camel Routes,所有Apache文档和围绕sof的信息使它看起来非常简单....(这是groovy,使用Apache Camel和Camel Salesforce组件作为库)

 class SFRouteClass extends RouteBuilder {

   @Override
    void configure() {
        def camelRouteId

        from("direct:moveFailedMessage")
            .process { Exchange exchange ->
                exchange.out
            } 
        from('direct:sfe')
            .onException(Exception.class)
                .to('log:sfe?level=INFO&showHeaders=true&multiline=true')
                .to('direct:moveFailedMessage')
                .maximumRedeliveries(0)
            .end()
            .routeId('sfe')
            .enrich('direct:salesforceCheckLeadByIDUserHashId'.toString(), new AggregationStrategy() { ..... }
 } 

org.apache.camel.component.salesforce.api.SalesforceException: Error {404:Not Found} executing {GET:https://.....}
    at org.apache.camel.component.salesforce.internal.client.AbstractClientBase$1.onComplete(AbstractClientBase.java:176)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:193)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:185)
    at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:453)
    at org.eclipse.jetty.client.HttpReceiver.responseSuccess(HttpReceiver.java:400)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.messageComplete(HttpReceiverOverHTTP.java:266)
    at org.eclipse.jetty.http.HttpParser.parseContent(HttpParser.java:1487)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1245)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:156)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:117)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:69)
    at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:89)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:123)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.camel.component.salesforce.api.SalesforceException: {errors:[{"errorCode":"NOT_FOUND","message":"The requested resource does not exist"}],statusCode:404}
    at org.apache.camel.component.salesforce.internal.client.DefaultRestClient.createRestException(DefaultRestClient.java:121)
    at org.apache.camel.component.salesforce.internal.client.AbstractClientBase$1.onComplete(AbstractClientBase.java:175)
    ... 16 common frames omitted

如果没有错误,则此方法有效。我的问题是onException从不触发。我试图在配置中创建一个全局errorHandler,并且我尝试创建一个全局onExcpetion。什么都没有捕捉到错误,我无法弄清楚原因。

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用doTry / doCatch方式?

from('direct:sfe')
   .routeId('sfe')
    .doTry()
    .enrich('direct:salesforceCheckLeadByIDUserHashId'.toString(), new AggregationStrategy() { ..... }
    .doCatch(Exception.class)
              .to('log:sfe?level=INFO&showHeaders=true&multiline=true')
              .to('direct:moveFailedMessage')
              .maximumRedeliveries(0) // NOt needed as default is 0
      .end()

答案 1 :(得分:0)

你需要

  1. direct:salesforceCheckLeadByIDUserHashId开始的路由上没有设置错误处理程序,因此您在其他路径上的路径范围错误处理程序可以启动

  2. 或者也可以将onException添加/移动到该路由。