Local dev support for property sets

Hi there!,

 

I'm attempting local development using the apigee setup described in the docs (VS code, docker etc) but I can't seem to get any property sets to work in target endpoint definitions. 

 

For example: I have a property set called `system.properties` with a key value such as: 

   
endpoints.ct.path=somepath 
 
If I try to refer to this property in my targets:
 
<TargetEndpoint name="default">
<HTTPTargetConnection>
<LoadBalancer>
<Server name="server0"/>
</LoadBalancer>
<Path>/{propertyset.system.endpoints.ct.path}</Path>
</HTTPTargetConnection>
</TargetEndpoint>

All calls that I make result in:

{"fault":{"faultstring":"Illegal propertyset keysystem.endpoints.ct.path","detail":{"errorcode":"Bad Request"}}}

I have tried all manner of combinations to get this to work (e.g. propertyset.system.properties.endpoints.ct.path, propertyset.endpoints.ct.path) but to no avail. 

What I'm trying to achieve is a per-env deployment configuration (different servers managed via targets but different paths via propertysets).

Has anyone come across a solution or know how to debug this?

 

Cheers!

1 8 264
8 REPLIES 8

As per this page https://cloud.google.com/apigee/docs/api-platform/cache/property-sets

"The property set name and property name cannot have dots in them." so you cannot use "endpoints.ct.path=..." for example.

Fantastic - I totally missed that bit as I had read the 'java properties' and away I went. I'll give it a whirl.

 

Thanks @dknezic !

I use underlines. 

The restriction against dots seems arbitrary, but ok.  I can use underlines as a separator.

So made the change and it's not complaining about the format anymore which is ace, so I've updated my config to specify the URL in HTTPTargetConnection to be the following:

<TargetEndpoint name="default">
<HTTPTargetConnection>
<URL>https://{propertyset.system.endpoints_server_host}/{propertyset.system.endpoints_server_path}</URL>
</HTTPTargetConnection>
</TargetEndpoint>

based upon what I had seen in this answer:

https://www.googlecloudcommunity.com/gc/Apigee/How-can-I-dynamically-set-the-URL-for-a-ServiceCallou...

When I test this locally, the value is not being replaced:

{"level":"WARNING","thread":"NIOThread@0","mdc":{"messageId":"4ea537fe-13e4-4305-8081-3a45f10d825b1","apiName":"commerce-tools","env":"dev","org":"hybrid","revision":"0"},"className":"com.apigee.httpclient.DNSCache$2","method":"failed","severity":"WARNING","message":"Failed to resolve hostname {propertyset.system.endpoints_server_host}. Reason {propertyset.system.endpoints_server_host}: Name or service not known. This log message will snooze for 2 hours [ERROR: UNUSED LOG ARGUMENTS] [CONTEXT ratelimit_period\u003d\"2 HOURS\" ]","formattedDate":"2021-11-26T09:40:32.931Z","logger":"SERVICES.HTTPCLIENTSERVICE"}
 

Hmmm...... I would have thought that would work.  Let me look into it.

Awesome - thanks for the followup @dchiesa1 - let me know if you need anything from my side

First let me give some information regarding using Flow variables in the URL of HTTPTargetConnection.
HTTPTargetConnection with URL can be  used in two places as of now - service callout and target endpoint. Following are the configuration differences in both usages.
Service Callout
<HTTPTargetConnection>
    <URL>http://{backend_url}</URL>
</HTTPTargetConnection>​


Target Endpoint
<HTTPTargetConnection>
   <URL>http://apigee.com/{backend_path}</URL>
</HTTPTargetConnection>​


Details:
  • Protocol must be static in both cases it cannot be part of a flow variable used. The validation of requirements is done during deployment time.
  • Host (apigee.com in above example) must be static in case of target endpoint. This cannot be part of the flow variable; making the host part of the flow variable causes failure with error code 500 even though the validation during deployment succeeds.
Now keeping this in mind, I used the below configuration for my local dev target configuration and got the propertyset property replaced in the url.
<TargetEndpoint name="default">
<HTTPTargetConnection>
<!-- <URL>https://mocktarget.apigee.net/xml</URL> -->
<URL>https://mocktarget.apigee.net/{propertyset.targetnameps.target_url}</URL>
</HTTPTargetConnection>
</TargetEndpoint>
 
Now if you need to hit different target hosts then you can use RouteRule to create different targets and send requests to different target endpoints.

I hope this helps you in solving your issue.

And for truly dynamic URLs, you can also set "target.url" in the target request flow. That will override the configuration in the HTTPTargetConnection in the TargetEndpoint.