Skip to Content
Author's profile photo Midhun VP

Writing Custom Script in SMP 3 Integration Gateway

What is Integration Gateway ?

Integration gateway is a component in SAP Mobile Platform 3, it converts different types of protocols to Odata protocol. It is based on SAP Lean Java Server, it enables easy and convenient access to SAP and non SAP systems. This helps the developer to consume the services in a harmonized manner.

ScreenHunter_20 Jan. 27 23.55.jpg

How to convert different protocols to Odata ?

Integration Gateway comprises design-time tools for modelling and defining new Odata services from different systems. The design-tool is based on Eclipse, that enable you to build Odata models. How to Configure in Eclipse?

It also has a Runtime that allows you to run the newly created Odata services against the associated backend systems.

Which are the supported data sources ?

  • Simple Object Access Protocol (SOAP)
  • Java persistance API (JPA)
  • Java Database Connectivity (JDBC)
  • Odata Channel (ODC)
  • REST

What is the role of custom script in Integration Gateway?

From SMP 3 SP04, Integration Gateway supports writing custom script while modeling Odata. It helps to modify the requests and responses. The supported scripts are Javascript and Groovy.

Let’s do an exercise using Custom Script:

In this example SOAP is converted into Odata and an Odata Query is created using Custom Script.

WSDL file used: http://www.webservicex.net/medicareSupplier.asmx?WSDL

If you are new to Integration Gateway try this first :How to connect SOAP WebServices with Integration Gateway

Steps:

  • Use SOAP UI tool (open source) to test the requests and to identify the payload that has to be send from Custom Script.

ScreenHunter_06 Oct. 21 00.29.jpg

  • Create Odata Models with respect to the SOAP response.

ScreenHunter_06 Oct. 21 00.31.jpg

  • After creating Odata models, select the data source and choose operation as Query.

ScreenHunter_06 Oct. 21 00.35.jpg

  • Create a script file by right clicking on the “Query” operation. Modify processRequestData function as given below to modify the request. The payload created by SOAP UI is manually recreated here using JavaScript.

function processRequestData(message) {

  importPackage(com.sap.gateway.ip.core.customdev.logging);

  importPackage(com.sap.gateway.ip.core.customdev.util);

  importPackage(org.apache.olingo.odata2.api.uri);

  importPackage(java.util);

  importPackage(com.sap.gateway.core.ip.component.commons);

  importPackage(com.sap.gateway.ip.core.customdev.api);

  var parentMap = new LinkedHashMap();

  parentMap.put(“key:City”,”california”);

  //Set the message body back

  message.setBody(parentMap);

  //Logger

  importPackage (com.sap.gateway.ip.core.customdev.logging);

  log.logErrors(LogMessage.TechnicalError, “This is first log”+message.getBody().toString());

  return message;

}


  • Finally map the response and deploy the project to SMP. Done !!

ScreenHunter_06 Oct. 21 00.47.jpg

How to debug ?

Calling the log API inside the function processRequestXML will record the request logs (payload) in SMP server logs.

Example:

function processRequestXML(message) {

  //Logger

  importPackage (com.sap.gateway.ip.core.customdev.logging);

  log.logErrors(LogMessage.TechnicalError, “This is first log”+message.getBody().toString());

  return message;

}

Log can be accessed from SMP Admin cockpit or in the server installation path. Compare the xml payload created with the SOAP UI payload to troubleshoot.

ScreenHunter_06 Oct. 21 00.50.jpg

More Exercises:

How to use Integration Gateway with SMP 3.0

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gopala Krishna Gundu
      Gopala Krishna Gundu

      Hi

      followed the same steps provided by you.

      In the response I am getting only one record. any idea why its showing one record instead of multiple records.

      Thanks

      Gopal

      Author's profile photo Fenil Doshi
      Fenil Doshi

      Hi,

      Yes we get only single record in this and similar scenario I have with other SOAP WS. Any Help will be appreciated.

      Regards,

      Fenil.

      Author's profile photo Former Member
      Former Member

       

      Hi All,

       

      I am facing one problem with my web service call that when i am calling from  SMP i am getting "Mapping error" in which it is asking for input mapping name expected error ,that i have already set via js custom code .

      Plase help me with this.

       

       

       

       

      Thanks,

      Reena

      Author's profile photo Former Member
      Former Member

       

      Hi All,

       

      I am facing one problem with my web service call that when i am calling from  SMP i am getting “Mapping error” in which it is asking for input mapping name expected error ,that i have already set via js custom code(by using following parentMap.put() method) .

      Plase help me with this.

       

      Atached the screen shot

      Thanks,

      Reena