【问题标题】:wso2 micro integrator fails to validate with json schemawso2 微集成器无法使用 json 模式进行验证
【发布时间】:2022-11-23 06:49:28
【问题描述】:

我正在尝试在 WSO2 微集成器 1.2.0 中使用 json 模式验证消息。

<validate cache-schema="true">
    <schema key="conf:schema/eip_dit_oko_jsonschema_stage_0_input_params.json"/>
    <on-fail>
        <payloadFactory media-type="json">
            <format>{"Error":"$1","Error Details":"$2"}</format>
            <args>
                <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
                <arg evaluator="xml" expression="$ctx:ERROR_DETAIL"/>
            </args>
        </payloadFactory>
        <property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
       <respond/>
    </on-fail>
</validate>

如果架构文件在注册表中

       <item>
            <file>eip_dit_oko_jsonschema_stage_0_input_params.json</file>
            <path>/_system/config/schema</path>
            <mediaType>application/json</mediaType>
            <properties/>
        </item>

然后序列失败

[2022-11-22 21:14:33,492] ERROR {ValidateMediator} - {api:eip_dit_oko_api_stage_0} Error creating a new schema objects for schemas : [Value {name ='null', keyValue ='conf:schema/eip_dit_oko_jsonschema_stage_0_input_params.json'}] org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:74)
    at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXException(Util.java:62)
    at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:258)
    at org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:429)
...

显然,集成商试图将 json-schema 文件读取为 xml。

如果我尝试遵循这个答案about using local entry instead of registry

<validate cache-schema="true">
    <schema key="eip_dit_oko_jsonschema_stage_0_input_params"/>
...
</validate>
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="eip_dit_oko_jsonschema_stage_0_input_params" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[{    "$schema": "http://json-schema.org/draft-04/schema",    "id": "http://example.com/example.json",    "type": "object",    "title": "The root schema",    "required": [        "getData"    ],    "properties": {        "getData": {            "id": "#getData",            "type": "object",            "title": "The getData schema",            "required": [                "p_limit",                "p_offset"            ],            "properties": {                "p_limit": {                    "id": "#p_limit",                    "type": "integer",                    "title": "The p_limit schema"                },                "p_offset": {                    "id": "#p_offset",                    "type": "integer",                    "title": "The p_offset schema"                },                "p_defect_text": {    "id": "#/properties/defect_text",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },                "p_district_code": {                    "id": "#p_district_code",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "integer"    }                },                "p_okrug_code": {                    "id": "#p_okrug_code",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "integer"    }                },                "p_status": {                    "id": "#p_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },                "p_sys_status": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },                "p_ticket": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },                "p_season": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },                "p_critical": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }                },               "p_owner_name": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_address": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_address_like": {                    "id": "#p_address_like",                    "type": "string"               },"p_id_object": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "integer"    }                },               "p_id_300": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_type_object": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_id_systems": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_defect_el1": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_defect_el": {                    "id": "#p_sys_status",    "type": "array",    "items": {"id": "#/properties/defect_text/items","type": "string"    }               },               "p_sys_sla": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_sys_sla_from": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_sys_sla_to": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_data_creation_from": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_data_creation_to": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_view_date_from_from": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_view_date_to_to": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_view_date_from_to": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_view_date_to_from": {                    "id": "#p_sys_status",                    "type": "string",    "format":"date-time",                    "title": "The p_sys_status schema"               },               "p_deadline": {                    "id": "#p_sys_status",                    "type": "number",                    "title": "The p_sys_status schema"               }            }        }    }}]]></localEntry>

然后调解失败,因为

[2022-11-22 16:13:17,517]  WARN {SynapseConfigUtils} - Cannot convert object to a StreamSource

【问题讨论】:

    标签: wso2 wso2-esb wso2-micro-integrator


    【解决方案1】:

    出现此问题的原因之一是您发送的有效负载不是 JSON,或者您没有发送 Content-Type: application/json 标头。但我会假设如果您发送的内容类型不正确,它会在到达验证中介之前失败。所以我的猜测是您根本没有随请求发送任何有效负载。您是否尝试使用 GET 请求对此进行测试?根据code,如果您不发送 JSON 有效载荷,它将沿着 XML 路径向下移动,这可能会导致您面临的问题,因此请确保您在请求中发送有效的 JSON 有效载荷。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2015-06-07
      相关资源
      最近更新 更多