Skip to Content

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-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.

buildConsumer.PNG

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.

readEntities.PNG

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.

parseData.PNG

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

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply