简体   繁体   English

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

[英]How to modify the sequence of WSO2 APIM handler

I am using WSO2 APIM 1.10.0 with my custom handlers which are referenced here . 我正在使用WSO2 APIM 1.10.0和我在这里引用的自定义处理程序。

I have 2 global custom handlers: 我有2个全局自定义处理程序:

  1. HeaderSwapHandler HeaderSwapHandler
  2. APIInforHandler APIInforHandler

And I want these two custom handlers sequence as follows when the API created. 在创建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 on the top and APIInforHandler on the bottom of the handlers. HeaderSwapHandler顶部和APIInforHandler在处理器的底部。

Is there any way to do that? 有没有办法做到这一点?

Edit and Solved 编辑和解决

My original velocity_template.xml is like: 我原来的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>

Just change to: 只需改为:

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

That could solve my problem. 这可以解决我的问题。

In the same page that you are referring, it has Engaging the custom handler section. 在您引用的同一页面中,它具有Engaging the custom handler部分。 It shows how you can use velocity_template.xml to engage your new handler to APIs. 它显示了如何使用velocity_template.xml将新处理程序引用到API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM