我有一个Mule流程,根据值来评估有效负载,可能会使用Groovy引发异常。我的流程如下:
<flow name="test-flow" doc:name="test-flow">
<vm:inbound-endpoint path="testexception.in" exchange-pattern="request-response" doc:name="VM"/>
<choice doc:name="Choice">
<when expression="#[payload == 'Goodbye']">
<logger message="**************** #[payload] ****************" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[throw new Exception('We have an error')]]></scripting:script>
</scripting:component>
</otherwise>
</choice>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger level="INFO" message="*** The exception is: #[exception] ***" doc:name="Logger"/>
<logger level="INFO" message="There has been an error" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
我发送“Hello”之类的消息时看到的错误如下所示:
ERROR 2014-05-29 12:18:39,707 [Thread-0] org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : Failed to invoke ScriptComponent{test-flow.component.1695047076}. Component that caused exception is: ScriptComponent{test-flow.component.1695047076}. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. We have an error (java.lang.Exception)
sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. java.lang.Exception: We have an error (javax.script.ScriptException)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:323 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/script/ScriptException.html)
3. Failed to invoke ScriptComponent{test-flow.component.1695047076}. Component that caused exception is: ScriptComponent{test-flow.component.1695047076}. Message payload is of type: String (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.Exception: We have an error
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
有没有办法可以访问异常堆栈的第一项,以便我可以评估该值并确保我的错误被正确抛出?在这种情况下,我希望访问“我们有错误”的值。我认为解决方案是使用#[exception]
,但这给了我org.mule.component.ComponentException: Failed to invoke ScriptComponent{test-flow.component.1695047076}. Component that...
这样的东西,这不是我所追求的。感谢任何帮助或指导,提前谢谢。
答案 0 :(得分:1)
org.mule.component.ComponentException
应该包装你的自定义异常,可能有几个级别。
为了提供帮助,Mule提供ExceptionUtils帮助挖掘异常并找到你想要的那个。