当我们在Groovy脚本mule中引发异常时,如何限制ERROR日志不会打印在日志中。 以下是流程和响应。
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="7475" doc:name="HTTP Listener Configuration"/>
<flow name="ExceptionTestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[throw new Exception("Invalid Message")]]></scripting:script>
</scripting:component>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
Response as follows:
INFO 2017-02-09 12:13:52,928 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor:
org.mule.DefaultMuleMessage
{
id=1efcb560-ee93-11e6-a87c-005056880d06
payload=org.mule.transport.NullPayload
correlationId=<not set>
correlationGroup=-1
correlationSeq=-1
encoding=UTF-8
exceptionPayload=<not set>
Message properties:
INVOCATION scoped properties:
INBOUND scoped properties:
accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
accept-encoding=gzip, deflate, sdch, br
accept-language=en-US,en;q=0.8
connection=keep-alive
host=localhost:7475
http.listener.path=/test
http.method=GET
http.query.params=ParameterMap{[]}
http.query.string=
http.relative.path=/test
http.remote.address=/127.0.0.1:60711
http.request.path=/test
http.request.uri=/test
http.scheme=http
http.uri.params=ParameterMap{[]}
http.version=HTTP/1.1
upgrade-insecure-requests=1
user-agent=Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
OUTBOUND scoped properties:
SESSION scoped properties:
}
ERROR 2017-02-09 12:13:53,305 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : Failed to invoke ScriptComponent{ExceptionTestFlow.component.693275170}. Component that caused exception is: ScriptComponent{ExceptionTestFlow.component.693275170}. Message payload is of type: NullPayload
Type : org.mule.component.ComponentException
Code : MULE_ERROR--2
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html
Payload : {NullPayload}
********************************************************************************
Exception stack is:
1. Invalid Message (java.lang.Exception)
sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. java.lang.Exception: Invalid Message (javax.script.ScriptException)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:326 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/script/ScriptException.html)
3. Failed to invoke ScriptComponent{ExceptionTestFlow.component.693275170}. Component that caused exception is: ScriptComponent{ExceptionTestFlow.component.693275170}. Message payload is of type: NullPayload (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:142 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
********************************************************************************
Root Exception stack trace:
java.lang.Exception: Invalid Message
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at Script1.run(Script1.groovy:1)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:323)
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:44)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.mule.module.scripting.component.Scriptable.runScript(Scriptable.java:287)
at org.mule.module.scripting.component.ScriptComponent.doInvoke(ScriptComponent.java:78)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:120)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:55)
at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:236)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.component.AbstractComponent.process(AbstractComponent.java:154)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:55)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
at org.mule.processor.BlockingProce...
********************************************************************************
INFO 2017-02-09 12:13:53,334 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: null
它正在记录ERROR日志,它将捕获异常策略。在某些情况下,我不想记录ERROR(例如:整个ERROR块::: ERROR 2017-02-09 12:13:53,305 [[ExceptionTest] .HTTP_Listener_Configuration.worker.01])日志。请问有人帮助我们如何忽略在日志中打印ERROR日志并执行catch异常策略块。注意:我只需要限制应用程序级别。
答案 0 :(得分:0)
双击 catch-exception-strategy 组件以查看其属性。然后取消选中日志例外选项。
答案 1 :(得分:0)
Mule runtime 3.7.x没有在其实现中定义的logException属性。避免堆栈跟踪的解决方案如下。
在catch-exception-strategy中定义一个记录器并设置类别,同时将级别设置为ERROR以通知消息该异常。
此外,将应用程序log4j2.xml中的类别“org.mule.exception.CatchMessagingExceptionStrategy”设置为FATAL
如果您想要任何特定异常的堆栈跟踪,请将此记录器保留在该块中,
<logger message="Exceptions message is ... #[org.mule.util.ExceptionUtils.getFullStackTrace(exception)]" level="ERROR" doc:name="exceptionLogger"/>