我在WSO2 API Manager(1.10.0)中创建了一个API,其中包含下一个信息:
POST:
/regularPath/*
API网址:
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网址如下所示:
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
变量来捕获API URL的1.0.0
部分之后的路径(例如:regularPath/country/dataKey/amountOfUsers
),然后将该值分配给uri.var.newRestVar
变量。
接下来,是我在API Manager中创建的API Manager(Carbon)的修改后的Service Bus配置:
...
<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,我应该更改哪些配置?
答案 0 :(得分:0)
您可以在不修改synapse配置的情况下执行相同的操作。以下是步骤。希望它能成为您的解决方案
按以下方式创建api
API context : api/{version}/regularPath
注意:您可以在上下文中将版本定义为AM 1.10中的模板。一旦定义了版本,上面的上下文就会得到版本
resources:
POST mainService/cityInfo
POST country/cityInfo
POST country/dataKey/amountOfUsers
POST main/city/data/users
HTTP Endpoint
http://<ip-address-2>:8181
之后你就可以打电话给后端了。无需向synapse配置添加自定义修改
http://<ip-address-2>:8181/country/dataKey/amountOfUsers
带
http://<ip-address-1>/t/tenant.com/api/1.0.0/regularPath/country/dataKey/amountOfUsers
其他信息
如果出现问题,您可以启用有线日志并检查网关中出入和退出的请求类型。请参阅http://mytecheye.blogspot.com/2013/09/wso2-esb-all-about-wire-logs.html,了解如何启用wirelog并使用它进行调试。