Skip to Content

Thought I would share some notes I took when testing REST adapter functionality, with thanks to the following blog for getting me started https://blogs.sap.com/2014/12/18/pi-rest-adapter-blog-overview/.  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

For the request message mapping populate fields with constants where required

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

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

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)

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

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

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.

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.

SOAP UI

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

                                                                                 

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

SOAP UI call then looks like

SENDER ADAPTER – POST XML

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

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

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.

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)

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

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

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

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply