在Olingo 2中,我可以这样做:
Edm metadataEdm = EntityProvider.readMetadata(metadataInputStream, false); //metadataInputStream is java.io.InputStream
根据我在Olingo 4中所读到的,你可以这样做:
ODataClient client = ODataClientFactory.getClient();
String serviceRoot = "http://services.odata.org/V4/Northwind/Northwind.svc";
EdmMetadataRequest request
= client.getRetrieveRequestFactory().getMetadataRequest(serviceRoot);
ODataRetrieveResponse<Edm> response = request.execute();
但在我的项目中,我只能使用HTTPClient
进行任何网络调用 - 这意味着我无法使用ODataClient client
。
从HttpClient
我可以获得InputStream
。有没有办法(如上面的Olingo 2所示)从Olingo 4中的InputStream获取Edm
对象?
答案 0 :(得分:0)
是的,有一种方法可以使用ODataReader
在Olingo 4中执行此操作。它接受方法Edm readMetadata(InputStream input);
您可以通过以下方式修改上述代码,以获得相同的结果。
ODataReader reader = ODataClientFactory.getClient().getReader();
String serviceRoot = "http://services.odata.org/V4/Northwind/Northwind.svc/$metadata";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(serviceRoot);
httpGet.addHeader("Accept", "application/xml"); // Looks like version 4.4.0 of OData client only supports xml format for metadata
HttpResponse response = httpClient.execute(httpGet);
Edm edm = reader.readMetadata(response.getEntity().getContent());