WSO2 API Manager - Replace URLs in response body

2019-08-11 02:40发布

I'm trying to setup a proxy for my RESTful API using WSO2 API Manager. My problem is that the responses from the backend API are left untouched so all the urls that connect to other endpoints still reference the backend server rather than the proxy. I need a way to replace those url values in the response body to point to the proxied api. I understand this can be accomplished via Mediation Extensions, using ESB Mediators.

I'm not familiar enough with them to pick the one better suited for the job. URLRewrite mediator looks pretty straightforward, but it doesn't seem to apply to the message body but the headers. Payload Factory seems to require a fixed structure for the message, which is not very convenient for me, since I need it to work on the different responses that my API provides (and I wouldn't want to maintain those structures in the mediator definition).

1条回答
The star\"
2楼-- · 2019-08-11 02:59

I've managed to solve it by setting the headers my application checks to build its urls:X-Forwarded-Host and X-Forwarded-Proto.

So I've created a Header Mediator that looks like:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
    <header name="X-Forwarded-Host" expression="get-property('transport','Host')" scope="transport"/>
    <header name="X-Forwarded-Proto" value="https" scope="transport"/>
</sequence>

And that did the trick.

查看更多
登录 后发表回答