我在 WSO2 API Manager (1.10.0) 中创建了一个 API,其中包含以下信息:
邮政:
/regularPath/*
接口网址:
http://<ip-address-1>/t/tenant.com/api/1.0.0/
HTTP端点:
http://<ip-address-2>:8181/{uri.var.newRestVar}
问题是 HTTP 端点有多个路径,例如:
http://<ip-address-2>:8181/mainService/cityInfo
http://<ip-address-2>:8181/country/cityInfo
http://<ip-address-2>:8181/country/dataKey/amountOfUsers
http://<ip-address-2>:8181/main/city/data/users
我希望生成的 API URL 看起来像这样:
http://<ip-address-1>/t/tenant.com/api/1.0.0/regularPath/mainService/cityInfo
http://<ip-address-1>/t/tenant.com/api/1.0.0/regularPath/country/cityInfo
http://<ip-address-1>/t/tenant.com/api/1.0.0/regularPath/country/dataKey/amountOfUsers
http://<ip-address-1>/t/tenant.com/api/1.0.0/regularPath/main/city/data/users
我最初的方法是使用REST_URL_PREFIX
变量来捕获1.0.0
API URL 部分之后的路径(例如:)regularPath/country/dataKey/amountOfUsers
,然后将该值分配给uri.var.newRestVar
变量。
接下来是我在 API Manager 中创建的 API Manager (Carbon) 的修改后的服务总线配置:
...
<inSequence>
<filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
<then>
<property expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
<log>
<property expression="$trp:To" name="ToURL"/>
</log>
<property expression="$axis2:REST_URL_POSTFIX" name="restURL" scope="default" type="STRING"/>
<log>
<property
expression="get-property('restURL')" name="logRestURL"/>
</log>
<script description="JS" language="js">
<![CDATA[
var unmodifiedRestPostfix = new String(mc.getProperty("restURL"));
print("value = " + unmodifiedRestPostfix);
unmodifiedRestPostfix = unmodifiedRestPostfix.replace("/regularPath/", "");
mc.setProperty("uri.var.newRestVar", unmodifiedRestPostfix);
]]>
</script>
<log>
<property expression="get-property('uri.var.newRestVar')" name="URI_VAR_NEWRESTVAR"/>
</log>
<send>
<endpoint name="admin-AT-tenant.com--API-Main_APIproductionEndpoint_0">
<http uri-template="http://<ip-address-2>:8181/{uri.var.newRestVar}"/>
</endpoint>
</send>
...
但它不起作用。我检查了日志,但一切似乎都很好:
TID: [35] [] [2016-04-11 16:47:01,955] @bank.com [35] [AM] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: local://axis2services/api/1.0.0/regularPath/mainService/cityInfo, MessageID: urn:uuid:091613ce-9fd3-4094-8638-5b112
a4214ad, Direction: request, logRestURL = /regularPath/mainService/cityInfo {org.apache.synapse.mediators.builtin.LogMediator}
a4214ad, Direction: request, URI_VAR_NEWRESTVAR = /regularPath/mainService/cityInfo {org.apache.synapse.mediators.builtin.LogMediator}
为了使用我提到的 API 的路径成功访问 HTTP-Endpoint,我应该更改什么配置?