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

时间:2017-02-16 02:27:44

标签: wso2 wso2-am

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

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

  1. HeaderSwapHandler
  2. APIInforHandler
  3. 在创建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>
    

    这可以解决我的问题。

1 个答案:

答案 0 :(得分:0)

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

相关问题