WSO2 ESB 序列模板错误

WSO2 ESB sequence templates error

我正在使用 WSO2 ESB 序列模板生成通用验证模板。该模板将收到一条简单的 XML 消息,并将根据其架构对其进行验证。 Validate Mediator 需要两件事作为输入。一个是 "sourceElement" 另一个是 "schemaFilePath"

问题:

我已成功将 "sourceElement" 作为参数传递,但我没有通过调用模板调解器的参数传递架构文件路径。我可以在模板中接收它,但无法在“validate”调解器中使用它。

注意:我正在使用 WSO2 ESB 4.8.1 和 WSO2 developer studio 3.7.0。

"Template Code:"

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns="http://ws.apache.org/ns/synapse" name="ValidateCDM">
    <parameter name="sourceElement"/>
    <parameter name="schemaFilePath"/>
    <sequence>
        <validate xmlns:ns="http://org.apache.synapse/xsd" source="$func:sourceElement">
            <schema key="$func:schemaFilePath"/>
            <on-fail>
                <makefault version="pox">
                    <reason value="Invalid Request"/>
                    <detail>Invalid Request</detail>
                </makefault>
                <payloadFactory media-type="xml" description="ErrorMessageTransformation">
                    <format>
                        <Error>
                            <ErrorCode>404</ErrorCode>
                            <ErrorMessage>Error Thrown.</ErrorMessage>
                            <ErrorException>Unknown Exception</ErrorException>
                        </Error>
                    </format>
                </payloadFactory>
                <send>
                    <endpoint key="conf:ErrorQueue.xml"/>
                </send>
            </on-fail>
        </validate>
    </sequence>
</template>

"Call-Template Mediator Code:"

<call-template target="ValidateCDM" description="ValidateCDM">
        <with-param xmlns:abc="http://com.example/finance/datafile" name="sourceElement" value="{//abc:Message}"/>
        <with-param name="schemaFilePath" value="conf:/Example/XSD/IncomingMessage.xsd"/>
    </call-template>

"Exception in the Logs"

ERROR_MESSAGE : Cannot convert null to a StreamSource {org.apache.synapse.FaultHandler}
TID: [0] [ESB] [2015-01-27 10:32:50,559]  WARN {org.apache.synapse.FaultHandler} -  ERROR_DETAIL : org.apache.synapse.SynapseException: Cannot convert null to a StreamSource
    at org.apache.synapse.config.SynapseConfigUtils.handleException(SynapseConfigUtils.java:576)
    at org.apache.synapse.config.SynapseConfigUtils.getStreamSource(SynapseConfigUtils.java:77)
    at org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:146)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.template.TemplateMediator.mediate(TemplateMediator.java:77)
    at org.apache.synapse.mediators.template.InvokeMediator.mediate(InvokeMediator.java:129)
    at org.apache.synapse.mediators.template.InvokeMediator.mediate(InvokeMediator.java:78)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
    at org.apache.axis2.transport.jms.JMSMessageReceiver.processThoughEngine(JMSMessageReceiver.java:200)
    at org.apache.axis2.transport.jms.JMSMessageReceiver.onMessage(JMSMessageReceiver.java:122)
    at org.apache.axis2.transport.jms.ServiceTaskManager$MessageListenerTask.handleMessage(ServiceTaskManager.java:556)
    at org.apache.axis2.transport.jms.ServiceTaskManager$MessageListenerTask.run(ServiceTaskManager.java:449)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
 {org.apache.synapse.FaultHandler}

您想传递动态键值,但请先检查键区域允许的任何 x 路径或 属性 值?请检查并确认。如果wso2不允许,那是不可能的,但请先确认一下。

谢谢, 阿瓦伊斯·纳伊姆

$func:XXX 用作键时必须用大括号括起来:

<schema key="{$func:schemaFilePath}"/>

也许你需要对源属性做同样的事情:

<validate xmlns:ns="http://org.apache.synapse/xsd" source="{$func:sourceElement}">