ESB中的有效负载验证 [英] Validation of Payload in ESB

查看:119
本文介绍了ESB中的有效负载验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTTP POST请求,该请求发送如下的有效负载:

I have a HTTP POST REQUEST which sends a payload as follows:

{"key1":"value1","key2":"value2","key3":"value3"}

{ "key1" : "value1", "key2" : "value2" ,"key3": "value3" }

我能够验证所有值,但每次都必须使用一个组件. 在这种情况下,我使用了验证程序"Not a blank string" 3次.

I was able to validate all the values but I had to use a component everytime. In this case , I used the validator "Not a blank string" 3 times.

1. Is there any way that I can validate all the three values in a single validator ? 
 2. Should I use Scatter-Gather for validating all the values in parallel(according to best-practices) ?
 3. How can I validate the key set(the key set should only contain "key1", "key2" and "key3"  ?

更新: 我已经通过使用连接器setVariable来获取密钥集

Update: I have fetched the key set by using the connector setVariable

JSON验证程序可以从交易所下载.搜索JSON模块

推荐答案

我做了一个小样本来演示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="stackoverflowFlow1" 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>

这篇关于ESB中的有效负载验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆