Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Scala, Olingo, and SAP Gateway - Integration Made Easy

$
0
0

What is SAP and SAP Gateway?

SAP, the world’s largest provider of business software, provides world-class solutions and platforms helping customers and developers at global companies to invent, commercialize, and manage their products and services, to help businesses to run better.
SAP is open to other environments and platforms through SAP Gateway, a technology providing a simple way to connect devices, environments, and platforms, with SAP software based on industry standards.

By exposing business data and business logic via the OASIS standard Open Data Protocol (OData), SAP Gateway appeals to new developer communities which have not created client solutions connected to SAP applications before. OData is a standardized protocol for creating and consuming data APIs. OData builds on core protocols like HTTP and commonly accepted methodologies like REST. The result is a uniform way to expose full featured data APIs. For more information about oData read here.

 

 

What is Scala?

Scala is a general purpose programming language for JVM (Java virtual machine). Scala’s main characteristic is the unification of the Object Oriented and Functional programming paradigms. Scala particularly shines when it comes to scalable server software that makes use of concurrent and synchronous processing, parallel utilization of multiple cores, and distributed processing in the cloud.
Its functional nature makes it easier to write safe and performant multi-threaded code.

For more details about the Scala programming language read here.

 

 

What is Apache Olingo?

Apache Olingo (incubator) is a Java library that implements the Open Data Protocol (OData). Apache Olingo serves client and server aspects of OData. It currently supports OData 2.0 which is the most widely used specification of OData at the moment, and is planned to support OData 4.0 in the future. Apache Olingo is a part of the technical foundation of SAP Gateway technology. Olingo was contributed by SAP as Open Source in 2013.
Developers can also use the library as a client to consume OData services like those from rich SAP solutions using SAP Gateway.

For more details on Apache Olingo read here.

 

 

Integrating your Scala code into SAP business software

As a Scala developer intending to integrate with SAP software, there are just a few things you need to know, and here is one way how to do it.

 

Integration via Olingo using a Scala façade like

Scala is fully interoperable with Java, meaning that Scala and Java source files can coexist in the same project and from the Scala project we can call Java code seamlessly. Therefore a Scala developer can use Apache Olingo to interact with the enterprise data available in SAP through SAP Gateway.

For this façade we assume a use case in which a client (Scala application) is interested in a range of various products information residing in SAP business software. The following SAP Gateway demo service can be used to define a data model containing Products and related Business Partners.


Pre-requisites

1. Get access to the SAP Gateway demo system, and sign up as described here
2. An installed JVM version 1.6 or 1.7
3. To set up Scala IDE refer here
4. To set up SBT (a build tool for Scala) refer here
5. To set up and download Apache Olingo client refer here

 

Apache Olingo provides a method to create OData requests (serialization) and interpret responses (deserialization) based on the OData format. It does not provide functionality for sending and receiving requests so the Scala application is free to decide whatever HTTP client library it wants to use.


Read Metadata

For an OData service the Entity Data Model (EDM) defines all metadata information about the provided data of the service. Apache Olingo requires EDM for serialization and deserialization of the data of an entity. Hence the first step is to read the whole EDM of an OData Service.

 

def readEdm(serviceUrl:String):Edm={

    val content = execute(serviceUrl + SEPARATOR +METADATA,APPLICATION_XML,HTTP_METHOD_GET)

    EntityProvider.readMetadata(content, false)

} 


To read the EDM, a HTTP GET on the corresponding service’s $metadata URI is fired via the helper execute(…) method. The resulting content is passed to the EntityProvider.readMetadata(…) method to deserialize it into EDM object. This EDM object can then be used for other read operations.


Read Feed

For read of a complete ODataFeed the HTTP GET request URI for the EntitySetName is first created using the helper method createUri(…) and then the request is fired via the helper execute(…) method. The resulting object is passed to the EntityProvider.readFeed(…) to deserialize into ODataFeed.

 

def readFeed(edm:Edm,serviceUri:String,contentType:String,entitySetName:String):ODataFeed={

        val entityContainer = edm.getDefaultEntityContainer()

        val absoluteUri = createUri(serviceUri, entitySetName)

        println("Reading feed from url: "+ absoluteUri)

        val content = execute(absoluteUri,contentType,HTTP_METHOD_GET)

        EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content, EntityProviderReadProperties.init().build())

  }

 

Read Entry

For read of a single ODataEntry the HTTP GET request URI is an Entity for which key value is required for the creation of the absolute URI. The HTTP GET is fired via the connect(…) method and the resulting object is passed to the EntityProvider.readEntry(…) method deserialize into ODataEntry.


def readEntry(edm:Edm,serviceUri:String,contentType:String,entitySetName:String,keyValue:String,expandRelationName:String= ""):ODataEntry={

        val entityContainer = edm.getDefaultEntityContainer()

        val absoluteUri = createUri(serviceUri,entitySetName,keyValue,expandRelationName)

      println("Reading feed from url: "+ absoluteUri)

      val content = execute(absoluteUri,contentType,HTTP_METHOD_GET)

      EntityProvider.readEntry(contentType, entityContainer.getEntitySet(entitySetName), content, EntityProviderReadProperties.init().build())

  }

 

Code sample for integration example

If you prefer to see the code on this simplified example in one file, please look in the attachment to this blog.              

 

Summary:

SAP, the world’s largest provider of business software is open to other development environments and platforms.

As a Scala developer it will become easier to combine the power of Scala with the power of SAP application by using the Apache Olingo library to consume SAP Business data through the integration technology SAP Gateway using OData.

 


What’s next?

We love to hear what you are working on and how you could think of leveraging Scala-SAP Integration, so please post your ideas here to this very document.
Please let us also know about general requirements and features you would like to see from SAP for your Scala-based solution. - Either comment to this blog or send an email to Divya Mary <divya.mary@sap.com> .

 

 

 


Viewing all articles
Browse latest Browse all 2823

Trending Articles