问题
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