WSO2 API Manager v1.8.0

喜你入骨 提交于 2019-12-25 04:47:14

问题


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.


回答1:


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

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`


来源:https://stackoverflow.com/questions/28310484/wso2-api-manager-v1-8-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!