Mule - 访问异常堆栈并记录特定的部分 [英] Mule - accessing the exception stack and logging a particular part

查看:283
本文介绍了Mule - 访问异常堆栈并记录特定的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Mule流根据该值来评估一个有效负载,可能会使用Groovy引发异常。我的流程如下所示:

 < flow name =test-flowdoc:name =test-flow> ; 
< vm:inbound-endpoint path =testexception.inexchange-pattern =request-responsedoc:name =VM/>

< choice doc:name =选择>
< when expression =#[payload =='Goodbye']>
< logger message =****************#[payload] ****************level = INFOdoc:name =Logger/>
< / when>

< else>
< scripting:component doc:name =Groovy>
< scripting:script engine =Groovy><![CDATA [throw new Exception('We have a error')]]>< / scripting:script>
< / scripting:component>
< / otherwise>
< / choice>

< catch-exception-strategy doc:name =Catch Exception Strategy>
< logger level =INFOmessage =***异常是:#[exception] ***doc:name =Logger/>
< logger level =INFOmessage =发生错误doc:name =Logger/>
< / catch-exception-strategy>
< / flow>

当我发送像Hello这样的消息时,我看到的错误如下所示:

 错误2014-05-29 12:18:39,707 [Thread-0] org.mule.exception.CatchMessagingExceptionStrategy:
************************************************ ********************************
消息:无法调用ScriptComponent {test-flow.component.1695047076 }。导致异常的组件是:ScriptComponent {test-flow.component.1695047076}。消息有效载荷类型为:String
代码:MULE_ERROR - 2
----------------------------- -------------------------------------------------- -
异常堆栈是:
1.我们有一个错误(java.lang.Exception)
sun.reflect.NativeConstructorAccessorImpl:-2(null)
2. java.lang .Exception:我们有一个错误(javax.script.ScriptException)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:323(http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ javax / script / ScriptException.html)
3.无法调用ScriptComponent {test-flow.component.1695047076}。导致异常的组件是:ScriptComponent {test-flow.component.1695047076}。消息有效载荷的类型为:String(org.mule.component.ComponentException)
org.mule.component.AbstractComponent:148(http://www.mulesoft.org/docs/site/current3/apidocs/org/ mule / component / ComponentException.html)
-------------------------------------- ------------------------------------------
根异常堆栈跟踪:
java.lang.Exception:我们在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)上有一个错误

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
+ 3更多(设置调试级别日志记录或-Dmule.verbose.exceptions = true为所有)
* ************************************************** *****************************

有没有办法可以访问异常堆栈的第一个项目,以便我可以评估值确保我的错误已经被正确抛出?在这种情况下,我正在寻找值'我们有错误'。我以为解决方案是使用#[exception] ,但这给了我像$ code> org.mule.component.ComponentException:无法调用ScriptComponent {test -flow.component.1695047076}。组件... 这不是我以后。任何帮助或指导都是感谢,谢谢提前。

解决方案

org.mule.component.ComponentException为了帮助,Mule提供 ExceptionUtils ,以帮助挖掘异常并找到所需的。


I have a Mule flow that evaluates a payload an depending on the value, may throw an exception using Groovy. My flow looks as follows:

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

The error I see when I send a message like 'Hello' for example is something like the below:

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)
********************************************************************************

Is there a way I can access the first item of the exception stack so that I can evaluate the value and ensure my error has been thrown correctly? In this case I'm looking to access the value 'We have an error'. I thought the solution was in using #[exception] but this gives me something like org.mule.component.ComponentException: Failed to invoke ScriptComponent{test-flow.component.1695047076}. Component that... which isn't what I'm after. Any help or guidance is appreciated, thanks in advance.

解决方案

The org.mule.component.ComponentException should wrap your custom exception, maybe several level deep.

To help, Mule provides ExceptionUtils to help digging in the exception and finding the one you want.

这篇关于Mule - 访问异常堆栈并记录特定的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆