[英]wso2 micro integrator fails to validate with json schema
I'm trying to validate message with json schema in WSO2 micro integrator 1.2.0.我正在尝试在 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>
If the schema file is in registry如果架构文件在注册表中
<item>
<file>eip_dit_oko_jsonschema_stage_0_input_params.json</file>
<path>/_system/config/schema</path>
<mediaType>application/json</mediaType>
<properties/>
</item>
then sequence fails with然后序列失败
[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)
...
Obviously, integrator tries to read json-schema file as xml.显然,集成商试图将 json-schema 文件读取为 xml。
If I try to follow this answer 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>
then mediation fails as this然后调解失败,因为
[2022-11-22 16:13:17,517] WARN {SynapseConfigUtils} - Cannot convert object to a StreamSource
EDIT Request:编辑请求:
curl -v http://localhost:8290/api/stage -H 'Content-Type: application/json' -d '{"getData": {"p_season": ["winter"], "p_limit": 10, "p_offset": 0}}'
One reason for the issue is that the Payload you are sending is not a JSON or you are not sending the Content-Type: application/json
header. But I would assume if you are sending the incorrect content type it would fail before reaching the validate medaitor.该问题的一个原因是您发送的有效负载不是 JSON 或者您没有发送Content-Type: application/json
header。但我假设如果您发送的内容类型不正确,它会在到达验证之前失败调解员。 So my guess is that you are not sending any Payload with the request at all.所以我的猜测是您根本没有随请求发送任何有效负载。 Are you trying to test this with a GET request?您是否尝试使用 GET 请求对此进行测试? As per the code if you don't send a JSON payload it will go down the XML path which can cause the issue you are facing, hence make sure you send a valid JSON payload with your request.根据代码,如果您不发送 JSON 有效载荷,它将 go 沿着 XML 路径向下传输,这可能会导致您面临的问题,因此请确保您在请求中发送有效的 JSON 有效载荷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.