首页 文章

WSO2 API Gateway在运行时更改服务HTTP endpoints

提问于
浏览
0

我使用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

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

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

而不是预期的:

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

我验证了API的synapse配置,并按照定义正确捕获了 endpoints . 后端 endpoints 会自动更改什么?怎么可以避免?

1 回答

  • 1

    您使用的是什么版本的Api经理?如果它是API管理器1.10,那么对于默认的http endpoints ,您将收到这样的后端请求

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

    当请求从api管理器发出时,默认行为是将资源路径附加到后端 endpoints

    例如:如果 endpoints 是http://test.com/abc并且api有一个定义为/ testresource / 123的资源,那么请求将是http://test.com/abc/testresource/123到具有默认 endpoints 类型(HTTP endpoints )的后端

    如果要在不将资源附加到请求的情况下调用后端,可以将以下属性添加到synapse配置中 .

    <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

相关问题