This blog is part of a collection of blog entries that shows architectural concepts and configuration of the SAP PI REST Adapter. We also added some sample scenarios to make it easier for you to understand how your scenario can be implemented using the PI REST Adapter.

If you haven’t done so far, best is to start with the very first blog PI Rest Adapter – Don’t be afraid within the blog series covering the concepts of the REST adapter. A complete list of all blog entries can be accessed from here PI REST Adapter – Blog Overview.

The current blog describes how to call a function module via PI’s RFC adapter, and expose the same as a RESTful service.

Scenario

We would like to read customer data from an ERP backend system calling a remote function module, and expose this interface as RESTful service. The customer ID is passed to the service as part of the URL of the RESTful service call. In order to map the customer ID to the corresponding input field of the function module, we need to retrieve the ID from the URL, and store the same as adapter specific attribute.

In the SAP Process Integration Designer perspective of the NetWeaver Developer Studio (NWDS), I have defined an Integration Flow with a REST sender channel and an RFC receiver adapter. In the operation mapping, the value of the adapter specific attribute is read, and mapped to the function module structure.

Configuring the REST sender channel

On the Integration Flow, double click on the sender channel, and switch to tab General below the Adapter-Specific settings. In our specific case, the settings for the input message format, i.e., the format of the request message are superfluous since we do not provide any payload anyway. As mentioned above, the required customer ID is part of the URL. Choose Quality of Service Best Effort. The format of the output message, i.e., the response, should be JSON. Within PI, the format of the response from the remote function call is XML, so we need to select the Convert XML Payload to JSON check box.

We would like to define a custom end point. On the Channel Selection tab we specify the static part of the end point URL whereas on the REST Resources tab we define the dynamic part that will hold the customer ID. Switch to tab Channel Selection, and select the Specify Endpoint check box. As endpoint, we enter /demo/query/customer. Furthermore, we can limit the endpoint to specific http operations. We would like to allow the service being called via the GET http operation only, so we select the Limit to HTTP Operation check box, and the GET http operation from the drop down box.

Switch to tab REST Resources, and define the URL pattern as /{id_part}. The pattern element id_part is a placeholder for the customer ID. As mentioned above, we need to store the customer ID within a dynamic attribute. In the XI Dynamic Attribute section, we map the pattern element id_part to the dynamic attribute id.

Mapping the customer ID

In the ESR, I have created a user defined function getASMA  to read the value of the dynamic attribute:

@LibraryMethod(title=“getASMA”, description=“get adapter specific message attribute”, category=“UDFPool”, type=ExecutionType.SINGLE_VALUE)

      public String getASMA (

            @Argument(title=“”) String namespace,

            @Argument(title=“”) String attribute,

             Container container)  throws StreamTransformationException{

            Map all = container.getInputHeader().getAll();

            DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

            DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);

            String value = dynConf.get(key);

            return value;

      }


As input parameter of the function I pass the key of the attribute, in our case name id with namespace https://sap.com/xi/XI/System/REST. The value of the attribute is mapped to the input field CUSTOMERNO of the function module.




Running the scenario

For testing the scenario you can use the Advanced REST Client Application in the Google Chrome browser. The endpoint URL of your RESTful service starts with https://:/RESTAdapter with host and port of the SAP PI system, followed by what you have defined in the sender channel, here /demo/query/customer/.


Example: Assuming we would like to gather information of customer with ID 26, so the URL would be as follows:


https://:/RESTAdapter/demo/query/customer/26

As a response we would get the customer details in JSON format as can be seen in figure below.

I hope this blog was helpful to understand how to expose a function module as RESTful service using the SAP PI REST adapter. If you like to learn more, check out the other blogs in the series, accessible from the main blog PI REST Adapter – Blog Overview.

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !