开发者

Global onException to handle multiple RouteBuilder classes

I need to make onException, to be global over the whole route builders I have in order not to rewrite the same line for every route builder I create . The current scope for my exception handler is a camel context for specific route builder . I need to make route builder classes ,r1 and r2, to use the same onException().process.

开发者_如何学运维

The current working onException I use :

def configure {

     onException(classOf[CustomException]).process(exceptionProcessor).
       process(doExtraProcess)


    from(address).
            process(doSmth).
            process(doSmthElse)
  }

When I have moved the onException() line from configre method to be on the class level like the following :

  onException(classOf[CustomException]).process(exceptionProcessor).
           process(doExtraProcess)

    def configure {

        from(address).
                process(doSmth).
                process(doSmthElse)
      }

I got this error :

Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route52 at: >>> OnException[[class CustomException] -> [process[null], process[null]]] <<< in route: Route[[From[direct:locus]] -> [OnException[[... because of ref must be specified on: process[null]

Caused by: java.lang.IllegalArgumentException: ref must be specified on: process[null]


First, onException() needs to called by the configure() method. Next, you can just use inheritance to reuse exception handling. Just create a parent RouteBuilder class and put common exception handling in a method. Then have each subclass call that common method in their configure() method...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜