我有内置VFS的调用调解器来创建文件。当保存失败(无权限(时,我没有收到超时错误或其他理解的内容。这是顺序的一部分:<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>
问题是:保存失败时如何从呼叫调解器获取错误消息?
提前感谢!
您是否尝试过创建错误序列或错误处理程序?
您可以为代理服务添加故障序列:
<faultSequence>
<sequence key="conf:sequences/common/ErrorHandlerSeq.xml"/>
</faultSequence>
或者,要为序列定义错误处理程序,请执行以下操作:
<sequence name="mySequence" onError="conf:sequences/common/ErrorHandlerSeq.xml">
...
</sequence>
但是,wso2 中的错误处理有点特殊,调解器可能需要将异常包装到 SynapseException 中,以使其触发错误处理程序。
更新
在评论之后,它似乎是 WSO2 中错误处理的一个众所周知的问题。罪魁祸首是来自synapse-core.class的ProxyServiceMessageReceiver,具有以下行:
/* */ 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。