Problem using proxy basepath in policy

Hi,

The way we have set Apigee up, a backend ilb with url map talking to multiple cloud run services, adds a prefix to the url that a backend services expects. To work this out we are adding an X-Forwarded-Prefix header to tell the backend service the added prefix. 
The problem is that when using apiproxy.basepath the result is just blank. Using apiproxy.name works fine, but we have proxies where the name and prefix (basepath) are not the same.

This is the policy we're trying to use that always gives an empty value:

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-SetForwardedPrefix">
  <DisplayName>AM-SetForwardedPrefix</DisplayName>
  <Properties/>
  <Set>
    <Headers>
      <Header name="X-Forwarded-Prefix">/{apiproxy.basepath}/</Header>
    </Headers>
  </Set>
</AssignMessage>
 
Switching from apiproxy.basepath to apiproxy.name in the same policy works.
Solved Solved
1 5 147
2 ACCEPTED SOLUTIONS

tl;dr: I think you probably want to use proxy.basepath.

There is some confusion on this, let me try to clarify.

apiproxy.basepath returns a value that reflects something you can specify at deploy time, to give Apigee an additional basepath to prepend to any basepath in the proxyEndpoint. To repeat: it does not override the basepath configured in the proxyendpoint. This basepath gets prepended to that value. Specifying this additional deployment-time basepath cannot be done from the UI, as far as know, but is possible via the API. Though I haven't tried it, in a long time.

In Apigee Edge, specifying the basepath at deployment time looks like this:

POST :mgmtserver/v1/o/:org/e/:env/apis/:apiproxy/revisions/:rev/deployments?action=deploy&basepath=/cdx
Authorization: :apigee-auth
Content-type: application/x-www-form-urlencoded

I don't know, off hand, the corresponding magic in Apigee X.

Regardless, the apiproxy.basepath returns that value, and it is typically empty, because you typically do not provide a basepath at deployment time.

On the other hand, proxy.basepath returns the value you specify in the ProxyEndpoint configuration, under the BasePath element. That's probably what you want.

View solution in original post

I actually just checked the flow variables docs again and there are two different vars.

apiproxy.basepath seems to be populated only when doing deployment using api.

proxy.basepath is populated from the HTTPProxyConnection/BasePath

Why are there two, and why do they behave differently?!

View solution in original post

5 REPLIES 5

tl;dr: I think you probably want to use proxy.basepath.

There is some confusion on this, let me try to clarify.

apiproxy.basepath returns a value that reflects something you can specify at deploy time, to give Apigee an additional basepath to prepend to any basepath in the proxyEndpoint. To repeat: it does not override the basepath configured in the proxyendpoint. This basepath gets prepended to that value. Specifying this additional deployment-time basepath cannot be done from the UI, as far as know, but is possible via the API. Though I haven't tried it, in a long time.

In Apigee Edge, specifying the basepath at deployment time looks like this:

POST :mgmtserver/v1/o/:org/e/:env/apis/:apiproxy/revisions/:rev/deployments?action=deploy&basepath=/cdx
Authorization: :apigee-auth
Content-type: application/x-www-form-urlencoded

I don't know, off hand, the corresponding magic in Apigee X.

Regardless, the apiproxy.basepath returns that value, and it is typically empty, because you typically do not provide a basepath at deployment time.

On the other hand, proxy.basepath returns the value you specify in the ProxyEndpoint configuration, under the BasePath element. That's probably what you want.

Hi, and thanks.

Actually, if you look at this proxy definition I have the BasePath set inside <HTTPProxyConnection>:

<ProxyEndpoint name="default">
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows/>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<HTTPProxyConnection>
<BasePath>/taxservice</BasePath>
</HTTPProxyConnection>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
</ProxyEndpoint>

When I click to view the endpoint summary in the console UI it says that the basepath is set.

Bomelin_0-1708558719762.png

Still it is empty in apiproxy.basepath.

As you suggested, and according to the link you shared I should set the <BasePath> as a direct child to <ProxyEndpoint>. It the gives me an error saying "Instance reported error beans.MarshalFailure: "java.lang.IllegalArgumentException: java.lang.ClassCastException@952b312"

I actually just checked the flow variables docs again and there are two different vars.

apiproxy.basepath seems to be populated only when doing deployment using api.

proxy.basepath is populated from the HTTPProxyConnection/BasePath

Why are there two, and why do they behave differently?!

I explained why there are two, and I explained why they are different, and I recommended that you use proxy.basepath... All in my original reply. 🙂

I'm glad you eventually sorted it out.  

Sorry I must have misread your first reply. Reading it again I realize you gave me the answers 🙂

it makes me wonder though what the use case would be for the other basepath. Why would one want to define two basepaths that could be set to different values?