cancel
Showing results for 
Search instead for 
Did you mean: 

how to consume ODATA service in Java client

Former Member
0 Kudos

hi Team,

I created an ODATA service and in which I exposed a calculation view which gives the City details if we input the Customer Id into it.

the following is the URL which got estabilshed:

http://xx.xxx.xxx.xx:80xx/PKG_TEST/xsproject1/customer_det.xsodata/customer_det?$format=json&$select... eq 1)

My questions are:

1)how can we call this URL from a JAVA client?

2)for testing from a JAVA client, can I use the JAVA perspective of HANA Studio?

3)if point(2) is yes, then how can create a JAVA application and what are the necessary JAR files needed to run this application?

4)if point(2) is yes, how can I ensure that JAVA perspective is pointing to JRE which is installed on my system?

please provide inputs on the above points to proceed further in the development.

Regards,

Vishnu

Accepted Solutions (0)

Answers (1)

Answers (1)

pfefferf
Active Contributor
0 Kudos

Hello Vishnu,

one option would be to use Apache Olingo as OData Client Library. The tutorial https://olingo.apache.org/doc/odata2/tutorials/OlingoV2BasicClientSample.html#sampleservice which describes the creation of a OData client for a sample service should give you all necessary information regarding packages, development steps.

The Java perspective within the HANA Studio can be used. Regarding the JRE, check your settings under Window -> Preferences -> Java -> Installed JREs.

Best Regards,

Florian

Former Member
0 Kudos

hi Forian,

thanks for your mail.

I tried to implement the logic provided in the link of Olingo, but getting a huge amounts of errors may be due the reason that there were not enough/correct JAR files.

well I tried with another logic as under:

public class RSClient {

public static void main(String[] args) {

  Client c  = Client.create(new DefaultClientConfig());

  WebResource res = c.resource(buildURI()); 

  String result = res.accept(MediaType.TEXT_PLAIN);

  System.out.println("City"+result);

}

private static URI buildURI(){

     return UriBuilder.fromUri("http://10.xxx.xx.xx:80xx/PKG_TEST/xsproject1/customer_det.xsodata/customer_det?$format=json&$select=...)").build(null);

}

}

I imported all the necessary JAR files relating to JERSEY -> which is need for calling Webservice of ODATA from a Java environment -> Java Perspective in HANA studio, but getting the following error as:

"the method accept(MediaType[]) in the type WebResource is not applicable for the arguments(String)" but for the MediaType .TEXT_HTML/TEXT_PLAIN/TEXT_XML have a return type as STRING...

even though the result is defined as STRING and MediaType.TEXT_PLAIN is also a STRING, why this error is not getting removed?

please provide inputs on the above point to proceed further.

Regards,

Vishnu