Consuming Employee Central OData Services with the Java OData4j library

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: https://www.erpqna.com/consuming-employee-central-odata-services-java/

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.

Consuming Employee Central OData Services with the Java OData4j library

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.

Consuming Employee Central OData Services with the Java OData4j library

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.

Consuming Employee Central OData Services with the Java OData4j library