[英]WSO2 - Micro-integrator - Connects to Dashboard , but no instances found
[英]wso2 micro integrator fails to validate with json schema
我正在嘗試在 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。
如果我嘗試遵循這個關於使用本地條目而不是注冊表的答案
<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
編輯請求:
curl -v http://localhost:8290/api/stage -H 'Content-Type: application/json' -d '{"getData": {"p_season": ["winter"], "p_limit": 10, "p_offset": 0}}'
該問題的一個原因是您發送的有效負載不是 JSON 或者您沒有發送Content-Type: application/json
header。但我假設如果您發送的內容類型不正確,它會在到達驗證之前失敗調解員。 所以我的猜測是您根本沒有隨請求發送任何有效負載。 您是否嘗試使用 GET 請求對此進行測試? 根據代碼,如果您不發送 JSON 有效載荷,它將 go 沿着 XML 路徑向下傳輸,這可能會導致您面臨的問題,因此請確保您在請求中發送有效的 JSON 有效載荷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.