A user needs to find suppliers of a given part. The enterprise has an SAP HANA Cloud Platform, integration services (f.k.a., HCI) integration flow that does the task. We need to provision an API Proxy to the HCI end point that is safe to expose outside the enterprise and simple to consume.
Additionally for repeated requests for the same part, the enterprise needs to temporarily store the calculated result to reduce the load on the HCI tenant to ensure quick responses.
To expose the HCI integration flow endpoint via an API Proxy provisioned in SAP HANA Cloud Platform, API management.
A simplified way to think of an API Proxy is a reverse proxy that shields the real endpoint from external clients. It is also possible to execute logic before and after the call. This enables add-on features like Governance, Load management, Analytics to name a few.
This blog will showcase enabling 'Response Caching', a topic under Load Management on an HCI endpoint.
We will also be simplifying the end point URL for easier consumption.
I will outline an integration flow then show how this integration flow’s end point can be exposed via an API Proxy that improves performance by adding caching mechanism to the API Proxy .Then finally show how one can get analytics data on the performance of the API Proxy and the HCI Integration flow.
To keep this blog simple, I am using simpler integration flow as a placeholder for something much more complex, as would typically be found in a real scenario. I am querying the ProductSet for the ProductID and retrieving the related suppliers for the product.
I am connecting to the ES4 demo gateway system. To sign up to use the ES4 system refer to this blog.
The HCI integration flow.
https://<iflmap>/gw/OData/SAP/ES4GATEWAYFINDSUPPLIERADDRESS;v=1/BusinessPartnerSet
https://sapes4.sapdevcenter.com/sap/opu/OData/IWBEP/GWSAMPLE_BASIC
ProductSet?$select=ProductID,ToSupplier,ToSupplier/Address
,ToSupplier/BusinessPartnerID,ToSupplier/CompanyName
,ToSupplier/EmailAddress,ToSupplier/CurrencyCode
,ToSupplier/BusinessPartnerRole&$expand=ToSupplier
${header.filter}
I am using a script to formulate an OData filter clause dynamically using values passed by the user via query parameters. I am deliberately avoiding directly accepting an OData filter clause from the user to ensure the endpoint is simple to use.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import org.apache.olingo.odata2.api.uri.UriInfo;
import com.sap.gateway.ip.core.customdev.logging.*;
def Message processData(Message message) {
def filterText = "&\$filter=";
def prodFld = "ProductID";
def custom= message.getHeaders().get("UriInfo")
.getCustomQueryOptions();
def filterQuery = new StringBuilder();
def prodId = custom.get("ProductID");
if (prodId != null){
filterQuery.append(filterText);
filterQuery.append("$prodFld eq $prodId");
}
if (filterQuery.size() != 0)
message.setHeader("filter", filterQuery.toString()); //<-This step is crucial
return message;
}
To sign-up for an SAP HCP, API management Trial account please refer to this blog.
To learn more about SAP HCP, API management please visit http://scn.sap.com/community/api-management
We will use the API Portal (for API Administration) in this blog. The Dev Portal (for developer access and consumption) will be covered in another blog in this series.
In the SAP HCP, API management API Portal we will define an API Proxy. On this proxy we will define a response cache policy to cache responses, in order to reduce the average response time as well as reduce the load on the HCI tenant.
The same response cache policy is attached to the incoming call and the outgoing call. The incoming call is checked by the proxy policy to see if a response is cached, if so it then returns the data from the cache if not cached the proxy forwards the call to the target endpoint i.e., the HCI Sender Endpoint. The response from the target endpoint again encounters the response cache policy where it caches the response, for future requests before returning to the caller.
We will then use the API Test Console available in the SAP HCP, API management Dev Portal to execute the newly created API Proxy. Here we will see a significant reduction in the response times due to caching.
We can also see Analytics on the SAP HCP, API management API Portal. A standard set of charts are available to track performance of the API calls. It is also possible to specify custom charts, however we will not explore that in this blog.
<ResponseCache async="false"
continueOnError="false"
enabled="true"
xmlns="http://www.sap.com/apimgmt" >
<CacheKey>
<KeyFragment>param</KeyFragment>
<KeyFragment ref="request.queryparam.ProductID" />
</CacheKey>
<ExpirySettings>
<TimeoutInSec ref="">60</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup>
request.header.InvalidateCache = "true"
</SkipCacheLookup>
<SkipCachePopulation>
</SkipCachePopulation>
</ResponseCache>
<ExpirySettings>
<TimeoutInSec ref="">60</TimeoutInSec>
</ExpirySettings>
Simply choose the outgoing Stream this time, then click on Attach.
Click on update on the bottom right corner to save the policy
Click on Save and Deploy to Deploy the policy
Click on the 'Test' menu item
This opens the API console
Here you will find your API Proxy already listed.
Click on the API Proxy – ‘Find Suppliers’
Populate the following fields
Click on 'Analyze' menu item to view api analytics.
This image captures the analytics of the calls made in the previous step i.e., two calls to Find Supplier.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
35 | |
25 | |
14 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |