【问题标题】:Mule - accessing the exception stack and logging a particular partMule - 访问异常堆栈并记录特定部分
【发布时间】:2014-07-18 22:13:31
【问题描述】:

我有一个 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... 的东西,这不是我想要的。感谢您提供任何帮助或指导,在此先感谢。

【问题讨论】:

    标签: java exception groovy mule stack-trace


    【解决方案1】:

    org.mule.component.ComponentException 应该包含您的自定义异常,可能有几个级别。

    为了提供帮助,Mule 提供了ExceptionUtils 来帮助挖掘异常并找到您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      相关资源
      最近更新 更多