1

精简版。我正在尝试创建一个 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/(\d+.*)/goals/goal/$1?我知道我可以通过代理路由它并在 apache 中重写它或但这似乎违背了 WSO2 对我的目的。

4

1 回答 1

0

因此,在没有成功地进行更多研究并且没有得到任何回应之后,我只是盯着代码可以想出......

 <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>
于 2014-08-19T18:52:16.437 回答