Skip to Content

As mobility and cloud become the most prominent drivers for the IT investments today, the need for compact, light-weight integration is immensely felt, leading to  emergence of alternatives to conventional SOAP-based web-services. RESTful web services is one such option that is poised to replace conventional web service calls in many areas. In this blog, I wish to describe our journey through a successful implementation of a RESTful web service scenario using SAP PI.  I am borrowing the example web service from a popular blog by Michal Krawczyk on static RESTful web service via sender SOAP adapter; however our problem definition is different – a synchronous web service call with dynamic request message.

Since we are using PI 7.11, we only had the below choices when greeted with a challenge to consume a RESTful web service using SAP PI –

1.       Develop custom adapter module to address the peculiarities of RESTful web service calls

2.       Purchase third party adapter  that provides  out-of-the-box REST capabilities

Both these options obviously have their own limitations. However, Axis framework (Refer to SAP Note 1039369 for details) turned out to be an economical, fast and yet elegant option to fulfil the requirement.  It helped us address the two major challenges in implementing dynamic RESTful web service calls.

1. Dynamic Request  message:

An important difference between RESTful web service and SOAP-based web-service is that the former does not depend upon request XML message to deliver the response. The RESTful web-server extracts the request parameters from the URL used to call the service.  Since the parameters are to be taken from user inputs to the source application, it follows that the URL is to be  constructed dynamically at runtime based on these parameters. As the request XML message does not matter at the web-server end, a dummy message type  with a single node is sufficient to be used as target message in request mapping.  This is just to complete the design in ESR. The target server does not care about the request message at all !

The request message mapping is important as it gives us the handle to run a UDF that would collect the parameters from source message and build them into a meaningful URL. Once the URL is prepared, it is set into the dynamic configuration during mapping.

/wp-content/uploads/2012/08/scr5_128479.jpg

Finally the module chain is augmented with additional calls to Axis Handler Beans. A working combination for setting the URL in a RESTful call is shown below.

/wp-content/uploads/2012/08/scr2_128560.jpg

The Axis documentation accompanying SAP Note 1039369 implies that any arbitrary values for the namespace and parameter name should serve the purpose. However it has been observed that the adapter disregards the dynamic URL unless the exact key pair (http://sap.com/xi/XI/System/SOAP TServerLocation) is used.

Make sure that you check the ‘Keep Header’ checkbox in the communication channel parameters. This will ensure that the dynamic configuration is still available in the message header by the time the adapter framework invokes the Dynamic Configuration Handler for Axis. The URL entered in the communication channel is just for namesake.

/wp-content/uploads/2012/08/scr6_128559.jpg

The steps taken so far ensured that the request message (in the form of a URL) is constructed dynamically.

The remaining story to be continued in the next blog. Till then, REST assured !!

To report this post you need to login first.

6 Comments

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

  1. sabitha gangishetty

    Hi Amit,

    We are trying to implement the similar scenario. We are facing the below error when triggering from Runtime Workbench. Do we need to deploy any jar files.

    Error While Sending Message: Additional error text from response: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.lang.IllegalArgumentException: object type invalid: class com.sap.aii.adapter.xi.ms.XIMessage

    Regards

    Sabitha

    (0) 
  2. sabitha gangishetty

    Hi Amit,

    The error is resolved we have rechecked the module parameters and kept in same order. And that is working fine.

    Additionally we have added the ACCEPT Header Parameter and followed below steps in channel module configuration for module HandlerBean:

    handler.type:java:com.sap.aii.axis.soap.MessageContextPropertiesHandler

    key.0 : set HTTP-Request-Headers{Accept}

    value.0 : */*

    Regards,

    Sabitha

    (0) 
  3. ravi teja

    Hello Amit,

    Does this go well with PI 7.0 too?.. I dont see the provision to set the SOAP Action to “GET” as opposed to what you have depicted in the PI 7.1 screen shot

    (0) 
  4. Rebecca Alice

    Dear Amit,

    I have posted a query on this link Integration with JAVA application with JSON response.

    SAP PI has to consume the Restful service where the client has given the url

    http://www.trex:5500/TCS/IntServelt

    The Input parameter for the request is

    credentials=user10,TCS&password=TCS&action=getUserItem s&domainName=user10&departmentId=


    What could be the full formed url to access the services


    http://www.trex:5500/TCS/IntServelt&credentials=user10,TCS&password=TCS&action=getUserItems&domainName=user10&department…



    I am expecting a response from the system supporting JSON format.


    Regards

    (0) 

Leave a Reply