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