Global onException to handle multiple RouteBuilder classes

ⅰ亾dé卋堺 提交于 2019-12-25 02:15:09

问题


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]


回答1:


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...



来源:https://stackoverflow.com/questions/6719748/global-onexception-to-handle-multiple-routebuilder-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!