WSO2 API 网关在运行时更改服务 HTTP 端点

WSO2 API Gateway changing the service HTTP endpoint at runtime

我使用 WSO2 Publisher 应用程序创建并发布了具有以下配置的 API:

Context = a
Version = v1.0
URL Pattern: /b/{bId}/c/{cId}
HTTP Verb: GET
Endpoint Type: HTTP Endpoint
Production Endpoint: http://backendserver:port/services/rest/GetXYZ

在我订阅了 API 的商店中,生成了一个应用程序令牌并使用以下 URL:

调用了 API
https://gatewayserver:port/a/v1.0/b/123/c/456

但是,当网关调用后端服务时,它会以某种方式自动将端点更改为以下内容:

http://backendserver:port/services/rest/456

而不是预期的:

http://backendserver:port/services/rest/GetXYZ

我验证了 API 的突触配置,它按照定义正确捕获了端点。什么会自动更改后端端点?如何避免?

您使用的是哪个版本的 Api 管理器?如果它是 API 管理器 1.10,您将收到这样的后端请求,用于默认 http 端点

GET /services/rest/GetXYZ/b/123/c/456

当请求从 api 管理器

发出时,默认行为是将资源路径附加到后端端点

ex:如果端点是 http://test.com/abc and api has a resource defined as /testresource/123 then the request would be http://test.com/abc/testresource/123 到具有默认端点类型(HTTP 端点)的后端

如果你想调用后端而不向请求附加资源,你可以在突触配置中添加以下属性。

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

您可以使用 API 管理器中提供的中介扩展功能来执行此操作。看 https://docs.wso2.com/display/AM1100/Adding+Mediation+Extensions

以下是示例扩展文件

<sequence xmlns="http://ws.apache.org/ns/synapse" name="removeresource">
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
</sequence>

上传此文件,然后将其导入 api 中的 'IN flow' 序列。参见 https://docs.wso2.com/display/AM1100/Change+the+Default+Mediation+Flow+of+API+Requests