简体   繁体   中英

WSO2 API Manager 1.9.1 - Routing

WSO2 API Manger中有什么方法可以从请求xml / json(有效负载)中读取参数值,并基于该值将请求路由到其他后端端点?

You can try using mediator extensions.

The API Manager has a default mediation flow for the API invocation requests that it receives. You can extend this default mediation flow to route the request.

  1. First write a sequence file to change the flow. Sample sequence as follows.
 <sequence xmlns="http://ws.apache.org/ns/synapse" name="YahooWeather2"> <property name="YQL" type="Expression" expression="concat('?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22',syn:get-property('uri.var.zipcode'),',',syn:get-property('uri.var.country'),'%22)format=json')"/> <property name="REST_URL_POSTFIX" type="Expression" expression="get-property('YQL')" scope="Axis2"/> </sequence> 
  1. To upload the sequence file to APIM, login as admin go to main-> Resources-> Browse
  2. Go to /_system/governance/apimgt/customsequences/in. from the tree view
  3. Click on Add Resource upload the sequence file you created.
  4. Login to API Publisher ,select the api and click on edit and go to Manage tab.
  5. Click on check box for Check to select a custom sequence to be executed in the message flow and in the In Flow dropdown select your sequence( in sample case YahooWeather2 ) and do Save & Publish .
  6. Login to API store and subscribe the api and generate an access token.

You can check availability from API Console in API store. for ferther details refer https://docs.wso2.com/display/AM191/Change+the+Default+Mediation+Flow+of+API+Requests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM