requirement to put basepath like below, v1/dm/*/change

Not applicable

Hi, I have the requirement to put basepath like below, v1/dm/*/change.

The * value will be employee or organisation.

If URL=v1/dm/employee/change

I need to call employee target URL.

if URL=v1/dm/organisation/change

I need to call the organisation target URL.

Could anyone please help me with the logic to implement this in APIGEE?

I tried with the below condition, it is not working <Condition>(proxy.pathsuffix LikePath "/employees/") and (request.verb = "POST")</Condition>

Solved Solved
0 4 435
1 ACCEPTED SOLUTION

Not applicable

No, you cannot use a wildcard in the basepath (not yet anyway).

You may be able to get what you want by using a shorter basepath - use the fixed part of what you want to include as a wildcard; in your case, this would be /v1/dm. And then use conditional flows with a "MatchesPath" operator.

<ProxyEndpoint name='whatever'>
 <Flows>
  <Flow name='flow1'>
   ...
   <Condition>proxy.pathsuffix MatchesPath "**/employee/*"</Condition>
  </Flow>
  <Flow name='flow2'>
    ...
   <Condition>proxy.pathsuffix MatchesPath "**/organisation/*"</Condition>
  </Flow>
 </Flows>
 ...
 <HTTPProxyConnection>
     <BasePath>/v1/dm</BasePath>
     <VirtualHost>...</VirtualHost>
     <VirtualHost>...</VirtualHost>
 </HTTPProxyConnection>
</ProxyEndpoint>

Note: the ** will match multiple path segments, the single * will match a single path segment.

View solution in original post

4 REPLIES 4

Not applicable

No, you cannot use a wildcard in the basepath (not yet anyway).

You may be able to get what you want by using a shorter basepath - use the fixed part of what you want to include as a wildcard; in your case, this would be /v1/dm. And then use conditional flows with a "MatchesPath" operator.

<ProxyEndpoint name='whatever'>
 <Flows>
  <Flow name='flow1'>
   ...
   <Condition>proxy.pathsuffix MatchesPath "**/employee/*"</Condition>
  </Flow>
  <Flow name='flow2'>
    ...
   <Condition>proxy.pathsuffix MatchesPath "**/organisation/*"</Condition>
  </Flow>
 </Flows>
 ...
 <HTTPProxyConnection>
     <BasePath>/v1/dm</BasePath>
     <VirtualHost>...</VirtualHost>
     <VirtualHost>...</VirtualHost>
 </HTTPProxyConnection>
</ProxyEndpoint>

Note: the ** will match multiple path segments, the single * will match a single path segment.

Thanks, @Priyadarshi Ajitav Jena.

I tried with the above condition, but still, it is not working. Please help here.

I attaching the trace screenshot and code.

Code:

Pre flow:
-----------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <Flows>
        <Flow name="employee">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "**/employee/*") and (request.verb = "POST")</Condition>
        </Flow>
        <Flow name="organisation">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "**/organisation/*") and (request.verb = "POST")</Condition>
        </Flow>
    </Flows>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/v1/dm/*/change-notification</BasePath>
        <VirtualHost>secure</VirtualHost>
        <VirtualHost>ecure_sso</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="employee">
        <Condition>(proxy.pathsuffix MatchesPath "**/employee/*") and (request.verb = "POST")</Condition>
        <TargetEndpoint>employee</TargetEndpoint>
    </RouteRule>
    <RouteRule name="organisation">
        <Condition>(proxy.pathsuffix MatchesPath "**/organisation/*") and (request.verb = "POST")</Condition>
        <TargetEndpoint>organisation</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

Target endpoint:
------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="employee">
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>https://hostname/v1/dm/change-notification/employees</URL>
    </HTTPTargetConnection>
</TargetEndpoint>



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="organisation">
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>https://hostname/v1/dm/change-notification/org</URL>
    </HTTPTargetConnection>
</TargetEndpoint>


Error message in Postname:
--------------------------


{
    "fault": {
        "faultstring": "Unable to route the message to a Target Endpoint",
        "detail": {
            "errorcode": "messaging.runtime.RouteFailed"
        }
    }
}

Error in trace:
-----------------
 <ErrorMessage>
            <Content>{"fault":{"faultstring":"Unable to route the message to a Target Endpoint","detail":{"errorcode":"messaging.runtime.RouteFailed"}}}</Content>
            <Headers>
                <Header name="Content-Type">application/json</Header>
            </Headers>
            <ReasonPhrase>Internal Server Error</ReasonPhrase>
            <StatusCode>500</StatusCode>
        </ErrorMessage>


Not applicable

please try below

Pre flow:
-----------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <Flows>
        <Flow name="employee">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/employee/change") and (request.verb = "POST")</Condition>
        </Flow>
        <Flow name="organisation">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/organisation/change") and (request.verb = "POST")</Condition>
        </Flow>
    </Flows>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/v1/dm</BasePath>
        <VirtualHost>secure</VirtualHost>
        <VirtualHost>ecure_sso</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="employee">
        <Condition>(proxy.pathsuffix MatchesPath "/employee/change") and (request.verb = "POST")</Condition>
        <TargetEndpoint>employee</TargetEndpoint>
    </RouteRule>
    <RouteRule name="organisation">
        <Condition>(proxy.pathsuffix MatchesPath "/organisation/change") and (request.verb = "POST")</Condition>
        <TargetEndpoint>organisation</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>


Target endpoint:
------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="employee">
    <PreFlow name="PreFlow">
        <Request>
	    <Step>
                <Name>AM-PathSuffixFalse</Name>
            </Step>
		</Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>https://hostname/v1/dm/change-notification/employees</URL>
    </HTTPTargetConnection>
</TargetEndpoint>






<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="organisation">
    <PreFlow name="PreFlow">
        <Request>
	    <Step>
                <Name>AM-PathSuffixFalse</Name>
            </Step>
		</Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>https://hostname/v1/dm/change-notification/org</URL>
    </HTTPTargetConnection>
</TargetEndpoint>




=========================================================================


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

@Priyadarshi Ajitav Jena's Thanks