2016-04-11 24 views
0

我已经创造了WSO2 API管理器(1.10.0)与下一个信息的API:动态替换端点的路径值(WSO2 - 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管理器(碳)的修改服务总线配置:

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

但它不工作。我查了日志,但似乎一切都OK:

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端点的?

回答

0

您可以在不修改突触配置的情况下做同样的事情。以下是步骤。希望这将是一个为你解决

如下

API context : api/{version}/regularPath 

注创建API:您可以定义在上下文中使用的版本为1.10 AM的模板。一旦你定义版本,上面的上下文将获得版本

resources: 
POST mainService/cityInfo 
POST country/cityInfo 
POST country/dataKey/amountOfUsers 
POST main/city/data/users 

HTTP Endpoint 
http://<ip-address-2>:8181 

之后,你将能够调用后端。无需自定义修改添加到突触配置

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关于如何启用接线和使用它进行调试。