如何在 WSO2 中使用 JSON/XSD 验证器验证多种方法

How to validate Multiple Methods using JSON/XSD validator in WSO2

我需要在 WSO2 中验证传入的 JSON 请求结构我能够做到这一点,但是在同一上下文中有两种不同的方法 GET 和 POST,因此验证适用于方法,但我不需要验证 GET 方法。如何限制仅对一种方法进行验证。 我应用了过滤器但它不起作用有人可以帮助我如何实现这一目标。
工具:WSO2 API manger 2.6.0.

我正在尝试使用以下代码但无法发布。请帮我解决这个问题。

    <property name="Resource" expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
<property name="requestMethod" expression="get-property('axis2', 'HTTP_METHOD')"/>
<filter source="$ctx:Resource" regex="/books">
    <filter source="$ctx:requestMethod" regex="POST">
        <than>
            <validate>  
                <schema key="conf:/LocalBkStore.json"/>     
                    <on-fail>
                        <payloadFactory media-type="json">
                            <format>...</format>
                            <args>
                                <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
                            </args>
                        </payloadFactory>
                        <property name="HTTP_SC" value="500" scope="axis2"/>
                        <respond/>
                    </on-fail>      
            </validate>
        <than>      
    </filter>
</filter>

可以通过在 <apim-home>/repository/resources/customsequences/in 中添加自定义流入序列来实现,如下所示,

<sequence xmlns="http://ws.apache.org/ns/synapse"  name="detect_get_post">      
<property name="requestURL" expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
<property name="requestMethod" expression="get-property('axis2', 'HTTP_METHOD')"/>
<filter source="$ctx:requestURL" regex="/books">
    <then>
        <filter source="$ctx:requestMethod" regex="POST">
            <then>
                //POST request having the URL path /books and you can do the validation here
            </then>
        </filter>
    </then>
</filter>

您可以复制并粘贴上面的代码片段,并在我添加评论的地方添加验证部分。

在您添加的代码片段中,在第一个 filter 中介之后应该有一个 then 标签,并且第二个 then 标签中的拼写错误 filter调解员。