WSO2 APIM非发布API /设置变量的自定义序列

时间:2018-05-31 12:49:51

标签: wso2 sequence wso2-am mediator

我们已经定义了一个默认的自定义序列来管理不同的网关,如here

所述

我们按照doc Creating Global Conection

中的说明安装了序列

序列只读取环境中的2个变量,并用于构建端点URL。这是代码:

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

这适用于已发布的API,但如果我们将API降级为原型(直接使用而无需订阅),它就无法正常工作。

我们尝试过:

  • 将其安装为API级别的Message Mediaton策略

  • 在中设置参数 /repository/resources/api_templates/prototype_template.xml 序列

我们测试报告空主机名时的错误(因为它试图读取变量,并且它是空的)

您知道如何在原型环境中设置环境变量吗?

1 个答案:

答案 0 :(得分:1)

在&#34; Prototype Endpoint&#34;中部署API时使用velocity_template.xml创建API实现。

此模板为PROTOTYPE和PUBLISHED API生成不同的代码。

我不得不包含APIManagerExtensionHandler(处理自定义扩展序列的处理程序),在velocity模板中添加以下内容(在处理程序添加循环之后)。

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
相关问题