如何将 WSO2 自定义处理程序仅应用于某些 API?

How can I apply a WSO2 custom handler only to some APIs?

我有一个只能应用于一组 API 的自定义处理程序。我已经看到编辑 <APIM_HOME>/repository/resources/api_templates/velocity_template.xml 会将更改应用到所有 API。有没有一种自动分配它的方法,但只分配给 API 的一个子集?

更新: 我的 wso2 api 管理版本是 2.6.0。我正在检查 application_type 属性 但它不起作用:

<handlers>
#if($apiObj.additionalProperties.get('application_type') == "whatener")
    <handler class="com.codependent.MyCustomHandler"/>
#end
</handlers>

删除 if 块正确打印处理程序。

那么如何访问 API 属性来检查条件?

您可以根据 API 属性有选择地应用处理程序。看看我在

中的回答

例如。

<Handlers>
    #foreach($handler in $handlers)
        #if(($handler.className ==
"org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler") &&
($apiObj.additionalProperties.get('auth_mode') == "Inhouse"))
            <handler xmlns="http://ws.apache.org/ns/synapse" class="$handler.className">
            #if($handler.hasProperties())
                #set ($map = $handler.getProperties())
                #foreach($property in $map.entrySet())
                    <property name="$!property.key" value="$!property.value"/>
                #end
            #end
            </handler>
            <handler class="org.wso2.apim.custom.extensions.CustomAuthHandler"/>
<Handlers>