简体   繁体   中英

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.

ex: Say json fields {

"firstname": "abcd",

"eid" : "566",

"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.

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

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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