Skip to Content

Scenario

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.

Solution

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.

Integration Flow (on HCI)

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.

iflow.PNG

On the Sender side,
oDataSender.PNG
I have an OData Adapter using User Authentication to do a GET operation on BusinessPartnerSet entity.

The Sender endpoint looks something like this

https://<iflmap>/gw/OData/SAP/ES4GATEWAYFINDSUPPLIERADDRESS;v=1/BusinessPartnerSet

On the Receiver side I again used an OData Adapter,
oDataReciever.PNG

connecting to

https://sapes4.sapdevcenter.com/sap/opu/OData/IWBEP/GWSAMPLE_BASIC

and performing a GET operation on ProductSet entity with the following query

ProductSet?$select=ProductID,ToSupplier,ToSupplier/Address
,ToSupplier/BusinessPartnerID,ToSupplier/CompanyName
,ToSupplier/EmailAddress,ToSupplier/CurrencyCode
,ToSupplier/BusinessPartnerRole&$expand=ToSupplier
${header.filter}

 

You also need to

 

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;
}


I then map the BusinessPartnerSet instance from the expanded ToSupplier relation from ProductSet to the BusinessPartnerSet on the Sender and return.

Mapping.PNG

 

 

API Proxy (on API Management)

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.

Access the SAP HCP, API management API Portal to define your API Proxy
accessAPIPortal.PNG

 

  • Click on the hamburger icon on the top left corner.
  • Select the ‘Manage’ menu item on the left hand side
  • Then choose the default API tab
  • Then click on Create button on the bottom right corner
  • Create an API proxy

CreateAPI.PNG

 

Even though the HCI endpoint is OData, we will hide the OData nature and instead expose a very simple REST service.

Here we will populate the mandatory values…

  • URL -> This needs to be the sender endpoint of the integration flow
  • Name -> A suitable name for the Proxy
  • Title -> A suitable title for the proxy
  • API Base Path -> Enter ‘/FindSupplier’
  • Service type: Select ‘REST’

Click on Create to create the API Proxy
CreateSupplier.PNG

The same HCI endpoint can be exposed as an OData service by another end point if required.

NOTE: SAP HCP, API management supports OData, SOAP and REST api types.

Click on Policies to open the Policy Editor

SAP HCP, API management supports a wide variety of Policies to achieve varied use cases.

  • Choose Preflow under ProxyEndpoint.
  • Add a policy to this flow by clicking on the ‘+’ sign next to Response Cache from the Policy menu.

ChooseResponseCachePolicy.PNG

  • Specify a name for the policy
  • Choose the default stream ‘Incoming Request’
  • Click on Add

IncomingRequest.PNG

 

  1. Copy the following script to enable response caching. This attaches the policy to the incoming request.
  2. We need to attach this policy also on the outgoing message. To reattach, click on Preflow under the ProxyEndpoint again.
  3. Reattach the same policy by click on the ‘+’ under Created Policies

CopyScript.PNG

<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>

Note: this policy xml sets the timeout (interval response is cached) to 60 seconds and is described in the XML fragment

<ExpirySettings>
          <TimeoutInSec ref="">60</TimeoutInSec>
</ExpirySettings>

 

Simply choose the outgoing Stream this time, then click on Attach.OutgoingRequest.PNG

Click on update on the bottom right corner to save the policy

Click on Save and Deploy to Deploy the policy

  You can now use the API Proxy URL

deployed.PNG

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’

You will see the proxy URL and the Operation, as specified in the API Proxy already populated.

APITestConsole.PNG

Populate the following fields

  1. Click on ‘Authentication’ and enter your username and password valid for the integration flow sender endpoint
  2. Click on ‘Url Params’ to display the ‘Url Parameters’ section
  3. Populate the key with the query fieldname “ProductID” and the value as “’HT-1000’”. Notice the value is in single quotes.

TestA.PNGHitting send button more than once in a minute will show the following results

  • The time for each call is reduced due to Caching

 

The caching duration can be increased in the policy xml given above

Capture.PNG

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 can also make custom analytic charts by clicking the Analyze Data button at the bottom right of the screen

Analytics.PNG

 

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Aaditya Nigam Post author

    Hello Gagandeep,

     

    if you see the response cache code you see…

     

    We can describe an expiration strategy like

    <ExpirySettings> <TimeoutInSec ref=>60</TimeoutInSec> </ExpirySettings>

     

    The code that updates the master data can  fire a call to invalidate the cache, same url except a new header variable – invalidateCache. Which will go to the DB and retrieve fresh values.

    <SkipCacheLookup> request.header.InvalidateCache = “true” </SkipCacheLookup>

     

    Warm regards

    aadi

    (0) 

Leave a Reply