Apigee - 使用 targetserver 时修改目标路径 [英] Apigee - modify target path when using targetserver

查看:37
本文介绍了Apigee - 使用 targetserver 时修改目标路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 API 代理,需要能够修改最终目标 URL 的路径组件.如果为整个代理定义了目标端点 URL,但我们使用的是 TargetServers 和 VirtualHosts,这显然是在 TargetEndpoint PreFlow 之后分配的,这看起来相当简单

I have an API proxy that needs to be able to modify the path component of the eventual Target URL. This appears fairly straightforward in cases where there's a defined Target Endpoint URL for the entire proxy but we are using TargetServers and VirtualHosts which apparently are assigned after the TargetEndpoint PreFlow

我在目标端点 PreFlow 中有一个 JS 函数,当我尝试修改 context.targetRequest.path 时出现未指定的 JS 错误.在 Proxy PreFlow 期间尝试修改传入代理的路径部分也失败了.

I have a JS function in the Target Endpoint PreFlow and get unspecified JS errors when I attempt to modify context.targetRequest.path. Attempts to modify the path part of the incoming proxy during Proxy PreFlow also failed.

转储 targetRequest 的值给出:

Dumping the values of targetRequest gives:

  1. 主机=空
  2. path=/v2/cat1/cat2/?param=......
  3. url=与路径相同!

我能够成功"修改的唯一变量是 targetRequest.url 以实现我的目标,但要做到这一点,我必须分配整个内容,包括我不知道的协议和主机!

The only variable that I've been able to "successfully" modify is targetRequest.url to achieve my aim but to do that I must assign the whole thing, including the protocol and host which aren't known to me!

有人知道怎么做吗?我基本上想修改替换/?"的路径只有?"

Anyone know how to do this? I essentially want to modify the path replacing "/?" with just "?"

谢谢

推荐答案

您还可以通过利用 Path 元素和 TargetServer 在目标端点进行设置:

You can also set it up at the target endpoint by leveraging the Path element along with TargetServer:

<TargetEndpoint>
    ...
    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="TargetServerABC"/>
        </LoadBalancer>        
        <Path>/v1/YourPathHere/json.ws?{flow.company.queryparams}</Path>
    </HTTPTargetConnection>
</TargetEndpoint>

注意 TargetServerABC 需要是使用以下这些步骤创建的 TargetServer.

Note TargetServerABC needs to be a TargetServer created using the following these steps.

这篇关于Apigee - 使用 targetserver 时修改目标路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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