【问题标题】:How to extract Mulesoft JSON Schema Validator Errors?如何提取 Mulesoft JSON Schema Validator 错误?
【发布时间】:2018-03-15 20:02:42
【问题描述】:

在 Mulesoft 中使用“Validate JSON Schema”元素时,如果出现多个验证错误,则将以下消息放入#[exception]。

org.mule.api.MessagingException: Json content is not compliant with schema
com.github.fge.jsonschema.core.report.ListProcessingReport: failure
--- BEGIN MESSAGES ---
error: string "blah" is too long (length: 4, maximum allowed: 3)
    level: "error"
    schema: {"loadingURI":"file:/...}
    instance: {"pointer":"/blah_blah_code"}
    domain: "validation"
    keyword: "maxLength"
    value: "blah"
    found: 4
    maxLength: 3
error: string "USDe" is too long (length: 4, maximum allowed: 3)
    level: "error"
    schema: {"loadingURI":"file:/..."}
    instance: {"pointer":"/blah_code"}
    domain: "validation"
    keyword: "maxLength"
    value: "USDe"
    found: 4
    maxLength: 3
---  END MESSAGES  ---

有没有办法提取个别错误?

【问题讨论】:

    标签: json mule mule-component json-schema-validator


    【解决方案1】:

    您可以在 catch-exception-strategy 中使用 when 条件并为每个元素相应地设置有效负载

    下面是blah元素的例子

    <when expression="#[exception.causedBy(org.mule.api.MessagingException)&amp;&amp; exception.cause.message.contains('schema') &amp;&amp; exception.cause.message.contains('blah')]">
      <set-payload value="include element specification here" doc:name="Json schema validation error"/>
    </when>
    

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多