Path suffix not writing variables in new url

Not applicable

Hi

I have a TargetServer set up to allow me to redirect API calls to the relevant back end API depending on the environment. My Target Endpoint is correctly redirecting API calls to this url, but the problem comes when I want to change the destination path.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="Insurance">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows>
	......
    </Flows>
    <HTTPTargetConnection>
        <SSLInfo>
            <Enabled>true</Enabled>
        </SSLInfo>
        <LoadBalancer>
            <Server name="Insurance"/>
        </LoadBalancer>
        <Path>/api{targetpathsuffix}</Path>
        <Properties/>
    </HTTPTargetConnection>
</TargetEndpoint>

I have an AssignMessage policy that I can use to set the path suffix, and again this works

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="test-redirect">
    <DisplayName>test-redirect</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>targetpathsuffix</Name>
        <Value>/eng/test</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

The issue comes when I try and add a variable into the path. I have a policy to extract the variable (which works) and another AssignMessage policy to add it to the path:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-certificatetenancyId">
    <DisplayName>Extract Variables-certificate.tenancyId</DisplayName>
    <Properties/>
    <URIPath>
        <Pattern>/**/tenancy/{tenancyId}/test</Pattern>
    </URIPath>
    <Source clearPayload="false">request</Source>
    <VariablePrefix/>
    <variable name="tenancyId"/>
</ExtractVariables>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="insurance-tenancy-certificate-targetURL">
    <DisplayName>insurance-tenancy-certificate-targetURL</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>targetpathsuffix</Name>
        <Value>/tenancy/{tenancyId}/test</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

However this doesn't write the destination URL correctly:

http://xxxxxxxx/api/tenancy/%7BtenancyId%7D/test

Does anyone have any ideas as to why it won't translate the Id correctly?

Many thanks

Simon

Solved Solved
1 11 1,112
1 ACCEPTED SOLUTION

Ok try using Ref tag.

<AssignMessage name="Assign-Message-1">
    <AssignVariable>
        <Name>targetpathsuffix</Name>
        <Ref>/tenancy/urirequest.tenancyId/test</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

The Value element is used to set a specific value. The text of the Value element is not interpreted as a Message Template. (Wrapping variable names in curlies inside the Value element... does nothing! Though there is an outstanding feature request to allow something like this.)

I read this sometime back in community written by Dino.

View solution in original post

11 REPLIES 11

Hi Simon, did you try using an <VariablePrefix>urirequest</VariablePrefix> in Extract Variable policy.

Then in AM use /tenancy/{urirequest.tenancyId}/test

Hi Siddharth

Thanks for the quick reply! I just tried that, but I had the same result.

Ok try using Ref tag.

<AssignMessage name="Assign-Message-1">
    <AssignVariable>
        <Name>targetpathsuffix</Name>
        <Ref>/tenancy/urirequest.tenancyId/test</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

The Value element is used to set a specific value. The text of the Value element is not interpreted as a Message Template. (Wrapping variable names in curlies inside the Value element... does nothing! Though there is an outstanding feature request to allow something like this.)

I read this sometime back in community written by Dino.

Something different now at least. I get an error:

Unresolved variable : targetpathsuffix

Yeah my bad,

<Ref>/tenancy/urirequest.tenancyId/test</Ref> -- this doesnt work
<Ref>urirequest.tenancyId</Ref> -- this works, it will get the value from extarct variable policy.

I will give it a try & let you know.

Thanks Siddharth.

How would I then add the rest of the path around it though?

I think we need to use a Javascript policy.

Any chance you could help with that please?

 var id =context.getVariable("urirequest.tenancyId");
if(id !== null ){
  context.setVariable("targetpathsuffix", "/tenancy/"+ id +"/test");
}

Please try this JS code.

Thanks very much, that did it! I just needed to also remove the existing pathsuffix before calling the JS

I'm glad it worked 🙂