Change Target URL while using target server configuration

I am using target configuration like below, how to update the path variable dynamically. I need to use different path for two request using the same target. I have to use target server configuartion , I am not able to use URL configuation as per our requirement.

<HTTPTargetConnection>
        <Properties/>
        <LoadBalancer>
            <Server name="hpid_target"/>
        </LoadBalancer>
        <Path>/scim/v2/Clients</Path>
    </HTTPTargetConnection> 
Solved Solved
1 7 5,023
2 ACCEPTED SOLUTIONS

EDIT 2018-July-11: today it is possible to specify a message template for the Path, for the HTTPTargetConnection. In other words, this works:

<HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
           <Server name="hpid_target"/>
    </LoadBalancer>
    <Path>{my-custom-path-variable}</Path>  <<<< valid!
</HTTPTargetConnection>

For the HTTPTargetConnection, this is not valid:

<HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
           <Server name="hpid_target"/>
    </LoadBalancer>
    <Path ref='my-custom-path-variable'/>  <<<< not valid
</HTTPTargetConnection>

I think there are a couple other options.

Before I lay 'em out, why are you using a TargetServer? It appears fromthe configuration that there is just one server. If that is the case, I will guess that you like the external configuration of the target server URL, on a per-environment basis.

If that is the case, then you may be able to get the same effect by populating a KVM entry in the environment with the target server address, and setting the target.url variable dynamically, in the target flow. This has the added advantage that you can also dynamically set the path - of course you MUST set the path when you set target.url, so you will reach your desired goal automatically. This option means you would eliminate the use of the TargetServer completely, and replace it with a KVM + HTTPTargetConnection.

View solution in original post

When using Target Servers (eg, the LoadBalancer element within HTTPTargetConnection), you can set the path via a message template.

Use this:

<TargetEndpoint name="Sampleservice">
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step>
        <Name>JS-AddPathSuffix</Name> 
      </Step> 
    </Request> 
  </PreFlow> 
  <HTTPTargetConnection> 
    <SSLInfo> 
      <Enabled>true</Enabled> 
    </SSLInfo> 
    <LoadBalancer> 
      <Server name="testserver"/> 
    </LoadBalancer> 
    <Path>{mypathvariable}</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

And this:

context.setVariable('target.copy.pathsuffix', false);
context.setVariable('mypathvariable', '/foo/bar/bam');

View solution in original post

7 REPLIES 7

EDIT 2018-July-11: today it is possible to specify a message template for the Path, for the HTTPTargetConnection. In other words, this works:

<HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
           <Server name="hpid_target"/>
    </LoadBalancer>
    <Path>{my-custom-path-variable}</Path>  <<<< valid!
</HTTPTargetConnection>

For the HTTPTargetConnection, this is not valid:

<HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
           <Server name="hpid_target"/>
    </LoadBalancer>
    <Path ref='my-custom-path-variable'/>  <<<< not valid
</HTTPTargetConnection>

I think there are a couple other options.

Before I lay 'em out, why are you using a TargetServer? It appears fromthe configuration that there is just one server. If that is the case, I will guess that you like the external configuration of the target server URL, on a per-environment basis.

If that is the case, then you may be able to get the same effect by populating a KVM entry in the environment with the target server address, and setting the target.url variable dynamically, in the target flow. This has the added advantage that you can also dynamically set the path - of course you MUST set the path when you set target.url, so you will reach your desired goal automatically. This option means you would eliminate the use of the TargetServer completely, and replace it with a KVM + HTTPTargetConnection.

Thank you for the detailed response , We are using two way SSL for the target connection with different key stores for each environment . So it is easy to configure the target server than a url version of the HTTP target connection for each environment. Do you think this is real limitation, even if there is workaround using URL and keystore. Assume a customer is using multiple servers load balanced via apigee then they will end up in same situation.

The SSLInfo accepts variable references ... and keystore references. Which I think would satisfy your requirements. All of the necessary information could be dynamically encoded in the KVM, and applied at runtime... if you wanted.

I'm not sure what you mean by "they will end up in same situation". Not clear on that.

When Load balanced URL is configured it doesn't take SSL information configured within HTTPTargetConnection. Can you please let know what could be the issue here?

@krishnaprasadm

, As per my understanding you are trying to set <Path> dynamically for your call out. If yes then use the below configuration.

<Request clearPayload="true" variable="myRequest">
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <Set>
        <Path>{dynamic_path_variable}</Path>
    </Set>
</Request>
<Response>response</Response>
<HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
        <Server name="hpid_target"/>
    </LoadBalancer>
</HTTPTargetConnection>

Yes, that would work for a ServiceCallout policy. I think the OP is not interested in using a ServiceCallout policy, but instead, wants to use a typical HTTP target. In that case, I would think he could use an AssignMessage in the PreFlow of the target to do what you suggest. Like this:

<AssignMessage name="AM-DynamicPath">
    <AssignTo createNew="false" transport="http" type="request"/>
    <Set>
        <Path>/foo/bar/baz</Path>  <<<< won't work
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

But, per the documentation, the <Set><Path> element is not currently working as expected. Therefore, he needs to resort to an AssignVariable or a JS with a context.setVariable(), either way setting the target.url. (And it needs to be in the target preflow.)

When using Target Servers (eg, the LoadBalancer element within HTTPTargetConnection), you can set the path via a message template.

Use this:

<TargetEndpoint name="Sampleservice">
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step>
        <Name>JS-AddPathSuffix</Name> 
      </Step> 
    </Request> 
  </PreFlow> 
  <HTTPTargetConnection> 
    <SSLInfo> 
      <Enabled>true</Enabled> 
    </SSLInfo> 
    <LoadBalancer> 
      <Server name="testserver"/> 
    </LoadBalancer> 
    <Path>{mypathvariable}</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

And this:

context.setVariable('target.copy.pathsuffix', false);
context.setVariable('mypathvariable', '/foo/bar/bam');