SAP Process Integration, SAP PI

REST Sender Adapter GET and POST Examples

The example that follow are based on a REST sender request calling an RFC in ECC. Only the steps relevant to using the REST adapter are shown.

SENDER ADAPTER – GET

Data is send in HTTP header therefore no payload is submitted

ESR

Could not find any examples on how to do this so there may be better ways than my methodology – create a dummy message type for the request message.

SAP Process Integration, SAP PI

For the request message mapping populate fields with constants where required

SAP Process Integration, SAP PI

For fields where the data will be passed in from the URL or via parameters create function to read the data from the dynamic attributes of the message

SAP Process Integration, SAP PI

public String getASMA(String attribute, String namespace, Container container) throws StreamTransformationException{
Map map = container.getTransformationParameters();
DynamicConfiguration conf = (DynamicConfiguration)map.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);
String value = conf.get(key);
return value;
}

Use UDF in mapping

SAP Process Integration, SAP PI

Where ‘attribute’ field in UDF (constant ‘id’ in this example) = Name of Dynamic attribute in communication channel (see further down for details on setting this up)

SAP Process Integration, SAP PI

And ‘namespace’ field in UDF is set to: http://sap.com/xi/XI/System/REST

ID

Configure Sender REST adapter

Does not matter what the input message format is since no payload sent with GET requests
Output message can be XML or JSON

SAP Process Integration, SAP PI

On Channel Selection tab tick specify endpoint and enter name of resource the client will call
Can use format {name}/{name2}…. As required

SAP Process Integration, SAP PI

On REST Resources tab set URL Pattern to ‘Custom Pattern’ and then specify what attributes will be fed from the URL, attributes put in curly brackets. Next populate the XI Dynamic attribute settings, this dictates what get set in the dynamic attributes of the message and can then be read in message mapping. In below example an attribute of ‘id’ will be created with a value as passed in the URL {cust_no} place holder.

SAP Process Integration, SAP PI

On Operation Determination tab set pointer to the interface to call (assume needs this since no payload was passed?). In the below example Operation and Namespace are set to the Name and namespace of the request Message Type respectively.

SAP Process Integration, SAP PI

SAP Process Integration, SAP PI

SOAP UI

Method = ‘GET’
Endpoint = ‘http://{host}:{port}/RESTAdapter’
Resource = Endpoint value specified above in communication channel plus the URL pattern

SAP Process Integration, SAP PI SAP Process Integration, SAP PI

So in the above example data is retrieved for customer 010

To run for a different customer just change the last value

To Run using a Parameter instead:

Change adapter as below

SAP Process Integration, SAP PI

SOAP UI call then looks like

SAP Process Integration, SAP PI

SENDER ADAPTER – POST XML

Data is sent in HTTP body and receiver as payload in PI

SAP Process Integration, SAP PI

On Channel Selection tab tick specify endpoint and enter name of resource the client will call
Can use format {name}/{name2}…. As required

SAP Process Integration, SAP PI SAP Process Integration, SAP PI

In SOAPUI set Method to ‘POST’ and endpoint to ‘http://{host}:{port}/RESTAdapter’ and Resource to the Endpoint value specified above in communication channel. Nb I used the BAPI data format for the sender and receiver interfaces.

SAP Process Integration, SAP PI

SENDER ADAPTER – POST JSON

Set input data format as JSON and tick ‘Convert to XML’ and ‘Add Wrapper Element’
Enter Element Name/Namespace as per Root node of expected message (Request message)

Above settings will convert JSON to PI required format

Change output data format to JSON and tick ‘Convert XML payload to JSON’
(could leave output as xml if required)

SAP Process Integration, SAP PI

On Channel Selection tab tick specify endpoint and enter name of resource the client will call

SAP Process Integration, SAP PI

SAP Process Integration, SAP PI

In SOAPUI set Method to ‘POST’ and endpoint to ‘http://{host}:{port}/RESTAdapter’ and Resource to the Endpoint value specified above in communication channel

SAP Process Integration, SAP PI

Set Media Type to ‘application/json’ and enter json for required fields in PI sender service interface is expecting

SAP Process Integration, SAP PI

Leave a Reply

Your email address will not be published. Required fields are marked *