如何修改 WSO2 APIM 处理程序的顺序

How to modify the sequence of WSO2 APIM handler

我正在使用 WSO2 APIM 1.10.0 和我的自定义处理程序,这些处理程序被引用 here

我有 2 个全局自定义处理程序:

  1. HeaderSwapHandler
  2. APIInforHandler

我希望这两个自定义处理程序在 API 创建时按如下顺序排列。

<handlers>
  <handler class="com.wso2.header.handler.HeaderSwapHandler"/>
  <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
     <property name="apiImplementationType" value="ENDPOINT"/>
  </handler>
  <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
  <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
     <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
     <property name="policyKeyApplication"
               value="gov:/apimgt/applicationdata/app-tiers.xml"/>
     <property name="id" value="A"/>
     <property name="policyKeyResource"
               value="gov:/apimgt/applicationdata/res-tiers.xml"/>
  </handler>
  <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
  <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
     <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
  </handler>
  <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
  <handler class="com.wso2.header.handler.APIInforHandler"/>
</handlers>

HeaderSwapHandler 在处理程序的顶部,APIInforHandler 在处理程序的底部。

有什么办法吗?

编辑并解决

我原来的velocity_template.xml是这样的:

<handlers xmlns="http://ws.apache.org/ns/synapse">
<handler class="com.wso2.header.handler.HeaderSwapHandler"/>
<handler class="com.wso2.header.handler.APIInforHandler"/>
#foreach($handler in $handlers)
<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>
#end
</handlers>
        #end
        #end
        #if($apiStatus == 'PROTOTYPED')
        #end
        ## end of apiIsBlocked check
         <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
         <property name="inline" value="INLINE"/>
      </handler>
       </handlers>
        </api>

只需更改为:

<handlers xmlns="http://ws.apache.org/ns/synapse">
<handler class="com.wso2.header.handler.HeaderSwapHandler"/>
#foreach($handler in $handlers)
<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>
#end
<handler class="com.wso2.header.handler.APIInforHandler"/>
</handlers>
        #end
        #end
        #if($apiStatus == 'PROTOTYPED')
        #end
        ## end of apiIsBlocked check
         <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
         <property name="inline" value="INLINE"/>
      </handler>
       </handlers>
        </api>

这可以解决我的问题。

在您引用的同一页面中,它有 Engaging the custom handler 部分。它展示了如何使用 velocity_template.xml 让新的处理程序参与 API。