Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Working with REST Adapter: A REST to SOAP Scenario in SAP PI/PO

Introduction: With the introduction of the REST Adapter in SAP PI/PO, consuming a REST service or exposing a REST service in PI becomes more fun. This is with respect to the fact that the SAP PI/PO ESB extends its capabilities to handle and process REST-based messages (XML, JSON) easily. Prior to this time, implementing or consuming a REST-based service had to be done via third party adapters (e.g Advantco) or manipulation of the AXIS Framework within SAP PI, which is often a tough task. In this blog, my aim is to highlight simple steps needed to expose a REST-based service in SAP PI/PO. An end-to-end implementation of simple REST to SOAP scenario is described.

Prerequisite: SAP NetWeaver 7.31 SP14 or SAP NetWeaver 7.40 SP 09 and above, knowledge of creating objects in Enterprise Service Repository and Integration Builder.

Scenario: The REST to SOAP scenario is implemented such that, an XML-based/JSON-based request is triggered from SOAP UI/Chrome REST Client. It is received by the Configured REST Adapter, processed and passed to the Receiver SOAP Adapter (configured to connect with the currency converter webservice from www.webservicex.com ).

Figure: Exposing REST-based Service via SAP PI as shown in REST-to-SOAP Scenario diagram

ESR and Configuration Objects: In this scenario, the necessary ESR objects creation steps are only listed below, with more emphasis on the configuration.

ESR Objects: Create the following ESR objects

1)      Download the WSDL from: http://www.webservicex.com/ws/WSDetails.aspx?CATID=2&WSID=10

2)      Import the WSDL as external definition in the sender and receiver namespaces

3)      Create the service interfaces for sender and receiver (use the same XSD on both sides)

4)      Create the message mappings and operation mappings

Directory Objects: Described below the necessary configurations steps for each object;

Sender REST Adapter: Create the Sender Communication channel by selecting the “REST Adapter” option.  Configure the REST Adapter as show below;

  • Input message format: XML
  • Quality of Service: Best Effort
  • Output message format: XML

Figure: Sender REST Adapter Configuration with input message as XML

Navigate to the “Channel Selection” and specify a URL path.  This is optional, but useful to distinguish the different scenarios exposing REST-based services in SAP PI, as this will be added in the URL of the sender application (in this case: SOAP UI).

Figure: Sender REST Adapter Configuration Endpoint

Receiver SOAP Adapter: Create the receiver communication channel and provide the necessary connection details to the currency converter webservice.

Figure: Receiver SOAP Adapter Configuration

Integrated Configuration: Configure the integrated configuration (ICO) using the sender and the receiver channels created earlier.

Test the Scenario with XML: To test the scenario, SOAP UI is used as the sender application. The endpoint URL to fire the message to is constructed as shown below;

http://<server>:<port>/RESTAdapter/<pathspecifiedinthecommunicationchannel>

eg: http://xxxxxxx:50000/RESTAdapter/Rojo/CurrencyConverter/201503

Obtain a sample XML message from the test tab of the “Message Mapping” object in the ESR to be used as the XML to be sent from SOAP UI.

Figure: XML Request message from SOAP UI


Change The Sender Adapter Configuration (for JSON to XML conversion)

In addition to the above test, change the sender adapter configuration from XML to JSON, so that SAP PI receives a JSON request message from SOAP UI;

  • Input message format: JSON with the following additional configuration
  • Convert to XML
  • Add wrapper element
  • Element name (name of the request message as in the XSD in ESR)
  • Element namespace (namespace of the request as in the XSD in ESR)
  • Quality of Service: Best Effort
  • Output message format: XML

Figure: Sender REST Adapter Configuration with input message as JSON

Test the Scenario with JSON: To test the scenario, SOAP UI is used as the sender application. The endpoint URL to fire the message to is the same as in the previous test. The SOAP UI JSON request and response messages are shown below;

Figure: JSON Request from SOAP UI

Figure: JSON Request from Chrome REST Client

The results of the calls to consume the exposed REST service in SAP PI based on the REST adapter are also shown above in both test cases.

Conclusion: With this blog, I have been able to provide an insight into how to expose a REST service in SAP PI/PO using the REST Adapter as the sender communication channel. Additional settings of the adapter can also be used as well, e.g. sending a JSON message as input or output message.

13 Comments
Labels in this area