WSO2 API管理器v1.8.0 [英] WSO2 API Manager v1.8.0

查看:110
本文介绍了WSO2 API管理器v1.8.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple use case of mapping path param from the API consumer to the backend API endpoint. I have done a lot of research but have not found out the specific answer on how to do that. As per my understanding, thr mapping of the path parameter can't be done without the use of uri-template. Now the problem is that the API Manager does not support uri-template from the API Publisher user interface and you have to use url-mapping instead. One blog from WSO2 developer says that you can then go to the individual synapse config and change that to uri-template manually. But what is happening in pratice is that the updates made to the synapde config somehow triggers the database update that would happen from the publisher UI otherwise and the end result is that it does not work. Can someone please provide the way forward on how the path param can be mapped? FYI - the query parameter mapping is working for me since that does not need uri-template and can be implemented using url-mapping itself.

推荐答案

APIM 1.8同时支持uri-template和url-mapping.您可以在资源部分下定义url-template(如果需要uri-mapping).请参阅我在其中添加了url-template和url-mapping的synapse配置

APIM 1.8 support both uri-template and url-mapping.You can define your url-template(or if you want uri-mapping) under resource section. please see the synapse config where i have added url-template and a url-mapping

在发布商中,我为URL映射添加了/json作为URL模式,对于uri模板添加了/json/{id}

in publisher I added /json as url pattern for url-mapping and /json/{id} for 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`

这篇关于WSO2 API管理器v1.8.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆