How to use Composite WSDL in Integration Gateway
Using Integration Gateway SOAP can be converted to Odata protocol. If the WSDL used is of type composite, it has to be managed via custom script because the Integration Gateway design time tool will not support mapping of composite WSDL. This guide is on how to use a composite WSDL in Integration Gateway using custom script.
Prerequisites
- SAP Mobile Platform 3.0 SP05 Developer Installation
- Eclipse Kepler
- SAP Mobile Platform Eclipse Plugins. Available from the SAP eclipse update site: https://tools.hana.ondemand.com/kepler
- WSDL used:http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl
Create SMP Odata Implementation Project
- Open Eclipse and select File > New > SAP Mobile Platform Odata Implementation Project.
- In the pop up window provide the project name “GetStockQuote”.
- Select Target Runtime Server as “SAP Mobile Platform 3.0 SP5”.
- Click Next.
- Enter Model name “StockQuote”.
- Choose Model content “Blank Odata Model”.
- Click Finish. It creates the GetStockQuote project in the workspace.
Create Entity Set
- From the palette tab choose “Entity Type”, and then click on the empty area under the opened StockQuote.odata file. It creates an entity set.
- Change the name of the Entity Type to StockQuote.
- Rename existing property name StockQuoteID to Symbol.
- Keep the cursor on the entity type to show more options. Then click on Add Property.
- In the properties tab change the name to “Last”.
- Add all other properties: Date, Time and Name.
Write Custom Script for Query
- In the Project Explorer right click on StockQuote.odatasrv file > Select Data Source.
- Select Query from Operations and select SOAP Service as Data source.
- Click Next.
- Browse WSDL file stored in local machine and select the operation “GetStockQuote”.
- Click Finish.
- Expand StockQuote.odatasrv file > Right click on Query > Define Custom Code.
- Choose JavaScript as Script type and click Finish.
- Place the below code under the function processRequestData
importPackage(java.lang); importPackage(java.util); var map = new LinkedHashMap(); map.put(“key:request”, “SAP”); //Passing input to query. message.setBody(map); |
- Place the below code under the function processResponseXML
importPackage(org.apache.camel.component.cxf); importPackage(java.util); importPackage(java.lang); importPackage(javax.xml.transform.dom); importPackage(org.w3c.dom); //Creating response for the query var payload = message.getBody().toString(); importPackage(com.sap.gateway.ip.core.customdev.logging); log.logErrors(LogMessage.TechnicalError, “Response Payload is: “ + payload); var tokens = payload.split(“(?=<)|(?<=>)”); var buffer = new StringBuffer(); buffer.append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?>”); buffer.append(“<StockQuoteSet><StockQuote>”); var breakLoop = false; for(var i=0;i<tokens.length;i++) { log.logErrors(LogMessage.TechnicalError, “token length is : “ + tokens.length.toString()); log.logErrors(LogMessage.TechnicalError, ” token name is : “ + tokens[i]); if(tokens[i].contains(“Symbol”) && !breakLoop) { buffer.append(“<Symbol>”); buffer.append(tokens[i+1]); buffer.append(“</Symbol>”); i=i+2; breakLoop = true; } if(tokens[i].contains(“Last”)) { buffer.append(“<Last>”); buffer.append(tokens[i+1]); buffer.append(“</Last>”); i=i+2; } if(tokens[i].contains(“Date”)) { buffer.append(“<Date>”); buffer.append(tokens[i+1]); buffer.append(“</Date>”); i=i+2; } if(tokens[i].contains(“Time”)) { buffer.append(“<Time>”); buffer.append(tokens[i+1]); buffer.append(“</Time>”); i=i+2; } if(tokens[i].contains(“Name”)) { buffer.append(“<Name>”); buffer.append(tokens[i+1]); buffer.append(“</Name>”); i=i+2; } } buffer.append(“</StockQuote></StockQuoteSet>”); message.setBody(buffer.toString()); |
- Save the file.
Deploy to SMP Server
- To setup the connection to SMP server click on Windows > Preferences > Expand SAP Mobile Platform Tools > Server.
- Provide below details:
URL: https://<smphostname>:8083
User: smpAdmin
Password: s3pAdmin
- Click on Test Connection.
- Right click on the project > Generate and Deploy Integration Content.
Test your service
- Login to SAP Gateway Cockpit.
- Under Services tab find the GETSTOCKQUOTE.
- Click on Open Service Document to see the service document of the Odata service created.
- Append Odata collection name with the service document execute the query operation and get the data. https://<smpserverhotname>:8083/gateway/odata/SAP/GETSTOCKQUOTE;v=1 /StockQuoteSet
Hi Midhun,
We tried your code, it works also, but it has only first entry in response where as we are having multiple set of record in response. for your case also its showing only single set of record.
Can you please help us.