简体   繁体   English

一次验证JSON请求,而不是在WSO2 ESB中一一验证

[英]Validating JSON request at at time instead of one by one in WSO2 ESB

My Requirement is to Validate the JSON iNPUT Request at a time instead of one by one. 我的要求是一次验证JSON iNPUT请求,而不是一次一次。

ex: Say json fields { 例如:说json字段{

"firstname": "abcd", “ firstname”:“ abcd”,

"eid" : "566", “ eid”:“ 566”,

"zip" : "698" “ zip”:“ 698”

} }

ASSUME all my fields are wrong when i pass the request it should throw only firstname element , i need to throw all the three elements error at a time in wso2 esb, thank in advance. ASSUME我的所有字段都错误,当我传递请求时,它应该只抛出firstname元素,我需要一次在wso2 esb中抛出所有三个元素错误,在此先感谢。

you can create appropriate XSD schema for your message and use Validate mediator, or you can create property for error message and concat all the error messages you need, like 您可以为消息创建适当的XSD架构并使用Validate中介器,也可以为错误消息创建属性并合并所需的所有错误消息,例如

<property name="error" expression=""/>
<filter source="json-eval($.firstname)" regex="...your condition on first name">
   <then>
<property name="error" value="firstname is not valid!"/>
   </then>
   <else> 
   </else>
</filter>
<property name="error" expression=""/>
<filter source="json-eval($.eid)" regex="...your condition on eid">
   <then>
<property name="error" expression="fn:concat(get-property('error'),' eid is not valid!')"/>
   </then>
   <else> 
   </else>
</filter>
<filter source="json-eval($.zip)" regex="...your condition on eid">
   <then>
<property name="error" expression="fn:concat(get-property('error'),' zip is not valid!')"/>
   </then>
   <else> 
   </else>
</filter>
<filter source="get-property('error')" regex="^$">
   <then>

    ...sending error...

   </then>
   <else> 
   </else>
</filter>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM