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.
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.
- Create Odata Models with respect to the SOAP response.
- After creating Odata models, select the data source and choose operation as Query.
- 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 !!
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.
More Exercises:
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
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.
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
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