Skip to Content
Technical Articles

CPI OData Calculator: SOAP Source (with Groovy Script on the Message Mapping)

Hello,

As SAP® “speaks” OData (Mobile, FIORI, etc.), my goal here is to demonstrate how the “OData conversion” works on CPI, creating a simple Calculator (multiply operation) iFlow:

We have a few options as the data source on the OData iFlow creation, in this blog i’m gonna use the SOAP one.

For the SOAP Webservice, i’m gonna use the http://www.dneonline.com/calculator.asmx. This is a FREE Calculator SOAP Webservice that will do just fine for the desired scenario.

So first things first, download the WSDL file here, we’re using the Multiply operation.

Play around with it if you want, note the test below (using SOAPUI):

It has 2 inputs and the result output.

So let’s create our scenario, on your CPI package create a OData Service:

Place your desired info:

Lets create our Entity Set from the WSDL file:

Mapping both the Inputs parameters and Output result:

Renamed the Fields and Entity Set (also changed the data type to String):

For the Multiply operation, let’s use the Create (POST) operation. So select the binding:

Use the WSDL again, to tell the operation that the iFlow needs to use, like this:

It will generate an iFlow, in the end it should look like these:

So first, let’s create a Content Modifier to capture the 2 Input fields on the Payload (using XPath):

After that, open the Request Mapping and:

On the SOAP Request-reply, don’t forget to replace the Auth to None:

 

 

 

 

 

 

On the response mapping, we’re mapping like these:

 

For the SOAP1 and SOAP2 fields, we want to send it back together with the result, because the SOAP WS just returns the value. For that, as we’ve created Property for the 2 inputs(on the Content Modifier above), we can access them using Groovy Script:

import com.sap.it.api.mapping.*;

def String SOAP1(String arg1, MappingContext context) {
         String SOAP1 = context.getProperty('SOAP1');
         return SOAP1;
}
def String SOAP2(String arg1, MappingContext context) {
         String SOAP2 = context.getProperty('SOAP2');
         return SOAP2;
}

Created like this, to show also how we could pass parameters to the script(this time, we’re not using, just using the Context):

Now save everything, it should look like these:

Deploy and let’s test it (using Postman):

First, don’t forget to get the Token(X-CSRF-Token) from a simple Get to the OData root URL service. After that, let’s make a POST request using the payload below:

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
 <content type="application/xml">
  <m:properties>
   <d:SOAP1>3</d:SOAP1>
   <d:SOAP2>75</d:SOAP2>
  </m:properties>
 </content>
</entry>

And Voilà:

Next up, we’re gonna create from a REST data source.

Enjoy!

Regards.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.