Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

1. Introduction


This article is the second in a three-part series. In this blog, I will briefly explain how to consume OData with the OData4j library. You can find the full source code in the previous article of this serie: http://scn.sap.com/community/erp/hcm/blog/2015/05/20/consuming-employee-central-odata-services-with-...


2. OData4j


OData4j is an open source Java library that implements OData. The library contains several methods to handle data in OData format and builds on top of existing java standards. For more information, see: https://code.google.com/p/odata4j/

The steps to consume OData in Java are as follows:

1. Build a consumer

2. Read entities

3. Analyze the consumed data and parse it to the output

This code snipped shows the method buildConsumer which defines the connection to the server by setting all the necessary information like the service URL and the log in information. The first String in  the BasicAuthenticationBehavior constructor describes a combination of user and company. The second string describes the password.

This code snippet shows the method readEntities which consumes data from the server based on the defined consumer. You need to define an entity which you can specify by expanding, filtering and selecting attributes.

The method parseData loops over the properties of the given entity. The method analyzeProperty writes the name and value of the attribute into the data model.

In my next blog, I will show you how to consume OData with the Olingo library, please stay tuned!

1 Comment