Mule-使用Choice和Catch进行异常处理会产生奇怪的错误

时间:2018-01-04 15:41:06

标签: exception-handling mule

我正在Mule运行时3.8.0中尝试实现异常处理。据我所知,我做的一切都很正确,但仍然会遇到奇怪的错误:

我的代码看起来像这样: 主流与参考例外策略:

<flow name="mod4Flow2">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/sg" doc:name="HTTP"/>
    <scatter-gather doc:name="Scatter-Gather">
        <flow-ref name="mod4Sub_Flow" doc:name="mod4Sub_Flow"/>
        <flow-ref name="mod4Sub_Flow1" doc:name=""/>
        <flow-ref name="mod4Sub_Flow2" doc:name=""/>
    </scatter-gather>
    <logger message="Combined payload : #[message.payload]" level="INFO" doc:name="Logger"/>
    <exception-strategy ref="exceptionconfigChoice_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<sub-flow name="mod4Sub_Flow">
    <set-payload value="From mod4Sub_Flow" doc:name="Set Payload"/>
</sub-flow>
<sub-flow name="mod4Sub_Flow1">
    <set-payload value="From mod4Sub_Flow1" doc:name="Set Payload"/>
</sub-flow>
<sub-flow name="mod4Sub_Flow2">
    <set-payload value="From mod4Sub_Flow2" doc:name="Set Payload"/>
</sub-flow>

单独配置文件中的全局异常策略“:

 <choice-exception-strategy name="exceptionconfigChoice_Exception_Strategy">
    <catch-exception-strategy doc:name="Catch Exception Strategy-UnSupported Operation" when="#[exception.causedBy(java.lang.UnsupportedOperationException)]">
        <set-property propertyName="http.status" value="400" doc:name="Property"/>
        <logger message="The exception is : #[exception]" level="INFO" doc:name="Logger"/>
        <set-payload value="Something wrong in Scatter-Gather !" doc:name="Set Payload"/>
    </catch-exception-strategy>
    <catch-exception-strategy doc:name="Catch Exception Strategy - SQL" when="#[exception.causeMatches('java.sql.*')]">
    <set-property propertyName="http.status" value="400" doc:name="Property"/>
        <logger message="The exception is : #[exception]" level="INFO" doc:name="Logger"/>
        <set-payload value="Something wrong in DB !" doc:name="Set Payload"/>
    </catch-exception-strategy>
</choice-exception-strategy>

在跑步的过程中我遇到了异常:

    ERROR 2018-01-04 21:01:46,704 [[mod4].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Execution of the expression "exception.causedBy(java.lang.UnsupportedOperationException)" failed.
org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "exception.causedBy(java.lang.UnsupportedOperationException)" failed.
    at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:232) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:163) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:142) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:216) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.expression.DefaultExpressionManager.evaluateBoolean(DefaultExpressionManager.java:417) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.expression.DefaultExpressionManager.evaluateBoolean(DefaultExpressionManager.java:674) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.exception.TemplateMessagingExceptionStrategy.accept(TemplateMessagingExceptionStrategy.java:191) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.exception.ChoiceMessagingExceptionStrategy.handleException(ChoiceMessagingExceptionStrategy.java:55) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase$3$1.execute(AsyncResponseFlowProcessingPhase.java:131) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase.executeCallback(AsyncResponseFlowProcessingPhase.java:144) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase.access$000(AsyncResponseFlowProcessingPhase.java:35) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase$3.responseSentWithFailure(AsyncResponseFlowProcessingPhase.java:125) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.HttpMessageProcessorTemplate.doBuildResponse(HttpMessageProcessorTemplate.java:129) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.HttpMessageProcessorTemplate.buildResponse(HttpMessageProcessorTemplate.java:112) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.HttpMessageProcessorTemplate.sendResponseToClient(HttpMessageProcessorTemplate.java:86) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase.runPhase(AsyncResponseFlowProcessingPhase.java:78) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.AsyncResponseFlowProcessingPhase.runPhase(AsyncResponseFlowProcessingPhase.java:35) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine$InternalPhaseExecutionEngine.phaseSuccessfully(PhaseExecutionEngine.java:65) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine$InternalPhaseExecutionEngine.phaseSuccessfully(PhaseExecutionEngine.java:69) ~[mule-core-3.8.0.jar:3.8.0]
    at com.mulesoft.mule.throttling.ThrottlingPhase.runPhase(ThrottlingPhase.java:186) ~[mule-module-throttling-ee-3.8.0.jar:3.8.0]
    at com.mulesoft.mule.throttling.ThrottlingPhase.runPhase(ThrottlingPhase.java:57) ~[mule-module-throttling-ee-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine$InternalPhaseExecutionEngine.phaseSuccessfully(PhaseExecutionEngine.java:65) ~[mule-core-3.8.0.jar:3.8.0]
    at com.mulesoft.gateway.http.phases.GatewayValidationPhase.runPhase(GatewayValidationPhase.java:93) ~[gateway-core-3.8.0.jar:3.8.0]
    at com.mulesoft.gateway.http.phases.GatewayValidationPhase.runPhase(GatewayValidationPhase.java:49) ~[gateway-core-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine$InternalPhaseExecutionEngine.phaseSuccessfully(PhaseExecutionEngine.java:65) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.modules.cors.CorsPhase.runPhase(CorsPhase.java:113) ~[mule-module-cors-gw-3.8.0.jar:3.8.0]
    at org.mule.modules.cors.CorsPhase.runPhase(CorsPhase.java:40) ~[mule-module-cors-gw-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine$InternalPhaseExecutionEngine.process(PhaseExecutionEngine.java:114) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.PhaseExecutionEngine.process(PhaseExecutionEngine.java:41) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.execution.MuleMessageProcessingManager.processMessage(MuleMessageProcessingManager.java:32) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.DefaultHttpListener$1.handleRequest(DefaultHttpListener.java:133) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.grizzly.GrizzlyRequestDispatcherFilter.handleRead(GrizzlyRequestDispatcherFilter.java:83) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) ~[grizzly-framework-2.3.24.jar:2.3.24]
    at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.run0(ExecutorPerServerAddressIOStrategy.java:102) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.access$100(ExecutorPerServerAddressIOStrategy.java:30) ~[mule-module-http-3.8.0.jar:3.8.0]
    at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy$WorkerThreadRunnable.run(ExecutorPerServerAddressIOStrategy.java:125) ~[mule-module-http-3.8.0.jar:3.8.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: org.mule.mvel2.PropertyAccessException: [Error: unable to resolve method: java.lang.RuntimeException.causedBy(java.lang.Class) [arglength=1]]
[Near : {... exception.causedBy(java.lang.U ....}]
             ^
[Line: 1, Column: 1]
    at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1178) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1087) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:415) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:212) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.ast.ASTNode.optimize(ASTNode.java:159) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.MVELRuntime.execute(MVELRuntime.java:86) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.mvel2.MVEL.executeExpression(MVEL.java:953) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
    at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:87) ~[mule-core-3.8.0.jar:3.8.0]
    at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:228) ~[mule-core-3.8.0.jar:3.8.0]
    ... 45 more

2 个答案:

答案 0 :(得分:0)

在全局异常配置xml中,尝试替换

when="#[exception.causedBy(java.lang.UnsupportedOperationException)]"

when="exception.causedBy(java.lang.UnsupportedOperationException)"

并替换

when="#[exception.causeMatches('java.sql.*')]"

when="exception.causeMatches('java.sql.*')"

答案 1 :(得分:0)

从您的代码中我假设当您捕获的错误类型为java.lang.UnsupportedOperationException或java.sql时,会抛出此错误。*?

如果是这样,那是因为Mule在转换有效负载时遇到了问题,java.util.concurrent.CopyOnWriteArrayList的一个对象是从分散 - 收集组件到Http Response对象的。

尝试添加默认的Catch异常策略,同时覆盖有效负载。

<catch-exception-strategy doc:name="Catch Exception Strategy">
    <set-property propertyName="http.status" value="400" doc:name="Property"/>
    <logger message="The exception is : #[exception]" level="INFO" doc:name="Logger"/>
    <set-payload value="Something wrong in DB !" doc:name="Set Payload"/>
</catch-exception-strategy>

如果能消除错误,请告诉我?