5

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.

4

2 回答 2

4

以下代码将帮助您开始使用通过 OData 公开的服务中的数据。(使用 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);

在此之后,您可以使用 EntityProvider 类的静态方法来执行各种操作,例如读取、更新、写入

如果您使用的是 odata4j,请使用以下代码

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


    for (EntitySetInfo entitySet : entitySetList) {
      System.out.println(entitySet.getHref());
    }
于 2014-05-08T10:56:39.227 回答
-2

这听起来很像我们阅读 RSS 或其他数据源的方式

由于您有一个 url,因此可以通过 Http 连接器甚至轮询 http 连接器读取。数据可以使用默认行为的 Java 输入流进行流式传输或转换为字符串(对象到字符串)。

一个使用 (OData4j) 的简单 java 组件可以处理您的内容.. 听起来像是骡子流上的 2 个简单组件。

R

于 2013-11-22T09:28:01.970 回答