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



我有一个自定义处理程序,它应该只应用于一组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属性选择性地应用handers。看看我在添加自定义处理程序到特定的API wso2 API-Manager 中的答案

例如。

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

最新更新