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.
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

1. Introduction

This article is the third and last 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 first article of this serie: Consuming Employee Central OData Services with Java

If you want to learn more about consuming OData with the Java OData4j library see: Consuming Employee Central OData Services with the Java OData4j library

2. Olingo

Apache Olingo is an open source Java library which implements OData. It is part of the technical foundation of SAP Gateway technology. You can use Olingo for Client or Server usage. For more information, see: http://olingo.apache.org/documentation.html

The steps to consume OData in Java are as follows:

1. Download the metadata and define connection

2. Read Feed

3. Analyze data and parse it to the output

This code snippet shows the Olingo method readEdm which reads the metadata of the given service URL.

With help of metadata being made available via class EDM you can now read a feed which is done in the following code snippet. In this code snippet the final access URL is created by adding filter, select and expand.

With the absolute URI you can initialize an input stream. This process includes the basic authentication and http status code checkup.

The next step is to analyze the feed. The method isEmpty controls that the feed is not empty. After that you loop over the entries.

The method parseData initializes the parse process by looping over the properties of each entry.

The method handleEntry writes the name and value of attribute in the data model. If the attribute is empty the method writes the String “null” as value. If the entry has <<PerPerson>> as entity, a specified handleEntry is launched.

This was the last blog in my three-part series. I hope you enjoyed it. If you have further questions please do not hesitate to contact me!

Best Regards,


1 Comment