我在WSO2 API管理器(1.10.0)中创建了一个API,其中包含以下信息:
员额:
/regularPath/* API URL:
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变量来捕获capture的1.0.0部分之后的路径(例如:regularPath/country/dataKey/amountOfUsers),然后将该值分配给uri.var.newRestVar变量。
接下来,是我在API管理器中创建的API管理器(碳)的修改后的服务总线配置:
...
<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,我应该更改什么配置?
发布于 2016-04-12 16:00:18
你可以在不修改突触配置的情况下做同样的事情。以下是步骤。希望这会是你的解决方案
创建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。
https://stackoverflow.com/questions/36560709
复制相似问题