简体   繁体   English

验证对WSO2 ESB的请求

[英]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. 从外部源到wso2 esb(版本4.8.0)的请求具有字段数。 As a part of validation, we need to validate the mandatory fields in the wso2 before the processing of request. 作为验证的一部分,我们需要在处理请求之前验证wso2中的必填字段。 Could any one please tell me how and where (files) to validate these fields in wso2. 谁能告诉我在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. 其中id1,id2,id3和dateOfBirth是必填字段,当请求返回到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, 由于JSON有效负载在ESB内部被视为SOAP消息,因此您的请求有效负载可能是这样的,

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

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

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