Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert


From SMP 3.0 SP05 release onward there is a support of OData Query operation for a service provisioned based on a REST service. In this blog post I want to show how you can develop and deploy an OData service to the SMP3 which relies on an REST service. That means that the Integration Gateway component in SMP3 will convert on the fly data coming from the REST service into OData.

 

Tools Used: Eclipse Kepler

Prerequisite:

1. SAP Mobile Platform Tools plugins added to Eclipse Kepler (make sure its version should be 1.3.1 check this guide for more info)

2. SAP Mobile Platform 3.0 SP06 Runtime

 

I got one publicly available REST service (http://www.thomas-bayer.com/sqlrest/CUSTOMER/1), i am going to convert this information into OData.


 

             

 

Steps:

 

1. Create a new project in Eclipse Kepler: File>New>SAP Mobile Platform OData Implementation Project



    • Make sure you select Target Runtime server as SP06








    • Give any model name and Finish




 



2. Create an Entity and add properties as below:



3. Right click .odatasrv > Select Data source as REST Service



    • Request URL : /sqlrest/CUSTOMER/1






4. Expand .odatasrv > Right click Query > Define Custom code



5. Replace generated code with below code. (I have attached it in a file as well)

function getUriInfo(message) {
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(com.sap.gateway.core.ip.component.commons);
var uriInfo = message.getHeaders().get(ODataExchangeHeaderProperty.UriInfo.toString());
return uriInfo;
}
function processRequestData(message) {
return message;
}
function processResponseData(message) {
importPackage(java.io);
importPackage(java.lang);
importPackage(java.util);
importPackage(org.apache.camel);
importPackage(com.sap.gateway.core.ip.component.commons);
importPackage(com.sap.gateway.ip.core.customdev.util);
importPackage(org.apache.olingo.odata2.api.edm);
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(com.sap.gateway.ip.core.customdev.logging);
var payload = message.getBody();
log.logErrors(LogMessage.TechnicalError, "\n +++++++++++++++++++++++++++++++++++ TRACE OUTPUT +++++++++++++++++++++++++++++++++++\n");
log.logErrors(LogMessage.TechnicalError, "\n Original Payload is:\n" + payload);
payload = payload.replace("\n", "");
payload = payload.replaceFirst("<.xml .*?>", ""); // remove the line <?xml version="1.0"?>
payload = "<CUSTOMERSet>" + payload + "</CUSTOMERSet>";
log.logErrors(LogMessage.TechnicalError, "\n Response Payload is:\n" + payload);
log.logErrors(LogMessage.TechnicalError, "\n +++++++++++++++++++++++++++++++ END OF TRACE OUTPUT ++++++++++++++++++++++++++++++++\n");
message.setBody(payload);
message.setHeader("Content-Type", new java.lang.String("xml"));
return message;
}




6. Right click project > Generate and Deploy Integration Content



Creating a destination in Gateway cockpit:

7. Open Gateway cockpit (https://smpserver:adminport/gateway/cockpit) > Navigate to "Destinations" tab

Destination URL : http://www.thomas-bayer.com



8. Select newly created destination and check if you are able to ping it .(Test connection)



9. Navigate to SERVICES > select deployed OData service (ThomasREST)> Add destination



10. Open service document

https://jk:8083/gateway/odata/SAP/THOMASRESTIGW;v=1

https://jk:8083/gateway/odata/SAP/THOMASRESTIGW;v=1/CUSTOMERSet



For more info, check official guide.

Enabling REST Services as OData Services

Custom Scripting functions for REST services

Note: From SMP SP06, the READ operation is supported as well. Check this blog.

Thanks mustafa.saglam and bjoernw for your continuous support.


4 Comments