0

我有一个简单的用例,将 API 使用者的路径参数映射到后端 API 端点。我已经做了很多研究,但还没有找到关于如何做到这一点的具体答案。据我了解,如果不使用uri-template,就无法完成路径参数的映射。现在的问题是 API Manager 不支持来自 API Publisher 用户界面的 uri-template,您必须改用 url-mapping。WSO2 开发人员的一篇博客说,您可以转到单个突触配置并手动将其更改为 uri-template。但实际情况是,对 synapde 配置所做的更新以某种方式触发了数据库更新,否则会从发布者 UI 发生,最终结果是它不起作用。有人可以提供有关如何映射路径参数的方法吗?仅供参考 - 查询参数映射对我有用,因为它不需要 uri-template 并且可以使用 url-mapping 本身来实现。

4

1 回答 1

0

APIM 1.8 支持 uri-template 和 url-mapping。您可以在资源部分定义您的 url-template(或者如果您想要 uri-mapping)。请查看我添加了 url-template 和 url-mapping 的突触配置

在发布者中,我添加了 /json 作为 url 映射的 url 模式和 /json/{id} 用于 uri-template

    <?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
     name="admin--mytst"
     context="/mytest"
     version="1"
     version-type="url">
   <resource methods="GET" url-mapping="/json" faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <send>
                  <endpoint name="admin--mytst_APIproductionEndpoint_0">
                     <http uri-template="http://localhost.com"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
   <resource methods="GET" uri-template="/json/{id}" faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <send>
                  <endpoint name="admin--mytst_APIproductionEndpoint_1">
                     <http uri-template="http://localhost.com"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
   <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
         <property name="id" value="A"/>
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
         <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
   </handlers>
</api>`enter code here`
于 2015-02-26T09:32:16.300 回答