WSO2 APIM Custom sequences for non published APIs / Setting variable

旧时模样 提交于 2019-12-24 23:26:49

问题


We have defined a default custom sequence for managing different gateways, as described here

We have installed the sequence as explained in the doc Creating Global Conection

The sequence only read 2 variables from environment, and uses to build the endpoint URL. This is the code:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
        <property name="uri.var.host" expression="get-property('system','host')" />
        <property name="uri.var.port" expression="get-property('system','port')" />
</sequence>

This is working fine with Published API, but if we degrade the API to prototype (for using directly without subscription), it doesn't work.

We have tried:

  • To install it as a Message Mediaton Policy at API level

  • Setting the parameter in the /repository/resources/api_templates/prototype_template.xml In sequence

The error when we test reports empty host name (as it tries to read the variable, and it's empty)

Do you know how to set environment variables in prototyped environment?


回答1:


When the API is deployed in "Prototype Endpoint" uses the velocity_template.xml for creating the API implementation.

This template generate different code for PROTOTYPE and PUBLISHED APIs.

I have forced to include the APIManagerExtensionHandler (which is the handler processing the Custom Extension Sequence), adding the following in velocity template (after the handler adding loop).

patch --forward $WSO2_PATH/$1/repository/resources/api_templates/velocity_template.xml <<EOF
*** velocity_template.xml   2018-06-02 11:04:42.474476581 +0200
--- velocity_template.xml.patched   2018-06-02 11:07:28.495395384 +0200
***************
*** 361,366 ****
--- 361,369 ----
      #end
  </handler>
  #end
+ #if(\$apiStatus == 'PROTOTYPED')
+ <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
+ #end
  </handlers>
          #end
          #end
EOF


来源:https://stackoverflow.com/questions/50624765/wso2-apim-custom-sequences-for-non-published-apis-setting-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!