0
votes

I am trying to implement WSO2 API Manager to handle calls to an API endpoint and do some mediation on the response. I have added an API in the publisher, set a http endpoint to the remote API and implemented some mediators. Everything is working just fine. I have the following mapping: {context}/{version}/RetrieveResource/{resourceid} -> {api server}/RetrieveResource/{resourceid}

Now I want to change the mapping like so: {context}/{version}/Resource/{resourceid} -> {api server}/RetrieveResource/{resourceid}

So I would like that my WSO2 api has the path /Resource/1 that calls the remote api /RetrieveResource/1. Therefore I have tried to use a rewrite mediator in my in-sequence. This changes my "To" header, but does not call the right endpoint path. I call Resource/1, I mediate it to RetrieveResource/1, but WSO2 still calls the endpoint as Resource/1 which ofcourse gives me a 404.

My mediator looks as follows:

<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>

I am clearly missing something, any help would be greatly appreciated.

2

2 Answers

2
votes

I have found the following solution after a lot of trail and error. Maybe this can help someone in the future.

<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"/>
0
votes

In a similar situation in 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