WSO2 API 管理器 - 替换响应正文中的 URL [英] WSO2 API Manager - Replace URLs in response body

查看:55
本文介绍了WSO2 API 管理器 - 替换响应正文中的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 WSO2 API 管理器为我的 RESTful API 设置代理.我的问题是来自后端 API 的响应保持不变,因此连接到其他端点的所有 url 仍然引用后端服务器而不是代理.我需要一种方法来替换响应正文中的那些 url 值以指向代理的 api.我知道这可以通过 中介扩展来完成,使用 ESB 中介.

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.

我对他们不够熟悉,无法选择更适合这份工作的人.URLRewrite 中介看起来很简单,但它似乎不适用于消息正文但标题.Payload Factory 好像需要固定的消息结构,不是很方便对我来说,因为我需要它来处理我的 API 提供的不同响应(我不想在中介定义中维护这些结构).

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

推荐答案

我设法通过设置我的应用程序检查的标题来解决它以构建其 url:X-Forwarded-Host 和 <代码>X-Forwarded-Proto.

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

所以我创建了一个如下所示的 Header Mediator:

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>

这就成功了.

这篇关于WSO2 API 管理器 - 替换响应正文中的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆