2

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

John
  • 23
  • 1
  • 3

2 Answers2

2

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.

Diego
  • 1,678
  • 1
  • 16
  • 20
  • Thanks Diego, this got me to the solution. I placed the adjusted value of proxy.pathsuffix (the var I wanted modified in the 1st place) into my own variable and applied that to the 'Path' in the TargetServer as you suggested. Also critical was setting `target.copy.pathsuffix = false` to prevent the original (bad) pathsuffix from also being applied. – John Jul 11 '14 at 20:19
0

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);
Michael Bissell
  • 1,210
  • 1
  • 8
  • 14
  • 1
    I appreciate the response but I noted that I can assign the complete URL but that's not a workable solution given the presence of TargetServers/VirtualHosts – John Jul 11 '14 at 17:51