Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将WSO2自定义处理程序仅应用于某些API?_Wso2_Wso2 Am - Fatal编程技术网

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

如何将WSO2自定义处理程序仅应用于某些API?,wso2,wso2-am,Wso2,Wso2 Am,我有一个自定义处理程序,它应该只应用于一组API。我已经看到编辑/repository/resources/api\u templates/velocity\u template.xml会将更改应用于所有api。是否有一种自动分配方法,但只分配给API的一个子集 更新:我的wso2 api管理版本是2.6.0。我正在检查应用程序类型属性,但它不起作用: <handlers> #if($apiObj.additionalProperties.get('application_type'

我有一个自定义处理程序,它应该只应用于一组API。我已经看到编辑
/repository/resources/api\u templates/velocity\u template.xml
会将更改应用于所有api。是否有一种自动分配方法,但只分配给API的一个子集

更新:我的wso2 api管理版本是2.6.0。我正在检查应用程序类型属性,但它不起作用:

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

#if($apiObj.additionalProperties.get('application\u type')==“whatener”)
#结束
如果正确打印处理程序,则删除块


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

您可以根据API属性有选择地应用handers。请看我的答案

例如


#foreach($handlers中的$handlers)
#如果($handler.className==
“org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler”)&&
($apiObj.additionalProperties.get('auth_mode')=“内部”))
#if($handler.hasProperties())
#set($map=$handler.getProperties())
#foreach($map.entrySet()中的属性)
#结束
#结束

Hi Bee,你能检查一下更新的问题吗?由于某些原因,if块不起作用:
#if($apiObj.additionalProperties.get('application\u type')==“whatever”)
<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>