java - Mule - 访问异常堆栈并记录特定部分

标签 java exception groovy mule stack-trace

我有一个 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} 的内容。组件... 这不是我想要的。感谢任何帮助或指导,提前致谢。

最佳答案

org.mule.component.ComponentException 应该包装您的自定义异常,可能有几层深度。

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

关于java - Mule - 访问异常堆栈并记录特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23932785/

相关文章:

Java泛型捕获错误 "? super capture#1 of ? super T"

java - AES128 解密 :javax. crypto.badpaddingexception pad block 已损坏

c# - 在 Debug模式下观察变量时出现 FileNotFoundException

Groovy 'No signature of method' 针对委托(delegate)运行关闭

mysql - 如何使用 JDBC 更改模式以连接到 Grails 中的 MySQL?

java - Kafka Stream根据json消息中的时间戳键对消息进行排序

java - 使用 JUnit 测试图形生成

java - Hibernate:如何刷新子实体

exception - 为什么Haskell中的()是Enum类型却没有实现succ函数

java - 定时器任务和线程