How can I append an arbitrary suffix to the target url, when using Target Servers?

Not applicable

I have 2 proxies calling internally calling Proxy 1 to Proxy 2 using path chaining. First endpoint in Proxy 2 returns a message back to Proxy 1 for additional processing then it calls Proxy 2 again on a different endpoint.

Proxy 2 needs to use the same target, which was invoked in first call, but with a different endpoint (endpoint basepath is same, but path suffix is different).

I am setting context.setVariable('target.copy.pathsuffix', false); using a javascript in preflow of target endpoint. This worked when on first call on proxy 2 while invoking a Target. In Second call target target.url is blank so I am not able to set path preffix.

Can you please advise?


Here I have simplified:

My proxy uses Target Servers.

The TargetEndpoint looks like 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>/v1/sample</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

This is the logic for AddPathSuffix.js :

context.setVariable('target.copy.pathsuffix', false);
var targeturl = context.getVariable('target.url');
context.setVariable('target.url', targeturl + '/contacts' );

I want it to call https://testserver.com/v1/sample/contacts but it is calling https://testserver.com/v1/sample .

How can I append an arbitrary suffix to the target url, when using Target Servers?

Solved Solved
0 5 1,944
1 ACCEPTED SOLUTION

When using Target Servers, 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>/v1/sample{mypathsuffix}</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

And this:

context.setVariable('target.copy.pathsuffix', false);
context.setVariable('mypathsuffix', '/contacts');

View solution in original post

5 REPLIES 5

not clear on how all the parts are connected or what you are trying to do.

There is chaining involved.

Seems like you want to invoke proxy2, from proxy1, two different times, in two different ways.

We can try to help. Please provide additional information:

1. Show what you've tried; show your configuration. Specifically proxy1, and where you are trying to connect to proxy2. ServiceCallout? TargetEndpoint? SHOW IT, don't say it. Show variable settings like target.copy.pathsuffix .

2, describe what you are expecting to happen.

3. describe what you observe is actually happening.

@Dino-at-Google

Proxy1 is calling an endpoint on proxy 2, which is calling /v1/sample/persons(using service callout HTTPTargetConnection) and /v1/sample/addresses (using Targetendpoint HTTPTargetConnection)

After I receive response from proxy 2 on previous call (after /v1/sample/addresses), now I call a different endpoint on Proxy 2 from proxy 1 using Target Endpoint(using path chaining) on Proxy2.

Proxy 2 - once I receive a request, I like to call a different endpoint on the same server i.e. /v1/sample/contacts using target endpoint

Proxy 2 Target Endpoint configuration:

<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>/v1/sample</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

Proxy 1 Target Endpoint configuration:

<TargetEndpoint name="sales"> 
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step> 
        <Name>JS-DisableCopyPathSuffix</Name>
      </Step> 
    </Request> 
  </PreFlow> 
  <LocalTargetConnection> 
    <Path>/v2/proxy2</Path> 
  </LocalTargetConnection> 
</TargetEndpoint>

2, describe what you are expecting to happen.

In a second call to Proxy2, when I am calling /v1/sample/contacts endpoint using tagetendpoint, it is trying to append path suffix from request endpoint. I have added a java script to remove path suffix and get target url to append new path suffix i.e. /contacts

3. describe what you observe is actually happening.

Target url is blank in tareget endpoint preflow. I am not able to set target url. If I don't disable path suffix in preflow, it is adding path suffix from the request. If I disable path suffix using java script in targetendpoint preflow it is using the path defined in targetendpoint i.e. /v1/sample

My requirement is to call /v1/sample/contacts.

Please let me know if I need to describe little more..

You know, I'm still not clear on which request is not working according to your desires. You've outlined these requests, I think:

  • proxy1 to proxy2 (via ServiceCallout)
  • proxy2 to /v1/sample/persons (via ServiceCallout?)
  • proxy1 to proxy2 (via Target - chaining? not sure)
  • proxy2 to /v1/sample/addresses (via Target)
  • proxy2 to /v1/sample/contacts (via Target)

(it seems like there is a 3rd system, unnamed, in the mix: /v1/sample/addresses, etc)

And I'm not sure which of those requests you're talking about. Not clear on which one is troubling you.

What I suggest is that you simplify the problem. Break it down. Simplify it. Remove some moving parts. Get the basics working. And then after the basic thing works, add complexity.

If the problem is in the proxy1->proxy2 connection, then use a version proxy2 that has NO TARGET. It delivers mocks. The proxy2->(other system) is irrelevant, so remove it! Get your problem sorted.

If the problem is in the proxy2->(some other system), then eliminate proxy1 completely, because it's irrelevant. Sort out the problem, then

Once you get the first problem sorted, add in the next piece.

It seems like sometimes you want to propagate the path, and sometimes not. But I don't know when you want to propagate it, and when you do.

Here I have simplified:

I tried calling second endpoint on proxy 2 directly, target url is empty in the trace.

Flow doesn't have any thing, it is directly calling target endpoint.

AddPathSuffix.js :

context.setVariable('target.copy.pathsuffix', false);
var targeturl = context.getVariable('target.url');
context.setVariable('target.url', targeturl + '/contacts' );

It's supposed to call https://testserver.com/v1/sample/contacts but it is using target url as https://testserver.com/v1/sample

<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>/v1/sample</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

When using Target Servers, 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>/v1/sample{mypathsuffix}</Path> 
  </HTTPTargetConnection> 
</TargetEndpoint>

And this:

context.setVariable('target.copy.pathsuffix', false);
context.setVariable('mypathsuffix', '/contacts');