Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

LocalTargetConnection is not setting proxy.pathsuffix variable to execute Route-Rule

proxy-chaining-1-rev1-2018-05-31.zip

proxy-chaining-2-rev1-2018-05-31.zip

Hi,

I wanted to implement proxy chaining using service-callout OR as a target end-point using

<LocalTargetConnection> </LocalTargetConnection>

I have conditional Route-Rule and wanted to execute conditional route-rule (hello-mock). attached the proxies .

1) approach-1

 <LocalTargetConnection>
        <APIProxy>proxy-chaining-2</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
 </LocalTargetConnection>

it calls default flow and default Route-Rule. To call my hello-mock route, see below -

2) When I use

<LocalTargetConnection>
        <Path>/v1/apis/proxychaning2/helloapi</Path>
</LocalTargetConnection>

it calls my expected Route-Rule (hello-mock) and got the expected response, But issue is here, I am hardcoding URL including version and basepath. I do not want to hardcoded here version and basepath URL because version might change later. Hence I tried below approach but it is not working

3) I tried 3 approach , But in that I am not getting proxy.pathsuffix as a '/helloapi' hence it is not calling my expected Route-Rule. Can someone have fix of this issue, how I can pass the proxy.pathsuffix ?

 <LocalTargetConnection>
        <APIProxy>proxy-chaining-2</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
        <Path>/helloapi</Path>
 </LocalTargetConnection>
Solved Solved
1 7 1,230
1 ACCEPTED SOLUTION

You can try something like this:

<TargetEndpoint name="chain">
    <PreFlow name="PreFlow">
      <Request>
        <Step>
          <Name>JS-SetTargetUrl</Name>
        </Step>
      </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <LocalTargetConnection>
        <Path>/required-but-not-used</Path>
    </LocalTargetConnection>
</TargetEndpoint>

The policy JS-SetTargetUrl should be like so:

var schemeAndHostForLocalConnection = 'http://localhost:8998';
var myDesiredUrlpath = context.getVariable(variableContainingDesiredPath); 
context.setVariable('target.url', schemeAndHostForLocalConnection + myDesiredUrlpath);

The variable containing the path can be set via KVM or some other mechanism. Thus not "hard coded".

Alternatively, as of November 2018 you can use an AssignMessage for setting this variable. like this:

<AssignMessage name='AV-SetLocalTargetPath'>
  <AssignVariable> 
    <Name>target.url</Name>
    <Template>http://localhost:8998{variableContainingDesiredPath}</Template>
  <AssignVariable>
</AssignMessage>

Unfortunately today, I believe it is not possible to specify a proxy name and endpoint AND a path.

View solution in original post

7 REPLIES 7
Top Solution Authors