Until successful failure expression that checks for multiple types of exceptions

巧了我就是萌 提交于 2019-12-30 11:00:13

问题


In Mule, I'm using an until successful around an HTTP endpoint, to catch connection exceptions/timeouts. I'm catching 3 different Java exceptions:

  • java.net.ConnectException
  • java.net.SocketTimeoutException
  • java.net.SocketException

I want to put the catching of these 3 into a failureExpression in my until-successful block, however when I try to do something like

  • #[exception-type:XYZ || exception-type:ZYX]
  • #[exception-type:XYZ] || #[exception-type:ZYX]

I get an error that it cannot parse these. Is there any way I can specify for the failureExpression to check for multiple exception types?


回答1:


I was able to achieve what I wanted using this:

failureExpression="#[exception != null && (exception.causedBy(java.net.ConnectException) || exception.causedBy(java.net.SocketTimeoutException) || exception.causedBy(java.net.SocketException))]"

My problem was the exception in the failure expression could be null, so I had to perform a null check.




回答2:


This is not correct MEL syntax. It should be something like #[exception is Type1 || exception is Typ2].

See:

  • http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+MEL
  • http://mvel.codehaus.org/MVEL+2.0+Operators


来源:https://stackoverflow.com/questions/20505855/until-successful-failure-expression-that-checks-for-multiple-types-of-exceptions

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