Proxy Path Suffix to be removed from on the basis of Flow Condition

I have a API Proxy (attached) , where I want to remove the path suffix for one of the FLOWS named POST-refresh.

Currently, I have Assign Message Policy (AM-RemovePathSuffix) which removes proxy path suffix for all the FLOWS defined in ProxyEndPoint.

How this can be achieved where proxy path suffix is removed on the basis of Condition in FLOWS.

Any quick help will be much appreciated

Thanks

authentication-access-token-rev1-2017-06-12-jainor.zip

Solved Solved
0 4 1,699
1 ACCEPTED SOLUTION

Not applicable

Hi @GAURAV try this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>JS-OpenAMTarget</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows>
     <Flow name="POST-refresh">
            <Description> Open AM API for refreshing access token</Description>
            <Request>
              <Step>
                <Name>AM-RemovePathSuffix</Name>
            </Step>
            </Request>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/refresh") and (request.verb = "POST")</Condition>
        </Flow>
    </Flows>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>http://keng01-dev01-ath31-oam31.int.dev.mykronos.com:8080/authn/oauth2/{realm}/access_token</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

View solution in original post

4 REPLIES 4

Not applicable

Did you try moving this AM-RemovePathSuffix step to a flow instead of having in preflow? @GAURAV

@Maruti Chand

How can I do that? Pls share

Thanks

Not applicable

Hi @GAURAV try this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>JS-OpenAMTarget</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows>
     <Flow name="POST-refresh">
            <Description> Open AM API for refreshing access token</Description>
            <Request>
              <Step>
                <Name>AM-RemovePathSuffix</Name>
            </Step>
            </Request>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/refresh") and (request.verb = "POST")</Condition>
        </Flow>
    </Flows>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>http://keng01-dev01-ath31-oam31.int.dev.mykronos.com:8080/authn/oauth2/{realm}/access_token</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

This is an old question and I'm sure you've moved beyond this problem by now. But maybe someone else has a similar question, and an answer might help.

You have this configuration in your target endpoint:

    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>AM-RemovePathSuffix</Name>
            </Step>
            <Step>
                <Name>JS-OpenAMTarget</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>


 

The AM-RemovePathSuffix is the policy you had mentioned. Within that policy there is this configuration:

<AssignMessage name="AM-RemovePathSuffix">
    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
</AssignMessage>

What that means is that for every request, you're un-setting the flag variable that governs whether the pathsuffix gets appended to the outbound request.

You ask, how can you do that only for a subset of requests?

Answer: use a condition.

   <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>AM-RemovePathSuffix</Name>
                <!-- add the following -->
                <Condition>CONDITION-GOES-HERE</Condition>
            </Step>
            <Step>
                <Name>JS-OpenAMTarget</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>

You must replace CONDITION-GOES-HERE with an actual condition expression. The condition syntax is described here.

One easy way to do it is to set a variable in the proxyendpoint "conditional flows" for which you want to retain (or alternatively, to avoid) the propagation of the proxy pathsuffix to the target. Set a boolean flag in each conditional flow there, then test the flag in the condition in the target endpoint.

IF you read me correctly, you see I'm suggesting that you set a boolean flag in the proxy endpoint, so that you can know in the target endpoint whether to set a different boolean flag. And that might seem a little frustrating and redundant. Why not just set the second flag directly in the proxy endpoint? The problem is the latter boolean flag, the well-known one which is documented by Apigee, "target.copy.pathsuffix", automatically gets set to true at the inception of the target flow. So whatever change you might make to target.copy.pathsuffix in the proxyendpoint will get overwritten when the targetendpoint starts. So we need a backup flag .

I hope this helps.