WSO2 Micro Integrator Validate Mediator 因不受支持的操作而失败

WSO2 Micro Integrator Validate Mediator fails with Unsupported Operation

在 Windows 10.

中使用 Integration Studio

当我尝试使用带有验证调解器的序列从 REST API 主体验证我的有效负载时,我收到错误消息。 错误:

[2020-03-10 11:07:29,295]  INFO {TRACE_LOGGER} - Building message. Sequence <SequenceMediator> is content aware
[2020-03-10 11:07:29,309] ERROR {org.apache.synapse.mediators.base.SequenceMediator} - Unsupported Operation org.apache.axiom.om.OMException: Unsupported Operation
at org.apache.axiom.om.impl.llom.OMTextImpl.getInputStream(OMTextImpl.java:422)
at org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:231)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:214)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:37)
at org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:69)
at org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:134)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:331)
at org.apache.synapse.rest.API.process(API.java:440)
at org.apache.synapse.rest.RESTRequestHandler.apiProcessNonDefaultStrategy(RESTRequestHandler.java:149)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:95)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:98)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:367)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:412)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:181)
at org.apache.axis2.transport.base.threads.NativeWorkerPool.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

然后我尝试从中验证:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="Reserves" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<validate cache-schema="false" source="json-eval($)">
    <schema key="conf:/schemas/ReservesRoot.json"/>
    <on-fail>
        <payloadFactory media-type="json">
            <format>{"Error":"}</format>
            <args>
                <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
            </args>
        </payloadFactory>
        <property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
        <respond/>
    </on-fail>
</validate>
</sequence>

JSON 架构:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "Type": {
            "type": "string"
        }
    },
    "required": [
        "Type"
    ]
}

当我在 属性 中获取模式时,我看到了模式的字符串。

<property value="get-property('registry', 'conf:/schemas/ReservesRoot.json')" name="ReservesSchema"/>
<log>
    <property expression="get-property('ReservesSchema')" name="JSON_P"/>
</log>

当注册表中保存的 JSON-schema 没有正确的媒体类型(必须是 application/json)时,会出现此问题。您能否在 Integration Studio Resources Editor 视图中仔细检查一下。

您可以通过右键单击注册表资源项目 -> 注册表资源编辑器来访问资源编辑器视图

微型集成器会出现此问题。微型集成商没有 rdbms 注册表工件。因此我们不能指定媒体类型。解决方法是使用验证 json 架构添加本地条目文件并在突触中引用它。

<validate cache-schema="false">
                      <schema key="createotpvalidate"/>
                        <on-fail>
                            <payloadFactory media-type="json">
                                <format>{"Error":"}</format>
                                <args>
                                    <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
                                </args>
                            </payloadFactory>
                            <property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
                            <respond/>
                            <!-- <schema key="conf:/schema/CreateOTPSchema.json"/> -->
                        </on-fail>
                    </validate>

Local Entry file:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="createotpvalidate" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[{  "$schema": "http://json-schema.org/draft-04/schema#",  "type": "object",  "properties": {            "request_type": {              "type": "string"            },"mobile": {              "type": "string"            },"otp": {              "type": "string"            }          },          "required": [            "request_type","mobile","otp"          ]        }]]></localEntry>