Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odata with Olingo or Odata4j

I'm in over my head.

At the broadest level, I'm trying to expose an Odata interface to an existing pool of data exposed by a service written using Mule. When my Mule service is invoked, if I detect that the URL is Odata format, I want to delegate processing down to something written in Java and then feed the response from that component back to my caller.

I found the Olingo and OData4j libraries. My problem is that these start from building a Web service. But that's too far upstream for me. I have a Web service. What I need to understand are what components I need to implement in order to pass the URL (which I have in hand) onward to an Odata parser which will, in turn, invoke a data provider.

I'm a bit lost with this technology. Can someone point me to a very basic tutorial that clearly delineates this. Or, can they give me a couple steps like: "You have to implement A, B & C and then pass your URL into C.foo()"?

I've tried the Getting Started doc for both libraries but they both start with "first we'll implement a Web service" and don't clearly delineate (to me, at least) where that leaves off and pure Odata sets in.

Thanks.

like image 558
TomD Avatar asked Nov 01 '22 10:11

TomD


1 Answers

The following is the code that will help you to get started for using data from a service exposing via OData.(using Apache Olingo).

 URL url=new URL(/*your url*/);
 HttpURLConnection conn=(HttpURLConnection) url.openConnection();
 conn.setRequestMethod("GET");
 conn.setRequestProperty(HttpHeaders.ACCEPT,HttpContentType.APPLICATION_XML);
 conn.connect();
 InputStream content=conn.getInputStream();
 Edm edm = EntityProvider.readMetadata(content, false);

After this you can use static methods of EntityProvider class for carrying out various operations like read,update,write

If you are using odata4j go with the following code

   ODataConsumer demo_consumer= ODataConsumers.create(/*your URL*/);
   Enumerable<EntitySetInfo> demo_entitySetList = demo_consumer.getEntitySets();


    for (EntitySetInfo entitySet : entitySetList) {
      System.out.println(entitySet.getHref());
    }
like image 189
prerna30 Avatar answered Nov 04 '22 10:11

prerna30