我在内部使用VFS调用mediator来创建文件。当保存失败(没有权限)时,我没有收到超时错误或其他东西来理解。这是顺序的一部分:
<property description="Concat path"
expression="fn:concat('vfs:file:///',get-property('BPath'),'/',get-property('dynamic'),'/wso2.file')"
name="Path"
scope="default"
type="STRING"/>
<header expression="get-property('Path')" name="To" scope="default"/>
<property description="OUT_ONLY=true"
name="OUT_ONLY"
scope="default"
type="STRING"
value="true"/>
<call description="">
<endpoint>
<default/>
</endpoint>
</call>
问题是:保存失败时如何从调用介体获取错误消息?
提前致谢!
答案 0 :(得分:0)
您是否尝试过创建故障序列或错误处理程序?
您可以为代理服务添加故障序列:
<faultSequence>
<sequence key="conf:sequences/common/ErrorHandlerSeq.xml"/>
</faultSequence>
或者,为序列定义错误处理程序:
<sequence name="mySequence" onError="conf:sequences/common/ErrorHandlerSeq.xml">
...
</sequence>
但是,wso2中的错误处理有点特殊,您的介体可能需要将异常包装到SynapseException中,以使其触发错误处理程序。
<强>更新强>
在评论之后,它看起来是WSO2中错误处理的一个众所周知的问题。罪魁祸首是来自synapse-core的ProxyServiceMessageReceiver.class,其中包含以下几行:
/* */ catch (SynapseException syne)
/* */ {
/* 193 */ if (!synCtx.getFaultStack().isEmpty()) {
/* 194 */ warn(traceOn, "Executing fault handler due to exception encountered", synCtx);
/* 195 */ ((FaultHandler)synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
/* */ }
/* */ else {
/* 198 */ warn(traceOn, "Exception encountered but no fault handler found - message dropped", synCtx);
/* */ }
/* */ }
/* */ finally {
/* 202 */ StatisticsReporter.endReportForAllOnRequestProcessed(synCtx);
/* */ }
这里显而易见的问题是,只有在捕获到SynapseException时才会触发错误处理程序,其他的只是被忽略。
如果您有可能更新WSO2实例的类,则可以使其捕获所有异常。
我用以下内容更改了这段代码:
/* */ catch (Exception syne)
/* */ {
/* 193 */ log.error("Exception caught on mediation sequence", syne);
if (!synCtx.getFaultStack().isEmpty()) {
/* 194 */ warn(traceOn, "Executing fault handler due to exception encountered", synCtx);
try {
/* 195 */ ((FaultHandler)synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
} catch (Exception ex) {
log.error("Exception caught while executing fault handler", ex);
//warn(traceOn, "Exception caught while executing fault handler", synCtx);
if (!synCtx.getFaultStack().isEmpty()) {
warn(traceOn, "Executing nested fault handler", synCtx);
try {
((FaultHandler)synCtx.getFaultStack().pop()).handleFault(synCtx, ex);
} catch (Exception e) {
log.error("Exception caught while executing nested fault handler, mediation stopped", e);
}
} else {
warn(traceOn, "No nested fault handler found - message dropped", synCtx);
}
}
/* */ }
/* */ else {
/* 198 */ warn(traceOn, "Exception encountered but no fault handler found - message dropped", synCtx);
/* */ }
/* */ }
它允许使用甚至嵌套的错误处理程序,它不能在盒子外工作,AFAIK。