【问题标题】:Validation of request coming to WSO2 ESB验证进入 WSO2 ESB 的请求
【发布时间】:2016-06-07 02:36:48
【问题描述】:

来自外部源对 wso2 esb(版本 4.8.0)的请求具有多个字段。作为验证的一部分,我们需要在处理请求之前验证 wso2 中的必填字段。谁能告诉我如何以及在哪里(文件)在 wso2 中验证这些字段。

示例请求是:

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

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

其中 id1, id2, id3 和 dateOfBirth 是必填字段,当返回到 wso2 esb 时必须进行验证。

【问题讨论】:

  • 您需要将此请求视为 XML,然后再次使用验证调解器将这些字段作为必需字段的 xsd 架构。
  • 你能举个例子吗?我无法找到解决方案
  • 我收到 JSON 格式的请求。我们不维护任何 xsd 模式。有什么方法可以在没有 xsd 文件/模式的情况下进行验证。任何指针将不胜感激。
  • 您可以使用 JSON (github.com/ethlo/jsons2xsd) 创建 XSD 并尝试使用验证中介。

标签: json wso2 wso2esb esb


【解决方案1】:

您可以简单地使用一些过滤介体来做到这一点。

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

使用如下过滤中介来验证请求中所需的键/值。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多