I am running API-M that calls another system (SAP) to call an OData Service. The OData service will return a response with URL. I don’t want to expose the internal URL on API-M but the policies are not working.
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">
<edmx:Reference Uri="http://xxxxx.sap-internal.company.cloud/sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_AGGREGATION',Version='0001',SAP__Origin='LOCAL')/$value" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
I wanted to mask http://xxxxx.sap-internal.company.cloud to http://xxxxapim.azure-api.net
Basically, I am using both policies. I have also tried using one of both policies individually
<outbound>
<base />
<find-and-replace from="xxxxx.sap-internal.company.cloud" to="xxxxapim" />
<redirect-content-urls />
</outbound>
In trace, I am seeing the policies.
I am not sure why is it not performing the policy correctly. Anyone else encountered the same thing?
I tried using API-M Policies to do the conversion but it’s not working correctly.
2
Answers
The policies which you have used is correct even I have tried. I have an another approach use a custom script policy to replace the internal URL with the masked URL in the OData service response:
template="liquid"
allows you to use a script inside the@{}
block. The script retrieves the response body, replaces the internal URL with the masked URL using theReplace
method, and returns the modified response.I had a sample API to get register in APIM and tried that which you had given in the above to mask the internal URL returned by an some ex-service in Azure API Management.
I have redirect by using a function app and tried to mask the internal URL exposed.
Output:
Response of the Replaced URL.
I had the same problem with the find-and-replace policy and an SAP OData API. On my end it was caused by an response encoding error. The APIM trace showed "Compression br not supported". When I limited allowed encoding to gzip and deflate only, the expression started to work as expected. Curious if that is your issue too.