且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ESB中的有效负载验证

更新时间:2023-11-29 13:47:04

我做了一个小样本来演示json验证程序的工作原理.您可以使用相同的

i did a small sample to demonstrate how json validator works. you can use the same

  1. 转到 https://jsonschema.net/或任何在线json模式生成器,并为您的json模式生成json文件.
  2. 将此模式同样放入扩展名为.json的文件中,并将其放置在src/main/resources文件夹中.
  3. 实施模式验证并引用您的模式,传入的json将自动针对该模式进行验证,因此您不必使用任何分散收集或每个单独的键值对验证.
  1. go to https://jsonschema.net/ or any online json schema generator and generate json schema for your json file.
  2. same this schema into a file with .json extension and place it in src/main/resources folder.
  3. implement the schema validate and refer to your schema and your incoming json will get validated against the schema automatically so you dont have to use any of the scatter-gather or each individual key-value pair validations.

这是一些针对我的流程使用不同json输入的响应

here are some of the responses with different json inputs against my flow

您始终可以根据自己的需要来增强架构.您可以为每个键定义数据类型.假设key3应该只包含数字值,key2应该是一个数组.诸如此类的任何事情都可以通过修改架构来实现,验证器将相应地验证传入的json.

you can always enhance your schema to suite your needs. you can define data type for each key. lets say key3 should contain only numeric values, key2 should be an array. anything like that all can be achieved by modifying your schema and the validator will validate the incoming json accordingly.

更新: 这是the子流的xml内容

update: here is the xml content of the mule flow

<flow name="***Flow1" doc:id="c24d34aa-ce1d-4bbb-b3fd-d73007dad60b" >
        <http:listener doc:name="Listener" doc:id="80ab5db5-1d3e-409f-9990-cebf1fc07dd5" config-ref="HTTP_Listener_config" path="/valid"/>
        <json:validate-schema doc:name="Validate schema" doc:id="0a51cde0-5175-4f11-b972-3d5d708094c6" schema="schema.json"/>
        <logger level="INFO" doc:name="Logger" doc:id="2d95a6f0-8f88-4608-bdb8-7fae8abc0e6d" message="valid json"/>
    </flow>