【问题标题】:Complex routing WSO2 API resourse uri template复杂路由 WSO2 API 资源 uri 模板
【发布时间】:2014-08-20 02:52:16
【问题描述】:

短版。 我正在尝试创建一个 API 来处理

/goals/risks
/goals/types
/goals/{goalID}

到目前为止,这就是我所拥有的,但并不是我想要的。因为它给了我 /goals/goal/{goalId}

<api xmlns="http://ws.apache.org/ns/synapse" name="GoalAPI" context="/goals">
  <resource methods="GET" uri-template="/risks" faultSequence="ReturnError">...</resource>
  <resource methods="GET" uri-template="/types" faultSequence="ReturnError">...</resource>
  <resource methods="GET" uri-template="/goal/{goalId}" faultSequence="ReturnError">...</resource>
</api>

GoalID 将始终与/^\d+$/ 匹配,因此如果我可以通过它以某种方式进行路由,它将起作用。最终我还想添加/goals/{goalID}/item and /goals/{goalID}/items/{itemID},但我相信一旦我弄清楚第一步,这将很容易。

如果这里没有办法做到这一点,有没有办法可以在 wso2 中的 url 到达资源之前重写它,然后我可以用 /goals/goal/$1? 替换 /goals/(\d+.*) 我知道我可以路由它虽然是代理并用 apache 或其他东西重写它,但这似乎违背了 WSO2 对我的目的。

【问题讨论】:

    标签: url-rewriting wso2 url-routing wso2esb uritemplate


    【解决方案1】:

    因此,在没有成功但没有得到任何回应之后,我只是盯着代码可以想出...

     <api xmlns="http://ws.apache.org/ns/synapse" name="GoalAPI" context="/goals">
       <resource methods="GET" uri-template="/{goalID}" faultSequence="ReturnError">
          <inSequence>
            <switch source="get-property('uri.var.goalId')">
              <case regex="risks">...</case>
              <case regex="types">...</case>
              <default>...Handle the ID here...</default>
            </switch>
          </inSequence>
          ...
       </resource>
     </api>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2019-07-03
      相关资源
      最近更新 更多