WSO2 AM HTTP 端点重写 url

WSO2 AM HTTP Endpoint rewrite url

我正在尝试实施 WSO2 API 管理器来处理对 API 端点的调用并对响应进行一些调解。我在发布者中添加了一个 API,将一个 http 端点设置为远程 API 并实现了一些调解器。一切正常。 我有以下映射: {context}/{version}/RetrieveResource/{resourceid} -> {api server}/RetrieveResource/{resourceid}

现在我想像这样更改映射: {context}/{version}/Resource/{resourceid} -> {api server}/RetrieveResource/{resourceid}

所以我希望我的 WSO2 api 具有调用远程 api /RetrieveResource/1 的路径 /Resource/1。因此,我尝试在 in-sequence 中使用重写调解器。这改变了我的 "To" header,但没有调用正确的端点路径。我调用 Resource/1,我将其调解为 RetrieveResource/1,但 WSO2 仍将端点称为 Resource/1,这当然给了我 404.

我的调解员长这样:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="custom_in">
    <property name="WSO2_AM_API_ACCEPT_MESSAGE_TYPE" expression="get-property('transport', 'Accept')" scope="default"/>
    <property name="Accept" scope="transport" action="remove"/>

    <rewrite xmlns="http://ws.apache.org/ns/synapse">
        <rewriterule>
            <action value="RetrieveResource" regex="Resource" type="replace" fragment="path"/>
        </rewriterule>
    </rewrite>

</sequence>

我显然遗漏了一些东西,我们将不胜感激。

WSO2 API Cloud, I used Property mediator to set the new value to REST_URL_POSTFIX as described in this tutorial: https://docs.wso2.com/display/APICloud/Change+the+Default+Mediation+Flow+of+API+Requests

中有类似情况

经过反复试验,我找到了以下解决方案。也许这对以后的人有帮助。

<property name="querystrings" expression="get-property('To')"/>

<rewrite outProperty="querystrings" xmlns="http://ws.apache.org/ns/synapse">
    <rewriterule>
        <action value="<what you want>" regex="<what you have>" type="replace" fragment="path"/>
    </rewriterule>
</rewrite>

<property name="REST_URL_POSTFIX"
                expression="get-property('querystrings')"
                scope="axis2"/>