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

ssisodiya
Participant III

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,091
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

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.

Thanks for reply .
Yes, we can do via js script but I thought of doing via <LocalTargetConnection>, But as per your comment it is not possible currently.

you CAN use a LocalTargetConnection. But you cannot specify the path in the Path element. You need to use that workaround.

It shoud work with ServiceCallout or only with TargetEndpoint?

Hi

I'm not clear on your question. What do you mean by "it" ? If you want to dynamically set the URL for a ServiceCallout, check this answer.

If that's not it, Maybe you can ask a new question. Your question seems to be related but not the same as this question.

Hi,

i need to use LocalTargetConnection inside a Service Callout with dynamic Path, something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout enabled="true" continueOnError="True" name="SC-Route-HTTP">
    <DisplayName>SC-Route-HTTP</DisplayName>
    <Request>
        <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
        <Set>
            <Payload contentType="{request_apigee.header.content-type}">{request_apigee.content}</Payload>
            <Verb>GET</Verb>
    <Response>response_apigee</Response>
    <LocalTargetConnection>
        <Path>{my_path}</Path>
    </LocalTargetConnection>
</ServiceCallout>

I didn't find a solution for that... can you help me?

Hi Dino, the code below works fine for me, do you see any problem there?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ServiceCallout enabled="true" continueOnError="True" name="SC-Route-HTTP">
    <DisplayName>SC-Route-HTTP</DisplayName>
    <Request>
        <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
        <Set>
            <Payload contentType="{request_apigee.header.content-type}">{request_apigee.content}</Payload>
            <Verb>GET</Verb>
	    <Path>{my_path}</Path>
    <Response>response_apigee</Response>
    <LocalTargetConnection>
        <Path></Path>
    </LocalTargetConnection>
</ServiceCallout>