简体   繁体   中英

Validation of request coming to WSO2 ESB

The request coming from an external source to wso2 esb (version 4.8.0) has number of fields. As a part of validation, we need to validate the mandatory fields in the wso2 before the processing of request. Could any one please tell me how and where (files) to validate these fields in wso2.

The sample request is :

{
    "name" : "abc",
    "studentId" : {
        "id1" : "testid",
        "id2" : "11234",
        "id3" : "6781"
    },

"details" : [
        {
            "dateOfBirth" : "01-01-2016"
}]

Where id1, id2, id3 and dateOfBirth are the mandatory fields which must be validated when the resuest comes to wso2 esb.

You can simply do this using some filter mediators.

Since JSON payload treated as a SOAP message inside ESB your request payload maybe like this,

 <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <jsonObject>
         <name>abc</name>
         <studentId>
            <id1>testid</id1>
            <id2>testid</id2>
            <id3>testid</id3>
         </studentId>
         <details>
            <dateOfBirth>01-01-2016</dateOfBirth>
         </details>
         <details>
            <dateOfBirth>01-01-2012</dateOfBirth>
         </details>
     </jsonObject>
 </soapenv:Body>

Use filter mediators as follows to validate required keys/values in request.

 <!-- xPath boolean() function may evaluate to false if value of id1 is empty/null or request doesn't have that key. --> 
 <filter regex="false" source="boolean(//jsonObject/studentId/id1)">
     <then>
     <!-- Generate Error message for id1-->
     </then>
     <else>
        <filter regex="false" source="boolean(//jsonObject/studentId/id2)">
            <then>
            <!-- Generate Error message for id2-->
            </then>
            <else>
                <!-- more filters -->
            </else>
        </filter>
     </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