Apigee - modify target path when using targetserver

倾然丶 夕夏残阳落幕 提交于 2019-12-23 01:09:05

问题


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

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.

Dumping the values of targetRequest gives:

  1. host=empty
  2. path=/v2/cat1/cat2/?param=......
  3. url=Identical to path!

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 "?"

Thanks


回答1:


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>

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




回答2:


There seems to be an issue with manipulating target.path (there is a bug report open in Apigee for this).

The current workaround is to rewrite the entire URI either in the AssignMessage policy using the AssignVariable block:

<AssignVariable>
    <Name>target.url</Name>
    <Value>http://example.com/mypath?param=value&variable={apigee.variable}</Value>
    <Ref/>
</AssignVariable>

or you can do it in Javascript with the context.setVariable function:

context.setVariable("target.url", mycompleteurl);


来源:https://stackoverflow.com/questions/24702740/apigee-modify-target-path-when-using-targetserver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!